Ejemplo n.º 1
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());
 }
Ejemplo n.º 2
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     CLIWCF::getReader()->println(CLIUtil::generateList(array_keys(CLICommandHandler::getCommands())));
 }
Ejemplo n.º 3
0
 /**
  * Initializes command handling.
  */
 protected function initCommands()
 {
     // add command name completer
     self::getReader()->addCompleter(new CLICommandNameCompleter());
     while (true) {
         // roll back open transactions of the previous command, as they are dangerous in a long living script
         if (WCF::getDB()->rollBackTransaction()) {
             Log::warn('Previous command had an open transaction.');
         }
         self::getReader()->setHistoryEnabled(true);
         $line = self::getReader()->readLine('>');
         if ($line === null) {
             exit;
         }
         $line = StringUtil::trim($line);
         try {
             $command = CLICommandHandler::getCommand($line);
             $command->execute(CLICommandHandler::getParameters($line));
         } catch (IllegalLinkException $e) {
             Log::error('notFound:' . JSON::encode(array('command' => $line)));
             self::getReader()->println(WCF::getLanguage()->getDynamicVariable('wcf.cli.error.command.notFound', array('command' => $line)));
             if (self::getArgvParser()->exitOnFail) {
                 exit(1);
             }
             continue;
         } catch (PermissionDeniedException $e) {
             Log::error('permissionDenied');
             self::getReader()->println(WCF::getLanguage()->getDynamicVariable('wcf.global.error.permissionDenied'));
             if (self::getArgvParser()->exitOnFail) {
                 exit(1);
             }
             continue;
         } catch (ArgvException $e) {
             // show error message and usage
             if ($e->getMessage()) {
                 echo $e->getMessage() . PHP_EOL;
             }
             echo $e->getUsageMessage();
             if (self::getArgvParser()->exitOnFail) {
                 exit(1);
             }
             continue;
         } catch (\Exception $e) {
             Log::error($e);
             if (self::getArgvParser()->exitOnFail) {
                 exit(1);
             }
             continue;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @see	\wcf\system\cli\command\ICLICommand::execute()
  */
 public function execute(array $parameters)
 {
     CLIWCF::getReader()->setHistoryEnabled(false);
     $this->exporters = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.exporter');
     $this->importers = array_keys(ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.importer'));
     if (empty($this->exporters)) {
         CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.selectExporter.noExporters'));
         return;
     }
     if (PACKAGE_ID == 1) {
         CLIWCF::getReader()->println(StringUtil::stripHTML(WCF::getLanguage()->get('wcf.acp.dataImport.cli.info.wcf')));
         $answer = CLIWCF::getReader()->readLine('> ');
         if ($answer === null) {
             exit;
         }
         if (mb_strtolower($answer) != 'y') {
             CLIWCF::getReader()->setHistoryEnabled(true);
             return;
         }
     }
     // step 1) previous import
     $sql = "SELECT\tCOUNT(*)\n\t\t\tFROM\twcf" . WCF_N . "_import_mapping";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute();
     if ($statement->fetchColumn()) {
         CLIWCF::getReader()->println(StringUtil::stripHTML(WCF::getLanguage()->get('wcf.acp.dataImport.existingMapping.notice')));
         CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.existingMapping.confirmMessage') . ' [YN]');
         $answer = CLIWCF::getReader()->readLine('> ');
         if ($answer === null) {
             exit;
         }
         if (mb_strtolower($answer) == 'y') {
             ImportHandler::getInstance()->resetMapping();
         }
     }
     // step 2) exporter
     $this->readExporter();
     // step 3) selected data
     $this->readSelectedData();
     if ($this->quitImport) {
         CLIWCF::getReader()->setHistoryEnabled(true);
         return;
     }
     // step 4) user merge mode
     $this->readUserMergeMode();
     // step 5) database connection
     $this->readDatabaseConnection();
     // step 6) file system path
     $this->readFileSystemPath();
     // step 7) save import data
     $queue = $this->exporter->getQueue();
     WCF::getSession()->register('importData', array('additionalData' => array(), 'dbHost' => $this->dbHost, 'dbName' => $this->dbName, 'dbPassword' => $this->dbPassword, 'dbPrefix' => $this->dbPrefix, 'dbUser' => $this->dbUser, 'exporterName' => $this->exporterName, 'fileSystemPath' => $this->fileSystemPath, 'userMergeMode' => $this->userMergeMode));
     // step 8) import data
     CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.started'));
     foreach ($queue as $objectType) {
         CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.data.' . $objectType));
         $workerCommand = CLICommandHandler::getCommand('worker');
         $workerCommand->execute(array('--objectType=' . $objectType, 'ImportWorker'));
     }
     CLIWCF::getReader()->println(WCF::getLanguage()->get('wcf.acp.dataImport.completed'));
     CLIWCF::getReader()->setHistoryEnabled(true);
 }
 /**
  * Creates a new instance of CLICommandNameCompleter.
  */
 public function __construct()
 {
     $this->commands = array_keys(CLICommandHandler::getCommands());
 }