示例#1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     foreach (\ProcessWire\wire('roles') as $role) {
         $output->writeln("  - {$role->name}");
     }
 }
示例#2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $email = $input->getOption('email');
     $pass = $input->getOption('password');
     $roles = explode(",", $input->getOption('roles'));
     $helper = $this->getHelper('question');
     if (!$email) {
         $question = new Question('Please enter a email address : ', 'email');
         $email = $helper->ask($input, $output, $question);
     }
     if (!$pass) {
         $question = new Question('Please enter a password : '******'password');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $pass = $helper->ask($input, $output, $question);
     }
     if (!\ProcessWire\wire("pages")->get("name={$name}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<error>User '{$name}' already exists!</error>");
         exit(1);
     }
     $user = $this->createUser($email, $name, $this->userContainer, $pass);
     $user->save();
     if ($input->getOption('roles')) {
         $this->attachRolesToUser($name, $roles, $output);
     }
     if ($pass) {
         $output->writeln("<info>User '{$name}' created successfully!</info>");
     } else {
         $output->writeln("<info>User '{$name}' created successfully! Please do not forget to set a password.</info>");
     }
 }
示例#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 $field
  * @param $output
  * @return bool
  */
 private function checkIfFieldExists($field, $output)
 {
     if (!\ProcessWire\wire("fields")->get("{$field}")) {
         $output->writeln("<error>Field '{$field}' does not exist!</error>");
         return false;
     }
 }
示例#6
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $pages = \ProcessWire\wire('pages');
     foreach (explode(',', $input->getArgument('selector')) as $selector) {
         $select = is_numeric($selector) ? (int) $selector : "/{$selector}/";
         $trashPages = $pages->find($select, array('include' => 'all'));
         if ($trashPages->count() === 0) {
             $trashPages = $pages->find($selector, array('include' => 'all'));
         }
         if ($trashPages->count() === 0) {
             $output->writeln("<error>No pages were found using `{$selector}`.</error>");
         }
         foreach ($trashPages as $trashPage) {
             if ($trashPage instanceof \ProcessWire\NullPage) {
                 $output->writeln("<error>Page `{$selector}` doesn't exist.</error>");
             } else {
                 $delete = $input->getOption('rm') === true ? true : false;
                 $title = $trashPage->title;
                 if ($delete === true) {
                     $pages->delete($trashPage, true);
                     $output->writeln("<info>Page `{$title}` was successfully deleted.</info>");
                 } else {
                     $pages->trash($trashPage, true);
                     $output->writeln("<info>Page `{$title}` has been successfully moved to the trash.</info>");
                 }
             }
         }
     }
 }
示例#7
0
 /**
  * get templates data
  *
  * @param object $filter
  * @return array
  */
 private function getData($filter)
 {
     $content = array();
     $count = 0;
     foreach (\ProcessWire\wire('fields') as $field) {
         // no filter, exclude built-in fields except title
         if ($filter->all === false && ($field->flags & Field::flagSystem || $field->flags & Field::flagPermanent)) {
             if ($field->name != 'title') {
                 continue;
             }
         }
         // filter unused fields
         if ($filter->unused && $field->getTemplates()->count()) {
             continue;
         }
         // filter by template
         if ($filter->template && !$field->getTemplates()->has($filter->template)) {
             continue;
         }
         // filter by tag
         if ($filter->tag && !$this->fieldHasTag($field->tags, $filter->tag)) {
             continue;
         }
         // filter by field type
         if ($filter->type && $field->type != $filter->type) {
             continue;
         }
         // get row content
         $fieldContent = array($field->name, $field->label, str_replace('Fieldtype', '', $field->type), $field->getTemplates()->count);
         // add field by tag
         if (!$field->tags) {
             $tag = 'untagged';
             if (!isset($content[$tag])) {
                 $content[$tag] = array();
             }
             $content[$tag][$field->name] = $fieldContent;
         } else {
             $tags = explode(' ', $field->tags);
             foreach ($tags as $tag) {
                 if (!$tag) {
                     continue;
                 }
                 $tag = strtolower(ltrim($tag, '-'));
                 if (substr($tag, 0, 1) === '-') {
                     ltrim($tag, '-');
                 }
                 if (!isset($content[$tag])) {
                     $content[$tag] = array();
                 }
                 $content[$tag][$field->name] = $fieldContent;
             }
         }
         $count++;
     }
     ksort($content);
     return (object) array('count' => $count, 'content' => $content);
 }
示例#8
0
 /**
  * get users
  *
  * @param InputInterface $input
  */
 private function getUsers($input)
 {
     $role = $input->getOption('role');
     if ($role) {
         $users = \ProcessWire\wire('users')->find('roles=' . $input->getOption('role'))->sort('name');
     } else {
         $users = \ProcessWire\wire('users')->find('start=0')->sort('name');
     }
     return $users;
 }
 private function checkIfModuleExists($module, $output, $remove)
 {
     if (!is_dir(\ProcessWire\wire('config')->paths->siteModules . $module)) {
         $output->writeln("<error>Module '{$module}' does not exist!</error>");
         exit(1);
     }
     if (!\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true)) && $remove === false) {
         $output->writeln("<info>Module '{$module}' is not installed!</info>");
         exit(1);
     }
 }
示例#10
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);
 }
示例#11
0
 /**
  * get templates data
  *
  * @param boolean $advanced
  * @return array
  */
 private function getTemplateData($advanced)
 {
     $content = array();
     $advanced = \ProcessWire\wire('config')->advanced || $advanced;
     foreach (\ProcessWire\wire('templates') as $t) {
         if (!$advanced && $t->flags & Template::flagSystem) {
             continue;
         }
         $content[] = array($t->name, count($t->fieldgroup), $t->getNumPages(), \ProcessWire\wireRelativeTimeStr($t->modified), $t->flags & Template::flagSystem ? '✖' : '');
     }
     return $content;
 }
示例#12
0
 /**
  * @param $type
  */
 protected function checkFieltype($type)
 {
     // get available fieldtypes
     $fieldtypes = array();
     foreach (\ProcessWire\wire('modules') as $module) {
         if (preg_match('/^Fieldtype/', $module->name)) {
             $fieldtypes[] = $module->name;
         }
     }
     // check whether fieldtype exists
     return in_array($type, $fieldtypes) ? true : false;
 }
示例#13
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);
 }
示例#14
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $names = explode(',', preg_replace('/\\s+/', '', $input->getArgument('name')));
     foreach ($names as $name) {
         if (!\ProcessWire\wire('roles')->get($name) instanceof \ProcessWire\NullPage) {
             $output->writeln("<error>Role '{$name}' already exists!</error>");
             exit(1);
         }
         \ProcessWire\wire('roles')->add($name);
         $output->writeln("<info>Role '{$name}' created successfully!</info>");
     }
 }
 /**
  * check if a module exists in processwire module directory
  *
  * @param string $module
  */
 public function downloadModuleIfExists($module)
 {
     $contents = file_get_contents(\ProcessWire\wire('config')->moduleServiceURL . '?apikey=' . \ProcessWire\wire('config')->moduleServiceKey . '&limit=1' . '&class_name=' . $module);
     $result = json_decode($contents);
     if ($result->status === 'error') {
         $this->output->writeln(" <error> A module with the class '{$module}' does not exist. </error>\n");
     } else {
         // yeah! module exists
         $item = $result->items[0];
         $moduleUrl = $item->project_url . '/archive/master.zip';
         $this->downloadModuleByUrl($module, $moduleUrl);
     }
 }
示例#16
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>");
     }
 }
示例#17
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $roles = explode(",", $input->getOption('roles'));
     $pass = $input->getOption('password');
     if (\ProcessWire\wire("pages")->get("name={$name}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<error>User '{$name}' doesn't exists!</error>");
         exit(1);
     }
     $user = $this->updateUser($input, $name, $pass);
     $user->save();
     if ($input->getOption('roles')) {
         $this->attachRolesToUser($name, $roles, $output, true);
     }
     $output->writeln("<info>User '{$name}' updated successfully!</info>");
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $pages = \ProcessWire\wire('pages');
     $config = \ProcessWire\wire('config');
     $trashed = "parent_id={$config->trashPageID},limit={$this->maxItems},";
     $trashed .= "status<" . Page::statusMax . ",include=all";
     $trashPages = $pages->find($trashed);
     if ($trashPages->getTotal() > 0) {
         $output->writeln("<question>{$trashPages->getTotal()} pages were found.</question>\n");
         foreach ($trashPages as $t) {
             $pages->delete($t, true);
         }
         $output->writeln("<info>The trash was successfully cleared.</info>");
     } else {
         $output->writeln("<info>The trash is already empty.</info>");
     }
 }
示例#19
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>");
         }
     }
 }
示例#20
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>");
 }
示例#21
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'));
 }
示例#22
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     if ($role = $input->getOption('role')) {
         $users = \ProcessWire\wire('users')->find("roles={$role}");
         foreach ($users as $user) {
             \ProcessWire\wire('users')->delete($user);
         }
         $output->writeln("<info>Deleted {$users->count()} users successfully!</info>");
     } else {
         $users = explode(',', $input->getArgument('name'));
         foreach ($users as $name) {
             if (\ProcessWire\wire('users')->get($name) instanceof \ProcessWire\NullPage) {
                 $output->writeln("<error>User '{$name}' doesn't exists!</error>");
             } else {
                 $user = \ProcessWire\wire('users')->get($name);
                 \ProcessWire\wire('users')->delete($user);
                 $output->writeln("<info>User '{$name}' deleted successfully!</info>");
             }
         }
     }
 }
示例#23
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) {
         // if module doesn't exist, download the module
         if (!$this->checkIfModuleExists($module)) {
             $output->writeln("<comment>Cannot find '{$module}' locally, trying to download...</comment>");
             $this->passOnToModuleDownloadCommand($module, $output, $input);
         }
         // check whether module is already installed
         if (\ProcessWire\wire('modules')->isInstalled($module)) {
             $output->writeln("<info>Module `{$module}` is already installed.</info>");
             exit(1);
         }
         // install module
         if (\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true))) {
             $output->writeln("<info>Module `{$module}` installed successfully.</info>");
         } else {
             $output->writeln("<error>Module `{$module}` does not exist.</error>");
         }
     }
 }
示例#24
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>");
 }
示例#25
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $check = parent::checkForCoreUpgrades($output, $input);
     $this->output = $output;
     $this->root = \ProcessWire\wire('config')->paths->root;
     if ($check['upgrade'] && $input->getOption('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('download'), $input, $output);
             } catch (Exception $e) {
             }
         }
     }
 }
示例#26
0
 /**
  * @param $output
  * @param InputInterface $input - whether branch name or commit
  * @return boolean
  */
 protected function checkForCoreUpgrades($output, $input)
 {
     $config = \ProcessWire\wire('config');
     $targetBranch = $this->determineBranch($input);
     $branches = $this->getCoreBranches($targetBranch);
     $upgrade = false;
     $new = version_compare($branches['master']['version'], $config->version);
     // branch does not exist - assume commit hash
     if (!array_key_exists($targetBranch, $branches)) {
         $branch = $branches['sha'];
         $upgrade = true;
     } elseif ($new > 0 && $targetBranch === self::BRANCH_MASTER) {
         // master is newer than current
         $branch = $branches['master'];
         $upgrade = true;
     }
     $versionStr = "{$branch['name']} {$branch['version']}";
     if ($upgrade) {
         $output->writeln("<info>A ProcessWire core upgrade is available: {$versionStr}</info>");
     } else {
         $output->writeln("<info>Your ProcessWire core is up-to-date: {$versionStr}</info>");
     }
     return array('upgrade' => $upgrade, 'branch' => $branch);
 }
示例#27
0
 /**
  * @return string
  */
 protected function getAdminUrl()
 {
     $admin = \ProcessWire\wire('pages')->get('template=admin');
     $url = \ProcessWire\wire('config')->urls->admin;
     if (!$admin instanceof \ProcessWire\NullPage && isset($admin->httpUrl)) {
         $url = $admin->httpUrl;
     }
     return $url;
 }
 protected function getDefaults()
 {
     return ['version' => '0.0.1', 'requirePw' => \ProcessWire\wire('config')->version, 'requirePhp' => PHP_VERSION];
 }
示例#29
0
 /**
  * Populate any non-required fields before the second save
  *
  * @param string $data file content
  * @param string $ext file extension
  * @param OutputInterface $output
  * @param Page $p
  *
  */
 protected function addFieldContent($data, $ext, $output, $p)
 {
     if ($ext === 'json') {
         foreach ($data as $fieldname => $fieldval) {
             $fieldname = strtolower($fieldname);
             if ($p->{$fieldname}) {
                 if ($fieldname === 'name') {
                     $fieldval = \ProcessWire\wire('sanitizer')->pageName($fieldval);
                 }
                 $p->{$fieldname} = $fieldval;
             } else {
                 $output->writeln("<comment>For the chosen template field `{$fieldname}` does not exist.\n</comment>");
             }
         }
     }
     // finally save the field data as well
     $p->save();
 }
示例#30
0
 /**
  * @param $role
  * @param $output
  * @return bool
  */
 private function checkIfRoleExists($role, $output)
 {
     if (\ProcessWire\wire("pages")->get("name={$role}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<comment>Role '{$role}' does not exist!</comment>");
         return false;
     }
 }