public function actionUpdate()
    {
        $module = \jacmoe\mdpages\Module::getInstance();

        if(!is_dir(Yii::getAlias($module->pages_directory))) {
            $this->stderr("Execution terminated: the repository to update does not exist - please run init first.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        if (!$this->acquireMutex()) {
            $this->stderr("Execution terminated: command is already running.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        $git = Yii::createObject('jacmoe\mdpages\components\yii2tech\Git');

        $log = '';
        if($git->hasRemoteChanges(Yii::getAlias($module->pages_directory), $log)) {
            //echo $log;

            $placeholders = [
                '{binPath}' => 'git',
                '{projectRoot}' => Yii::getAlias($module->pages_directory),
                '{remote}' => 'origin',
                '{branch}' => 'master',
            ];
            $result = Shell::execute('(cd {projectRoot}; {binPath} diff --name-only HEAD {remote}/{branch})', $placeholders);
            $raw_files = $result->toString();

            $git->applyRemoteChanges(Yii::getAlias($module->pages_directory), $log);
            //echo $log;

            $files = explode("\n", $raw_files);
            array_shift($files); // the first entry is the command
            array_pop($files); // the last entry is the exit code

            $to_update = array();
            foreach($files as $file) {
                $to_update[] = Yii::getAlias('@pages') . '/' . $file;
            }

            $this->updateDB($to_update);

            $this->createImageSymlink();

        } else {
            $this->stdout("No changes detected\n\n", Console::FG_GREEN);
        }

        $this->releaseMutex();
        return self::EXIT_CODE_NORMAL;

    }
public function actionUpdate()
    {
        $module = \jacmoe\mdpages\Module::getInstance();

        if(!is_dir(Yii::getAlias($module->pages_directory))) {
            $this->stderr("Execution terminated: the repository to update does not exist - please run init first.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        if (!$this->acquireMutex()) {
            $this->stderr("Execution terminated: command is already running.\n", Console::FG_RED);
            return self::EXIT_CODE_ERROR;
        }

        $git = Yii::createObject('jacmoe\mdpages\components\yii2tech\Git');

        $log = '';
        if($git->hasRemoteChanges(Yii::getAlias($module->pages_directory), $log)) {
            //echo $log;

            $placeholders = [
                '{binPath}' => 'git',
                '{projectRoot}' => Yii::getAlias($module->pages_directory),
                '{remote}' => 'origin',
                '{branch}' => 'master',
            ];
            $result = Shell::execute('(cd {projectRoot}; {binPath} diff --name-only HEAD {remote}/{branch})', $placeholders);
            $raw_files = $result->toString();

            $git->applyRemoteChanges(Yii::getAlias($module->pages_directory), $log);
            //echo $log;

            $files = explode("\n", $raw_files);
            array_shift($files); // the first entry is the command
            array_pop($files); // the last entry is the exit code

            $to_update = array();
            foreach($files as $file) {
                $to_update[] = Yii::getAlias('@pages') . '/' . $file;
            }

            $this->updateDB($to_update);

            $this->createImageSymlink();

        } else {
            $this->stdout("No changes detected\n\n", Console::FG_GREEN);
        }

        $this->releaseMutex();
        return self::EXIT_CODE_NORMAL;

    }
public function actionUpdate ( ) { $ module = \ jacmoe \ mdpages \ Module :: getInstance ( ) ; if ( ! is_dir ( Yii :: getAlias ( $ module -> pages_directory ) ) ) { $ this -> stderr ( "Execution terminated: the repository to update does not exist - please run init first.\n" , Console :: FG_RED ) ; return self :: EXIT_CODE_ERROR ; } if ( ! $ this -> acquireMutex ( ) ) { $ this -> stderr ( "Execution terminated: command is already running.\n" , Console :: FG_RED ) ; return self :: EXIT_CODE_ERROR ; } $ git = Yii :: createObject ( 'jacmoe\mdpages\components\yii2tech\Git' ) ; $ log = '' ; if ( $ git -> hasRemoteChanges ( Yii :: getAlias ( $ module -> pages_directory ) , $ log ) ) { //echo $log; $ placeholders = [ '{binPath}' => 'git' , '{projectRoot}' => Yii :: getAlias ( $ module -> pages_directory ) , '{remote}' => 'origin' , '{branch}' => 'master' , ] ; $ result = Shell :: execute ( '(cd {projectRoot}; {binPath} diff --name-only HEAD {remote}/{branch})' , $ placeholders ) ; $ raw_files = $ result -> toString ( ) ; $ git -> applyRemoteChanges ( Yii :: getAlias ( $ module -> pages_directory ) , $ log ) ; //echo $log; $ files = explode ( "\n" , $ raw_files ) ; array_shift ( $ files ) ; // the first entry is the command array_pop ( $ files ) ; // the last entry is the exit code $ to_update = array ( ) ; foreach ( $ files as $ file ) { $ to_update [ ] = Yii :: getAlias ( '@pages' ) . '/' . $ file ; } $ this -> updateDB ( $ to_update ) ; $ this -> createImageSymlink ( ) ; } else { $ this -> stdout ( "No changes detected\n\n" , Console :: FG_GREEN ) ; } $ this -> releaseMutex ( ) ; return self :: EXIT_CODE_NORMAL ; }
Updates the database if there are remote changes
@return integer success or fail
Updates the database if there are remote changes