/** * @see \wcf\system\cli\command\ICLICommand::execute() */ public function execute(array $parameters) { $this->argv->setArguments($parameters); $this->argv->parse(); if ($this->argv->list) { CLIWCF::getReader()->println(CLIUtil::generateTable($this->generateList())); return; } $args = $this->argv->getRemainingArgs(); // validate parameters if (count($args) != 1) { throw new ArgvException('', $this->getUsage()); } $class = $args[0]; // assume wcf\system\worker when no FQN is given if (strpos($class, '\\') === false) { $class = 'wcf\\system\\worker\\' . $class; } $invalid = false; if (!class_exists($class)) { $invalid = true; } else { $reflection = new \ReflectionClass($class); if (!$reflection->isInstantiable()) { $invalid = true; } else { if (!ClassUtil::isInstanceOf($class, 'wcf\\system\\worker\\IWorker')) { $invalid = true; } } } if ($invalid) { throw new ArgvException("Invalid worker '" . $class . "' given", $this->getUsage()); } // parse parameters $options = $this->argv->getOptions(); $parameters = array(); foreach ($options as $option) { $value = $this->argv->getOption($option); if ($option === 'setParameter') { if (!is_array($value)) { $value = array($value); } foreach ($value as $parameter) { list($parameterKey, $parameterValue) = explode('=', $parameter); $parameters[$parameterKey] = $parameterValue; } } else { $parameters[$option] = $value; } } $worker = new $class($parameters); $worker->validate(); $worker->getProgress(); // make sure objects are counted // initialize progressbar $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth()))); $progress = 0; for ($i = 0; $progress < 100; $i++) { $worker->setLoopCount($i); $worker->validate(); // execute worker $worker->execute(); // update progress $progress = $worker->getProgress(); $progressbar->update($progress); } $progressbar->update($progress); $progressbar->getAdapter()->finish(); }
/** * @see \wcf\system\cli\command\ICLICommand::execute() */ public function execute(array $parameters) { CLIWCF::getReader()->println(CLIUtil::generateList(array_keys(CLICommandHandler::getCommands()))); }
/** * Checks for updates. * * @return string */ public function checkForUpdates() { if (WCF::getSession()->getPermission('admin.system.package.canUpdatePackage') && VERBOSITY >= -1 && !self::getArgvParser()->disableUpdateCheck) { $updates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates(); if (!empty($updates)) { $return = self::getReader()->println(count($updates) . ' update' . (count($updates) > 1 ? 's are' : ' is') . ' available'); if (VERBOSITY >= 1) { $table = array(array(WCF::getLanguage()->get('wcf.acp.package.name'), WCF::getLanguage()->get('wcf.acp.package.version'), WCF::getLanguage()->get('wcf.acp.package.newVersion'))); foreach ($updates as $update) { $row = array(WCF::getLanguage()->get($update['packageName']), $update['packageVersion'], $update['version']['packageVersion']); $table[] = $row; } self::getReader()->println(CLIUtil::generateTable($table)); } } } }