protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); Bootstrapper::getApplication($this->target_dir); $this->_user_column = $input->getOption('user-column'); $this->_date_column = $input->getOption('date-column'); $dbo = \JFactory::getDbo(); $prefix = \JFactory::getApplication()->get('dbprefix'); $nullDate = $dbo->getNullDate(); $tables = $this->_getTables(); if ($input_tables = $input->getArgument('tables')) { $tables = array_intersect($tables, $input_tables); } if (empty($tables)) { $output->writeln("<comment>Nothing to check in</comment>"); } foreach ($tables as $table) { $output->write("<comment>Checking in the {$table} table ... </comment>"); $table = $prefix . $table; $query = $dbo->getQuery(true)->update($dbo->quoteName($table))->set(sprintf('%s = 0', $this->_user_column))->set(sprintf('%s = %s', $this->_date_column, $dbo->quote($nullDate)))->where(sprintf('%s > 0', $this->_user_column)); $dbo->setQuery($query); if ($dbo->execute()) { $affected = $dbo->getAffectedRows(); $format = '[<info>OK</info>] (%d %s checked in)'; $message = sprintf($format, $affected, $affected == 1 ? 'row' : 'rows'); $output->writeln("{$message}"); } else { $output->writeln("[<error>FAILED</error>]"); } } }
public function uninstall(InputInterface $input, OutputInterface $output) { $app = Bootstrapper::getApplication($this->target_dir); ob_start(); $installer = $app->getInstaller(); foreach ($this->extensions as $extension) { $dbo = \JFactory::getDbo(); $query = \JFactory::getDbo()->getQuery(true)->select('*')->from('#__extensions')->where($dbo->quoteName('element') . ' = ' . $dbo->quote($extension)); $dbo->setQuery($query); $row = $dbo->loadObject(); if (!$row || !$row->extension_id) { throw new \RuntimeException(sprintf('Extension Uninstall: %s extension not found', $extension)); } if ($row->protected) { throw new \RuntimeException(sprintf('Extension Uninstall: %s is a core extension', $extension)); } $result = $installer->uninstall($row->type, $row->extension_id); if ($result) { $output->writeln('<info>' . $row->name . ' extension deleted </info>'); } else { throw new \RuntimeException(sprintf('Extension Uninstall: failed to delete %s extension', $extension)); } } ob_end_clean(); }
public function install(InputInterface $input, OutputInterface $output) { $app = Bootstrapper::getApplication($this->target_dir); // Output buffer is used as a guard against Joomla including ._ files when searching for adapters // See: http://kadin.sdf-us.org/weblog/technology/software/deleting-dot-underscore-files.html ob_start(); $installer = $app->getInstaller(); foreach ($this->extension as $package) { $remove = false; if (is_file($package)) { $result = \JInstallerHelper::unpack($package); $directory = isset($result['dir']) ? $result['dir'] : false; $remove = true; } else { $directory = $package; } if ($directory !== false) { $path = realpath($directory); if (!file_exists($path)) { $output->writeln("<info>File not found: " . $directory . "</info>\n"); continue; } try { $installer->install($path); } catch (\Exception $e) { $output->writeln("<info>Caught exception during install: " . $e->getMessage() . "</info>\n"); } if ($remove) { \JFolder::delete($path); } } } ob_end_clean(); }
public function install(InputInterface $input, OutputInterface $output) { $app = Bootstrapper::getApplication($this->target_dir); // Output buffer is used as a guard against Joomla including ._ files when searching for adapters // See: http://kadin.sdf-us.org/weblog/technology/software/deleting-dot-underscore-files.html ob_start(); $installer = $app->getInstaller(); $installer->discover(); require_once $app->getPath() . '/administrator/components/com_installer/models/discover.php'; $model = new \InstallerModelDiscover(); $model->discover(); $results = $model->getItems(); $install = array(); foreach ($results as $result) { if ($result->element === 'com_extman') { array_unshift($install, $result->extension_id); } if ($result->type === 'component' && (in_array(substr($result->element, 4), $this->extension) || in_array($result->element, $this->extension))) { $install[] = $result->extension_id; } } ob_end_clean(); if (class_exists('Koowa') && !class_exists('ComExtmanDatabaseRowExtension')) { \KObjectManager::getInstance()->getObject('com://admin/extman.database.row.extension'); } $install = array_unique($install); foreach ($install as $extension_id) { try { $installer->discover_install($extension_id); } catch (\Exception $e) { $output->writeln("<info>Caught exception during install: " . $e->getMessage() . "</info>\n"); } } }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->check($input, $output); Bootstrapper::getApplication($this->target_dir); $catalogue = \KObjectManager::getInstance()->getObject('com://admin/koowa.translator')->getCatalogue(); $output->writeln($catalogue->getPrefix() . $catalogue->generateKey($input->getArgument('string'))); }
public function register(InputInterface $input, OutputInterface $output) { $app = Bootstrapper::getApplication($this->target_dir); ob_start(); // build the record. $data = new \JObject(); $data->name = $this->extension; $data->type = $this->type; $data->element = $this->extension; $data->client_id = $input->getOption('client_id'); $data->enabled = $input->getOption('enabled'); $data->position = $input->getOption('position'); $element = $input->getOption('element'); if (strlen($element)) { $data->element = $element; } // special case for plugin, naming and folder. if ($this->type == 'plugin') { // set the default folder for plugins only. $data->folder = $input->getOption('folder') ? $input->getOption('folder') : 'system'; // special case for the plugins only. if (substr($data->element, 0, 4) == 'plg_') { $data->element = substr($data->element, 4); } } if ($this->type == 'template') { if (substr($data->name, 0, 4) == 'tpl_') { $data->name = substr($data->name, 4); $data->element = substr($data->element, 4); } } //need to be sure that a prefix is provided for components and modules if (($this->type == "component" || $this->type == "module") && strpos($data->element, '_') === false) { $prefix = array_search($this->type, $this->typeMap); $data->element = $prefix . $this->extension; } // get the #__extensions model and table require_once JPATH_ADMINISTRATOR . '/components/com_installer/models/extension.php'; $model = new \InstallerModel(); $table = $model->getTable('extension', 'JTable'); // restrict on same name and type $unique = array('name' => $data->name, 'type' => $data->type); // does the extension exist? if (!$table->load($unique)) { if ($table->save($data->getProperties())) { if (array_key_exists($this->type, $this->exceptions)) { $this->handleExceptions($output, $app, $data, $this->type); } $output->writeln("<info>Your extension registered as a '{$this->type}', with extension_id: {$table->extension_id}</info>"); } else { $output->writeln("<info>" . $table->getError() . "</info>"); } } else { $output->writeln("<error>{$this->extension} {$this->type}: That extension already exists.</error>"); } ob_end_clean(); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->app = Bootstrapper::getApplication($this->target_dir); // Load Library language $lang = \JFactory::getLanguage(); // Try the finder_cli file in the current language (without allowing the loading of the file in the default language) $path = Util::isPlatform($this->target_dir) ? JPATH_SITE . '/components/com_finder' : JPATH_SITE; $lang->load('finder_cli', $path, null, false, false) || $lang->load('finder_cli', $path, null, true); // Fallback to the finder_cli file in the default language $this->check($input, $output); $this->purgeFinder($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); Bootstrapper::getApplication($this->target_dir); $this->url = $input->getOption('application-url'); if ($this->url == 'http://localhost/<site>') { $this->url = 'http://localhost/' . $this->site . '/'; } if (substr($this->url, -1) != '/') { $this->url .= '/'; } $this->check($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->target_dir = $input->getOption('base'); $this->app = Bootstrapper::getApplication($this->target_dir); if (!$input->hasOption('pass')) { require_once JPATH_BASE . '/libraries/joomla/user/helper.php'; $pass = \JUserHelper::genRandomPassword(14); } else { $pass = $input->getOption('pass'); } $this->groups = $this->getGroups(); $group = $this->groups[$input->getOption('group')]; $this->userParams = (object) array('name' => $input->getOption('name'), 'user' => $input->getOption('user'), 'pass' => $pass, 'email' => $input->getOption('email'), 'group' => $group->id); }
protected function toggle($enable = false) { Bootstrapper::getApplication($this->target_dir); $dbo = \JFactory::getDbo(); $query = \JFactory::getDbo()->getQuery(true)->select('extension_id')->from('#__extensions')->where($dbo->quoteName('element') . " = " . $dbo->quote($this->extension)); $dbo->setQuery($query); $extension = $dbo->loadResult('extension_id'); if (!$extension) { throw new \RuntimeException("{$this->extension} does not exist"); } $table = \JTable::getInstance('Extension'); $table->load($extension); if ($table->protected == 1) { throw new \RuntimeException("Cannot disable core component {$this->extension}"); } $table->enabled = (int) $enable; if (!$table->store()) { throw new \RuntimeException("Failed to update row: " . $table->getError()); } }
public function install(InputInterface $input, OutputInterface $output) { $app = Bootstrapper::getApplication($this->target_dir); $db = \JFactory::getDbo(); // Output buffer is used as a guard against Joomla including ._ files when searching for adapters // See: http://kadin.sdf-us.org/weblog/technology/software/deleting-dot-underscore-files.html ob_start(); $installer = $app->getInstaller(); $installer->discover(); require_once JPATH_ADMINISTRATOR . '/components/com_installer/models/discover.php'; $model = new \InstallerModelDiscover(); $model->discover(); $results = $model->getItems(); ob_end_clean(); $install = array(); $plugins = array(); foreach ($this->extensions as $extension) { foreach ($results as $result) { $included = false; if (in_array($result->element, array('com_extman', 'koowa')) && ($extension == 'all' || $extension == $result->element)) { array_unshift($install, $result); $included = true; } elseif ($extension == 'all' || in_array($extension, array($result->element, substr($result->element, 4)))) { $install[] = $result; $included = true; } if ($result->type == 'plugin' && $included) { $plugins[] = $result->extension_id; } if ($included && $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Queued {$result->name} for installation."); } } } foreach ($install as $extension) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Installing {$extension->element} .."); } try { $installer->discover_install($extension->extension_id); } catch (\Exception $e) { $output->writeln("<info>Caught exception whilst installing {$extension->type} {$extension->element}: " . $e->getMessage() . "</info>\n"); } if (in_array($extension->extension_id, $plugins)) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Enabling plugin `{$extension->element}` (ID #{$extension->extension_id}) .."); } $sql = "UPDATE `#__extensions` SET `enabled` = 1 WHERE `extension_id` = '{$extension->extension_id}'"; $db->setQuery($sql); $db->execute(); switch ($extension->element) { case 'com_extman': if (class_exists('Koowa') && !class_exists('ComExtmanDatabaseRowExtension')) { \KObjectManager::getInstance()->getObject('com://admin/extman.database.row.extension'); } break; case 'koowa': $path = JPATH_PLUGINS . '/system/koowa/koowa.php'; if (!file_exists($path)) { return; } require_once $path; if (class_exists('\\PlgSystemKoowa')) { $dispatcher = \JEventDispatcher::getInstance(); new \PlgSystemKoowa($dispatcher, (array) \JPLuginHelper::getPLugin('system', 'koowa')); } if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Initialised new PlgSystemKoowa instance"); } break; } } } }
public function modifyConfiguration() { if (!$this->version) { return; } $source = $this->target_dir . '/installation/configuration.php-dist'; $target = $this->target_dir . '/configuration.php'; $contents = file_get_contents($source); $replace = function ($name, $value, &$contents) { $pattern = sprintf("#%s = '.*?'#", $name); $match = preg_match($pattern, $contents); if (!$match) { $pattern = "/^\\s?(\\})\\s?\$/m"; $replacement = sprintf("\tpublic \$%s = '%s';\n}", $name, $value); } else { $replacement = sprintf("%s = '%s'", $name, $value); } $contents = preg_replace($pattern, $replacement, $contents); }; $remove = function ($name, &$contents) { $pattern = sprintf("#public \$%s = '.*?'#", $name); $contents = preg_replace($pattern, '', $contents); }; $random = function ($length) { $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $string = ''; $count = strlen($charset); while ($length--) { $string .= $charset[mt_rand(0, $count - 1)]; } return $string; }; $replacements = array('db' => $this->target_db, 'user' => $this->mysql->user, 'password' => $this->mysql->password, 'dbprefix' => $this->dbprefix . '_', 'dbtype' => 'mysqli', 'mailer' => 'smtp', 'mailfrom' => '*****@*****.**', 'fromname' => $this->site, 'sendmail' => '/usr/bin/env catchmail', 'smtpauth' => '0', 'smtpuser' => '', 'smtppass' => '', 'smtphost' => 'localhost', 'smtpsecure' => 'none', 'smtpport' => '1025', 'sef' => '1', 'sef_rewrite' => '1', 'unicodeslugs' => '1', 'debug' => '1', 'lifetime' => '600', 'tmp_path' => $this->target_dir . '/tmp', 'log_path' => $this->target_dir . '/logs', 'sitename' => $this->site, 'secret' => $random(16)); foreach ($replacements as $key => $value) { $replace($key, $value, $contents); } $remove('root_user', $contents); file_put_contents($target, $contents); chmod($target, 0644); `mv {$this->target_dir}/installation {$this->target_dir}/_installation`; `cp {$this->target_dir}/htaccess.txt {$this->target_dir}/.htaccess`; // Set com_users params - turn off user registration and email verification $this->app = Bootstrapper::getApplication($this->target_dir); require_once JPATH_BASE . '/libraries/cms/component/helper.php'; $comUserId = \JComponentHelper::getComponent('com_users')->id; $userParams = \JComponentHelper::getParams('com_users'); $userParams->set('allowUserRegistration', 0); $userParams->set('sendpassword', 0); $userParams->set('useractivation', 0); $table = \JTable::getInstance('extension'); $table->load($comUserId); $table->bind(array('params' => $userParams->toString())); // Save to database if (!$table->store()) { $this->setError('userParams: store: ' . $table->getError()); return false; } }