예제 #1
0
 /**
  * Formats time.
  * 
  * @param	integer	$timestamp
  * @return	string
  */
 public static function formatTime($timestamp)
 {
     $dateTimeObject = DateUtil::getDateTimeByTimestamp($timestamp);
     $date = DateUtil::format($dateTimeObject, DateUtil::DATE_FORMAT);
     $time = DateUtil::format($dateTimeObject, DateUtil::TIME_FORMAT);
     return str_replace('%time%', $time, str_replace('%date%', $date, CLIWCF::getLanguage()->get('wcf.date.dateTimeFormat')));
 }
예제 #2
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     $this->argv->setArguments($parameters);
     $this->argv->parse();
     $args = $this->argv->getRemainingArgs();
     // validate parameters
     if (count($args) != 1) {
         throw new ArgvException('', $this->getUsage());
     }
     $commands = CLICommandHandler::getCommands();
     if (!isset($commands[$args[0]])) {
         throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.cli.error.command.notFound', array('command' => $args[0])), $this->getUsage());
     }
     $command = $commands[$args[0]];
     if (!$command instanceof IArgumentedCLICommand) {
         throw new ArgvException(CLIWCF::getLanguage()->getDynamicVariable('wcf.cli.error.help.noArguments', array('command' => $args[0])), $this->getUsage());
     }
     CLIWCF::getReader()->println($command->getUsage());
 }
예제 #3
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::canAccess()
  */
 public function canAccess()
 {
     return CLIWCF::getSession()->getPermission('admin.system.package.canInstallPackage') || CLIWCF::getSession()->getPermission('admin.system.package.canUpdatePackage');
 }
예제 #4
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     CLIWCF::getReader()->println(CLIUtil::generateList(array_keys(CLICommandHandler::getCommands())));
 }
예제 #5
0
 /**
  * @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();
 }
예제 #6
0
 /**
  * Reads the user merge mode.
  */
 protected function readUserMergeMode()
 {
     CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.configure.settings.userMergeMode'));
     CLIWCF::getReader()->println('1) ' . WCF::getLanguage()->get('wcf.acp.dataImport.configure.settings.userMergeMode.4') . ' (*)');
     CLIWCF::getReader()->println('2) ' . WCF::getLanguage()->get('wcf.acp.dataImport.configure.settings.userMergeMode.5'));
     CLIWCF::getReader()->println(WCF::getLanguage()->getDynamicVariable('wcf.acp.dataImport.cli.selection', array('minSelection' => 1, 'maxSelection' => 2)));
     while (true) {
         $this->userMergeMode = CLIWCF::getReader()->readLine('> ');
         if ($this->userMergeMode === null) {
             exit;
         }
         switch (intval($this->userMergeMode)) {
             case 1:
                 $this->userMergeMode = UserImporter::MERGE_MODE_EMAIL;
                 break;
             case 2:
                 $this->userMergeMode = UserImporter::MERGE_MODE_USERNAME_OR_EMAIL;
                 break;
             default:
                 $this->userMergeMode = UserImporter::MERGE_MODE_EMAIL;
                 break;
         }
         break;
     }
 }