1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-14 01:26:13 +01:00
phorge-phorge/src/applications/diffusion/controller/DiffusionPathValidateController.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2011-04-04 04:20:47 +02:00
<?php
final class DiffusionPathValidateController extends DiffusionController {
2011-04-04 04:20:47 +02:00
protected function getRepositoryIdentifierFromRequest(
AphrontRequest $request) {
return $request->getStr('repositoryPHID');
2011-04-04 04:20:47 +02:00
}
public function handleRequest(AphrontRequest $request) {
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
2011-04-04 04:20:47 +02:00
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
2011-04-04 04:20:47 +02:00
$path = $request->getStr('path');
$path = ltrim($path, '/');
$browse_results = DiffusionBrowseResultSet::newFromConduit(
$this->callConduitWithDiffusionRequest(
'diffusion.browsequery',
array(
'path' => $path,
'commit' => $drequest->getCommit(),
'needValidityOnly' => true,
)));
$valid = $browse_results->isValidResults();
2011-04-04 04:20:47 +02:00
if (!$valid) {
switch ($browse_results->getReasonForEmptyResultSet()) {
case DiffusionBrowseResultSet::REASON_IS_FILE:
2011-04-04 04:20:47 +02:00
$valid = true;
break;
case DiffusionBrowseResultSet::REASON_IS_EMPTY:
2011-04-04 04:20:47 +02:00
$valid = true;
break;
}
}
$output = array(
'valid' => (bool)$valid,
);
if (!$valid) {
$branch = $drequest->getBranch();
if ($branch) {
$message = pht('Not found in %s', $branch);
2011-04-04 04:20:47 +02:00
} else {
$message = pht('Not found at %s', 'HEAD');
2011-04-04 04:20:47 +02:00
}
} else {
$message = pht('OK');
2011-04-04 04:20:47 +02:00
}
$output['message'] = $message;
return id(new AphrontAjaxResponse())->setContent($output);
}
}