2016-11-07 07:15:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace api\core;
|
|
|
|
|
2016-11-08 08:54:59 +00:00
|
|
|
use \error\core\Error;
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class release{
|
|
|
|
|
|
|
|
/* PULLS A BRANCH FROM GIT
|
|
|
|
*
|
|
|
|
* @project<String> Project's name
|
|
|
|
* @branch<String> Git branch
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function pull($args){
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
/* [1] Load projects' configuration
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Fetch file */
|
|
|
|
$fc = file_get_contents(__CONFIG__.'/projects.json');
|
|
|
|
if( !$fc )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::UnreachableResource];
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
/* (2) Checks json format */
|
|
|
|
$js = json_decode( $fc, true );
|
|
|
|
|
|
|
|
if( !$js )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::ParsingFailed];
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [2] Checks @project argument and files
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Checks @project */
|
|
|
|
if( !isset($js[$project]) )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::UnreachableResource];
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
/* (2) Checks @project's folder */
|
2016-11-07 18:47:54 +00:00
|
|
|
if( !is_dir($js[$project]['git']) )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::UnreachableResource];
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
/* (3) Checks @git directory */
|
2016-11-07 18:47:54 +00:00
|
|
|
if( !is_dir($js[$project]['git'].'/.git') )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::UnreachableResource];
|
2016-11-07 07:15:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] Launch script
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Launch command + test */
|
2016-11-08 08:26:00 +00:00
|
|
|
$cmd = 'cd '.$js[$project]['git'].'; git pull origin '.$branch.';';
|
|
|
|
$stdout = shell_exec($cmd);
|
2016-11-07 17:17:06 +00:00
|
|
|
|
|
|
|
/* (2) If error, raise error */
|
|
|
|
if( is_null($stdout) )
|
2016-11-08 08:54:59 +00:00
|
|
|
return ['ModuleError'=>Error::PermissionError, 'command'=>$cmd];
|
2016-11-07 17:17:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [4] Return success error
|
|
|
|
=========================================================*/
|
|
|
|
return [];
|
2016-11-07 07:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|