/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $names = explode(',', $input->getArgument('name')); $templates = \ProcessWire\wire('templates'); $fieldgroups = \ProcessWire\wire('fieldgroups'); foreach ($names as $name) { $template = $templates->get($name); if ($template->id) { // try to delete depending file? if (!$input->getOption('nofile') && file_exists($template->filename)) { unlink($template->filename); } $template->flags = Template::flagSystemOverride; $template->flags = 0; // all flags now removed, can be deleted $templates->delete($template); // delete depending fieldgroups $fg = $fieldgroups->get($name); if ($fg->id) { $fieldgroups->delete($fg); } $output->writeln("<info>Template '{$name}' deleted successfully!</info>"); } else { $output->writeln("<error>Template '{$name}' doesn't exist!</error>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $inputFields = explode(',', $input->getArgument('field')); $fields = \ProcessWire\wire('fields'); if ($input->getOption('tag')) { $tag = $input->getOption('tag'); } else { $output->writeln("\n<error> Please provide a tag name (`--tag=tagname`).</error>"); return; } foreach ($inputFields as $field) { $fieldToTag = $fields->get($field); if (is_null($fieldToTag)) { $output->writeln("\n<error> > Field '{$field}' does not exist!</error>"); continue; } try { $fieldToTag->tags = $tag; $fieldToTag->save(); $output->writeln("\n<info> > Field '{$field}' edited successfully!</info>"); } catch (\WireException $e) { $output->writeln("\n<error> > {$e->getMessage()}</error>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $dev = $input->getOption('dev') ? true : false; $check = parent::checkForCoreUpgrades($output, $dev); $this->output = $output; $this->root = wire('config')->paths->root; if ($check['upgrade'] && $input->getOption('just-check') === false) { if (!extension_loaded('pdo_mysql')) { $this->output->writeln("<error>Your PHP is not compiled with PDO support. PDO is required by ProcessWire 2.4+.</error>"); } elseif (!class_exists('ZipArchive')) { $this->output->writeln("<error>Your PHP does not have ZipArchive support. This is required to install core or module upgrades with this tool.</error>"); } elseif (!is_writable($this->root)) { $this->output->writeln("<error>Your file system is not writable.</error>"); } else { $this->fs = new Filesystem(); $this->projectDir = $this->fs->isAbsolutePath($this->root) ? $this->root : getcwd() . DIRECTORY_SEPARATOR . $this->root; $this->branch = $check['branch']; try { $this->download()->extract()->move()->cleanup()->replace($input->getOption('just-download'), $input, $output); } catch (Exception $e) { } } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); $fields = explode(",", $input->getOption('fields')); if (\ProcessWire\wire("templates")->get("{$name}")) { $output->writeln("<error>Template '{$name}' already exists!</error>"); exit(1); } $fieldgroup = new Fieldgroup(); $fieldgroup->name = $name; $fieldgroup->add("title"); if ($input->getOption('fields')) { foreach ($fields as $field) { $this->checkIfFieldExists($field, $output); $fieldgroup->add($field); } } $fieldgroup->save(); $template = new Template(); $template->name = $name; $template->fieldgroup = $fieldgroup; $template->save(); if (!$input->getOption('nofile')) { $this->createTemplateFile($name); } $output->writeln("<info>Template '{$name}' created successfully!</info>"); }
/** * @return array */ protected function getPWStatus($showPass) { $config = \ProcessWire\wire('config'); $on = Tools::tint('On', Tools::kTintError); $off = Tools::tint('Off', Tools::kTintInfo); $none = Tools::tint('None', Tools::kTintInfo); $version = $config->version; $latestVersion = parent::getVersion(); if ($version !== $latestVersion) { $version .= Tools::tint(" (upgrade available: {$latestVersion})", Tools::kTintComment); } $adminUrl = $this->getAdminUrl(); $advancedMode = $config->advanced ? $on : $off; $debugMode = $config->debug ? $on : $off; $timezone = $config->timezone; $hosts = implode(", ", $config->httpHosts); $adminTheme = $config->defaultAdminTheme; $dbHost = $config->dbHost; $dbName = $config->dbName; $dbUser = $config->dbUser; $dbPass = $showPass ? $config->dbPass : '******'; $dbPort = $config->dbPort; $prepended = trim($config->prependTemplateFile); $appended = trim($config->appendTemplateFile); $prependedTemplateFile = $prepended != '' ? $prepended : $none; $appendedTemplateFile = $appended != '' ? $appended : $none; $installPath = getcwd(); $status = [['Version', $version], ['Admin URL', $adminUrl], ['Advanced mode', $advancedMode], ['Debug mode', $debugMode], ['Timezone', $timezone], ['HTTP hosts', $hosts], ['Admin theme', $adminTheme], ['Prepended template file', $prependedTemplateFile], ['Appended template file', $appendedTemplateFile], ['Database host', $dbHost], ['Database name', $dbName], ['Database user', $dbUser], ['Database password', $dbPass], ['Database port', $dbPort], ['Installation path', $installPath]]; return $status; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $advanced = $input->getOption('advanced') ? true : false; $content = $this->getTemplateData($advanced); $headers = array('Template', 'Fields', 'Pages', 'Modified', 'Access'); $tables = array(WsTables::buildTable($output, $content, $headers)); WsTables::renderTables($output, $tables); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $modules = explode(",", $input->getArgument('modules')); foreach ($modules as $module) { $this->checkIfModuleExistsLocally($module, $output, $input); if (wire('modules')->getModule($module, array('noPermissionCheck' => true))) { $output->writeln("<info>Module {$module} installed successfully.</info>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); // get available fieldtypes $fieldtypes = array(); foreach (\ProcessWire\wire('modules') as $module) { if (preg_match('/^Fieldtype/', $module->name)) { $fieldtypes[] = $module->name; } } WsTools::renderList('Fieldtypes', $fieldtypes, $output); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $logs = \ProcessWire\wire('log')->getLogs(); $output->writeln(WsTools::tint(count($logs) . ' logs', 'comment')); $data = array(); foreach ($logs as $log) { $data[] = array($log['name'], \ProcessWire\wireRelativeTimeStr($log['modified']), \ProcessWire\wire('log')->getTotalEntries($log['name']), \ProcessWire\wireBytesStr($log['size'])); } $headers = array('Name', 'Modified', 'Entries', 'Size'); $tables = array(WsTables::buildTable($output, $data, $headers)); WsTables::renderTables($output, $tables, false); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); $label = $input->getOption('label') !== "" ? $input->getOption('label') : $name; $type = $this->getProperFieldtypeName($input->getOption('type')); $field = new Field(); $field->type = wire('modules')->get($type); $field->name = $name; $field->label = $label; $field->description = $input->getOption('desc'); $field->save(); $output->writeln("<info>Field '{$name}' ({$type}) created successfully!</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $template = \ProcessWire\wire('templates')->get($input->getArgument('template')); $fields = explode(",", $input->getOption('fields')); if (!$input->getOption('fields')) { $output->writeln("<error>Please supply field(s) via --fields!</error>"); exit(1); } if (!\ProcessWire\wire('templates')->get($template)) { $output->writeln("<error>Template {$template} cannot be found!</error>"); exit(1); } $this->assignFieldsToTemplate($fields, $template, $output); $output->writeln("<info>Field(s) added to '{$template}' successfully!</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); if ($input->getOption('target')) { $path = \ProcessWire\wire('config')->paths->root . $input->getOption('target'); } else { $path = \ProcessWire\wire('config')->paths->root . 'dump-' . date('Y-m-d-H-i-s'); } if (!file_exists($path)) { mkdir($path); } $pages = \ProcessWire\wire('pages'); if ($input->getOption('selector')) { $pages = \ProcessWire\wire('pages')->find($input->getOption('selector')); } else { $pages = \ProcessWire\wire('pages')->find("has_parent!=2,id!=2|7,status<" . Page::statusTrash . ",include=all"); } $fieldname = $input->getOption('field') ? $input->getOption('field') : 'images'; if ($pages) { $total = 0; $imgNames = array(); foreach ($pages as $page) { if ($page->{$fieldname}) { foreach ($page->{$fieldname} as $img) { if (!in_array($img->name, $imgNames)) { if (function_exists('copy')) { // php 5.5+ copy($img->filename, $path . '/' . $img->name); } else { $content = file_get_contents($img->filename); $fp = fopen($path, "w"); fwrite($fp, $content); fclose($fp); } $total++; $imgNames[] = $img->name; } } } } } if ($total > 0) { $output->writeln("<info>Dumped {$total} images into {$path} successfully.</info>"); } else { $output->writeln("<error>No images found. Recheck your options.</error>"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $database = wire('config')->dbName; $host = wire('config')->dbHost; $user = wire('config')->dbUser; $pass = wire('config')->dbPass; $filename = $input->getOption('filename') ? $input->getOption('filename') . '.sql' : 'dump-' . date("Y-m-d-H-i-s") . '.sql'; try { $dump = new Dump(); $dump->file($filename)->dsn("mysql:dbname={$database};host={$host}")->user($user)->pass($pass)->tmp(getcwd() . 'site/assets/tmp'); new Export($dump); } catch (Exception $e) { echo 'Export failed with message: ' . $e->getMessage(); } $output->writeln("<info>Dumped database into {$filename} successfully.</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $pwStatus = $this->getPWStatus(); $wsStatus = $this->getWsStatus(); $tables = []; $tables[] = $this->buildTable($output, $pwStatus, 'ProcessWire'); $tables[] = $this->buildTable($output, $wsStatus, 'wireshell'); if ($input->getOption('php')) { $phpStatus = $this->getDiagnosePHP(); $tables[] = $this->buildTable($output, $phpStatus, 'PHP Diagnostics'); } if ($input->getOption('image')) { $phpStatus = $this->getDiagnoseImagehandling(); $tables[] = $this->buildTable($output, $phpStatus, 'Image Diagnostics'); } $this->renderTables($output, $tables); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $inputFields = explode(',', $input->getArgument('field')); $fields = \ProcessWire\wire('fields'); foreach ($inputFields as $field) { $fieldToDelete = $fields->get($field); if (is_null($fieldToDelete)) { $output->writeln("\n<error> > Field '{$field}' does not exist!</error>"); continue; } try { $fields->delete($fieldToDelete); $output->writeln("\n<info> > Field '{$field}' deleted successfully!</info>"); } catch (\WireException $e) { $output->writeln("\n<error> > {$e->getMessage()}</error>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $field = $input->getArgument('field'); $fields = wire('fields'); $fieldToClone = $fields->get($field); if (is_null($fieldToClone)) { $output->writeln("<error>Field '{$field}' does not exist!</error>"); return; } $clone = $fields->clone($fieldToClone); if (!empty($input->getOption('name'))) { $clone->name = $input->getOption('name'); $clone->label = ucfirst($input->getOption('name')); $clone->save(); } $name = $input->getOption('name') !== "" ? $input->getOption('name') : $field . 'cloned'; $output->writeln("<info>Field '{$field}' cloned successfully!</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $field = $input->getArgument('field'); $fields = \ProcessWire\wire('fields'); $fieldToEdit = $fields->get($field); if (is_null($fieldToEdit)) { $output->writeln("<error>Field '{$field}' does not exist!</error>"); return; } if ($input->getOption('name')) { $fieldToEdit->name = $input->getOption('name'); } if ($input->getOption('label')) { $fieldToEdit->label = ucfirst($input->getOption('label')); } $fieldToEdit->save(); $output->writeln("<info>Field '{$field}' edited successfully!</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $modules = explode(",", $input->getArgument('modules')); $remove = $input->getOption('rm') === true ? true : false; foreach ($modules as $module) { $this->checkIfModuleExists($module, $output, $remove); if (\ProcessWire\wire('modules')->uninstall($module)) { $output->writeln("Module {$module} <comment>uninstalled</comment> successfully."); } // remove module if ($remove === true && is_dir(\ProcessWire\wire('config')->paths->{$module})) { if ($this->recurseRmdir(\ProcessWire\wire('config')->paths->{$module})) { $output->writeln("Module {$module} was <comment>removed</comment> successfully."); } else { $output->writeln("Module {$module} could not be removed <fg=red>could not be removed</fg=red>."); } } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); // get available fields $fieldtypes = array(); foreach (\ProcessWire\wire('modules') as $module) { if (preg_match('/^Fieldtype/', $module->name)) { $fieldtypes[] = $module->name; } } $headers = array('Name', 'Label', 'Type', 'Templates'); $data = $this->getData($this->getFilter($input)); if (count($data->count) > 0) { foreach ($data->content as $tag => $c) { $output->writeln('<fg=yellow;options=bold> ' . strtoupper($tag) . "</>"); $tables = array(WsTables::buildTable($output, $c, $headers)); WsTables::renderTables($output, $tables, false); } } $output->writeln(WsTools::tint("({$data->count} in set)", 'comment')); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $log = \ProcessWire\wire('log'); $availableLogs = $log->getLogs(); $availableLogsString = implode(array_keys($availableLogs), ', '); $name = $input->getArgument('name'); if (!array_key_exists($name, $availableLogs)) { $output->writeln("<error>Log '{$name}' does not exist, choose one of `{$availableLogsString}`</error>"); return; } $output->writeln(WsTools::tint("Log {$name}", 'comment')); $options = array('limit' => $input->getOption('limit') ? $input->getOption('limit') : 10, 'dateTo' => $input->getOption('to') ? $input->getOption('to') : 'now', 'dateFrom' => $input->getOption('from') ? $input->getOption('from') : '-10years', 'text' => $input->getOption('text') ? $input->getOption('text') : ''); $headers = array('Date', 'User', 'URL', 'Message'); $data = $log->getEntries($name, $options); $tables = array(WsTables::buildTable($output, $data, $headers)); WsTables::renderTables($output, $tables, false); $count = count($data); $total = $log->getTotalEntries($name); $output->writeln(WsTools::tint("({$count} in set, total: {$total})", 'comment')); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $name = $input->getArgument('name'); $label = $input->getOption('label') !== "" ? $input->getOption('label') : $name; $type = PwTools::getProperFieldtypeName($input->getOption('type')); $check = $this->checkFieltype($type); if ($check === true) { $field = new Field(); $field->type = \ProcessWire\wire('modules')->get($type); $field->name = $name; $field->label = $label; $field->description = $input->getOption('desc'); if ($input->getOption('tag')) { $field->tags = $input->getOption('tag'); } $field->save(); $output->writeln("<info>Field '{$name}' ({$type}) created successfully!</info>"); } else { $output->writeln("<error>This fieldtype `{$type}` does not exists.</error>"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $config = \ProcessWire\wire('config'); $database = $config->dbName; $host = $config->dbHost; $user = $config->dbUser; $pass = $config->dbPass; $filename = $input->getOption('filename') ? $input->getOption('filename') . '.sql' : 'dump-' . date("Y-m-d-H-i-s") . '.sql'; $target = $input->getOption('target') ? $input->getOption('target') : ''; if ($target && !preg_match('/$\\//', $target)) { $target = "{$target}/"; } try { $dump = new Dump(); $dump->file($target . $filename)->dsn("mysql:dbname={$database};host={$host}")->user($user)->pass($pass)->tmp(getcwd() . 'site/assets/tmp'); new Export($dump); } catch (Exception $e) { $output->writeln("<error>Export failed with message: {$e->getMessage()}. Please make sure that the provided target exists.</error>"); exit(1); } $output->writeln("<info>Dumped database into `{$target}{$filename}` successfully.</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::checkForProcessWire($output); $output->writeln("Starting PHP server at localhost:8000"); passthru("php -S localhost:8000"); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->fs = new Filesystem(); $this->projectDir = $this->getDirectory($input); $this->projectName = basename($this->projectDir); $this->src = $input->getOption('src') ? $this->getAbsolutePath($input->getOption('src')) : null; $srcStatus = $this->checkExtractedSrc(); $v = $input->getOption('v') ? true : false; $this->output = $output; $profile = $input->getOption('profile'); $branch = $this->getZipURL($input); $logger = new Logger('name'); $logger->pushHandler(new StreamHandler("php://output")); $this->installer = new Installer($logger, $this->projectDir, $v); $this->version = PwConnector::getVersion(); try { if (!$this->checkAlreadyDownloaded() && $srcStatus !== 'extracted') { if (!$srcStatus) { $this->checkProjectName()->download($branch); } $this->extract(); } $this->cleanUp(); } catch (Exception $e) { } try { $install = $input->getOption('no-install') ? false : true; if ($install) { $profile = $this->extractProfile($profile); $this->installer->getSiteFolder($profile); $this->checkProcessWireRequirements(); $helper = $this->getHelper('question'); $post = array('dbName' => '', 'dbUser' => '', 'dbPass' => '', 'dbHost' => 'localhost', 'dbPort' => '3306', 'dbEngine' => 'MyISAM', 'dbCharset' => 'utf8', 'timezone' => '', 'chmodDir' => '755', 'chmodFile' => '644', 'httpHosts' => ''); $dbName = $input->getOption('dbName'); if (!$dbName) { $question = new Question('Please enter the database name : ', 'dbName'); $dbName = $helper->ask($input, $output, $question); } $post['dbName'] = $dbName; $dbUser = $input->getOption('dbUser'); if (!$dbUser) { $question = new Question('Please enter the database user name : ', 'dbUser'); $dbUser = $helper->ask($input, $output, $question); } $post['dbUser'] = $dbUser; $dbPass = $input->getOption('dbPass'); if (!$dbPass) { $question = new Question('Please enter the database password : '******'dbPass'] = $dbPass; $dbHost = $input->getOption('dbHost'); if ($dbHost) { $post['dbHost'] = $dbHost; } $dbPort = $input->getOption('dbPort'); if ($dbPort) { $post['dbPort'] = $dbPort; } $dbEngine = $input->getOption('dbEngine'); if ($dbEngine) { $post['dbEngine'] = $dbEngine; } $dbCharset = $input->getOption('dbCharset'); if ($dbCharset) { $post['dbCharset'] = $dbCharset; } $bundleNames = array('AcmeDemoBundle', 'AcmeBlogBundle', 'AcmeStoreBundle'); $timezone = $input->getOption('timezone'); if (!$timezone) { $question = new Question('Please enter the timezone : ', 'timezone'); $question->setAutocompleterValues(timezone_identifiers_list()); $timezone = $helper->ask($input, $output, $question); } $post['timezone'] = $timezone; $chmodDir = $input->getOption('chmodDir'); if ($chmodDir) { $post['chmodDir'] = $chmodDir; } $chmodFile = $input->getOption('chmodFile'); if ($chmodFile) { $post['chmodFile'] = $chmodFile; } $httpHosts = $input->getOption('httpHosts'); if (!$httpHosts) { $question = new Question('Please enter the hostname without www. Eg: pw.dev : ', 'httpHosts'); $httpHosts = $helper->ask($input, $output, $question); } $post['httpHosts'] = $httpHosts . "\n" . "www." . $httpHosts; $accountInfo = array('admin_name' => 'processwire', 'username' => '', 'userpass' => '', 'userpass_confirm' => '', 'useremail' => '', 'color' => 'classic'); $adminUrl = $input->getOption('adminUrl'); if ($adminUrl) { $accountInfo['admin_name'] = $adminUrl; } $username = $input->getOption('username'); if (!$username) { $question = new Question('Please enter admin user name : ', 'username'); $username = $helper->ask($input, $output, $question); } $accountInfo['username'] = $username; $userpass = $input->getOption('userpass'); if (!$userpass) { $question = new Question('Please enter admin password : '******'password'); $question->setHidden(true); $question->setHiddenFallback(false); $userpass = $helper->ask($input, $output, $question); } $accountInfo['userpass'] = $userpass; $accountInfo['userpass_confirm'] = $userpass; $useremail = $input->getOption('useremail'); if (!$useremail) { $question = new Question('Please enter admin email address : ', 'useremail'); $useremail = $helper->ask($input, $output, $question); } $accountInfo['useremail'] = $useremail; $this->installProcessWire($post, $accountInfo); $this->cleanUpInstallation(); $this->output->writeln("\n<info>Congratulations, ProcessWire has been successfully installed.</info>"); } } catch (\Exception $e) { $this->cleanUp(); throw $e; } }