move IDF_View_Source_Precondition into a separate class file
This commit is contained in:
@@ -601,56 +601,3 @@ function IDF_Views_Source_ShortenString($string, $length)
|
||||
return substr($string, 0, $preflen).$ellipse.
|
||||
substr($string, -($length - $preflen - mb_strlen($ellipse)));
|
||||
}
|
||||
|
||||
class IDF_Views_Source_Precondition
|
||||
{
|
||||
/**
|
||||
* Ensures that the configured SCM for the project is available
|
||||
*
|
||||
* @param $request
|
||||
* @return true | Pluf_HTTP_Response_Redirect
|
||||
*/
|
||||
static public function scmAvailable($request)
|
||||
{
|
||||
$scm = IDF_Scm::get($request->project);
|
||||
if (!$scm->isAvailable()) {
|
||||
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help',
|
||||
array($request->project->shortname));
|
||||
return new Pluf_HTTP_Response_Redirect($url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the revision given in the URL path and acts accordingly
|
||||
*
|
||||
* @param $request
|
||||
* @return true | Pluf_HTTP_Response_Redirect
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function revisionValid($request)
|
||||
{
|
||||
list($url_info, $url_matches) = $request->view;
|
||||
list(, $project, $commit) = $url_matches;
|
||||
|
||||
$scm = IDF_Scm::get($request->project);
|
||||
$res = $scm->validateRevision($commit);
|
||||
switch ($res) {
|
||||
case IDF_Scm::REVISION_VALID:
|
||||
return true;
|
||||
case IDF_Scm::REVISION_INVALID:
|
||||
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::invalidRevision',
|
||||
array($request->project->shortname, $commit));
|
||||
return new Pluf_HTTP_Response_Redirect($url);
|
||||
case IDF_Scm::REVISION_AMBIGUOUS:
|
||||
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::disambiguateRevision',
|
||||
array($request->project->shortname,
|
||||
$commit,
|
||||
$url_info['model'].'::'.$url_info['method']));
|
||||
return new Pluf_HTTP_Response_Redirect($url);
|
||||
default:
|
||||
throw new Exception('unknown validation result: '. $res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user