/**
  * @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>");
 }
示例#2
0
 /**
  * @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) {
             }
         }
     }
 }
示例#3
0
 /**
  * @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
  */
 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
  */
 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);
 }
示例#6
0
 /**
  * @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>");
         }
     }
 }
示例#7
0
 /**
  * @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);
 }
示例#8
0
 /**
  * @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);
 }
示例#9
0
 /**
  * @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>");
 }
示例#11
0
 /**
  * @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>");
     }
 }
示例#12
0
 /**
  * @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>");
 }
示例#13
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $pwStatus = $this->getPWStatus($input->getOption('pass'));
     $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);
 }
示例#14
0
 /**
  * @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>");
         }
     }
 }
示例#15
0
 /**
  * @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>");
 }
示例#16
0
 /**
  * @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);
     $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>.");
             }
         }
     }
 }
示例#18
0
 /**
  * @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'));
 }
示例#19
0
 /**
  * @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'));
 }
示例#20
0
 /**
  * @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>");
     }
 }
示例#21
0
 /**
  * @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>");
 }