Piwik\Common::isRunningConsoleCommand PHP Méthode

isRunningConsoleCommand() public static méthode

./console xx:yy or php console xx:yy
public static isRunningConsoleCommand ( ) : boolean
Résultat boolean
    public static function isRunningConsoleCommand()
    {
        $searched = 'console';
        $consolePos = strpos($_SERVER['SCRIPT_NAME'], $searched);
        $expectedConsolePos = strlen($_SERVER['SCRIPT_NAME']) - strlen($searched);
        $isScriptIsConsole = $consolePos === $expectedConsolePos;
        return self::isPhpCliMode() && $isScriptIsConsole;
    }

Usage Example

Exemple #1
0
 public function runUpdaterAndExit($doDryRun = null)
 {
     $updater = new Updater();
     $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
     if (empty($componentsWithUpdateFile)) {
         throw new NoUpdatesFoundException("Everything is already up to date.");
     }
     SettingsServer::setMaxExecutionTime(0);
     $cli = Common::isPhpCliMode() ? '_cli' : '';
     $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli;
     $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli;
     $viewWelcome = new View($welcomeTemplate);
     $this->addCustomLogoInfo($viewWelcome);
     $viewDone = new View($doneTemplate);
     $this->addCustomLogoInfo($viewDone);
     $doExecuteUpdates = Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1;
     if (is_null($doDryRun)) {
         $doDryRun = !$doExecuteUpdates;
     }
     if ($doDryRun) {
         $viewWelcome->queries = $updater->getSqlQueriesToExecute();
         $viewWelcome->isMajor = $updater->hasMajorDbUpdate();
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         return $viewWelcome->render();
     }
     // CLI
     if (Common::isPhpCliMode()) {
         $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile);
         $output = $viewWelcome->render();
         // Proceed with upgrade in CLI only if user specifically asked for it, or if running console command
         $isUpdateRequested = Common::isRunningConsoleCommand() || Piwik::getModule() == 'CoreUpdater';
         if (!$this->coreError && $isUpdateRequested) {
             $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
             $output .= $viewDone->render();
         }
         return $output;
     }
     // Web
     if ($doExecuteUpdates) {
         $this->warningMessages = array();
         $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile);
         $this->redirectToDashboardWhenNoError($updater);
         return $viewDone->render();
     }
     exit;
 }