/** * Generates a list. * * @param array $list * @return string */ public static function generateList(array $list) { $result = ''; foreach ($list as $row) { $parts = StringUtil::split($row, CLIWCF::getTerminal()->getWidth() - 2); $result .= '* ' . implode(PHP_EOL . ' ', $parts) . PHP_EOL; } return $result; }
/** * Uninstalls the specified package. * $package may either be the packageID or the package identifier. * * @param mixed $package */ private function uninstall($package) { if (Package::isValidPackageName($package)) { $packageID = PackageCache::getInstance()->getPackageID($package); } else { $packageID = $package; } // UninstallPackageAction::prepare() $package = new Package($packageID); if (!$package->packageID || !$package->canUninstall()) { $this->error('invalidUninstallation'); } // get new process no $processNo = PackageInstallationQueue::getNewProcessNo(); // create queue $queue = PackageInstallationQueueEditor::create(array('processNo' => $processNo, 'userID' => CLIWCF::getUser()->userID, 'packageName' => $package->getName(), 'packageID' => $package->packageID, 'action' => 'uninstall')); // initialize uninstallation $installation = new PackageUninstallationDispatcher($queue); $installation->nodeBuilder->purgeNodes(); $installation->nodeBuilder->buildNodes(); CLIWCF::getTPL()->assign(array('queue' => $queue)); $queueID = $installation->nodeBuilder->getQueueByNode($queue->processNo, $installation->nodeBuilder->getNextNode()); $step = 'uninstall'; $node = $installation->nodeBuilder->getNextNode(); $currentAction = CLIWCF::getLanguage()->get('wcf.package.installation.step.uninstalling'); $progress = 0; // initialize progressbar $progressbar = new ProgressBar(new ConsoleProgressBar(array('width' => CLIWCF::getTerminal()->getWidth(), 'elements' => array(ConsoleProgressBar::ELEMENT_PERCENT, ConsoleProgressBar::ELEMENT_BAR, ConsoleProgressBar::ELEMENT_TEXT), 'textWidth' => min(floor(CLIWCF::getTerminal()->getWidth() / 2), 50)))); // InstallPackageAction::readParameters() $finished = false; while (!$finished) { $queue = new PackageInstallationQueue($queueID); $installation = new PackageUninstallationDispatcher($queue); switch ($step) { case 'uninstall': $_node = $installation->uninstall($node); if ($_node == '') { // remove node data $installation->nodeBuilder->purgeNodes(); // UninstallPackageAction::finalize() CacheHandler::getInstance()->flushAll(); // /UninstallPackageAction::finalize() // show success $currentAction = CLIWCF::getLanguage()->get('wcf.acp.package.uninstallation.step.success'); $progress = 100; $step = 'success'; $finished = true; continue; } // continue with next node $queueID = $installation->nodeBuilder->getQueueByNode($installation->queue->processNo, $installation->nodeBuilder->getNextNode($node)); $step = 'uninstall'; $progress = $installation->nodeBuilder->calculateProgress($node); $node = $_node; } $progressbar->update($progress, $currentAction); } $progressbar->getAdapter()->finish(); }
/** * @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(); }