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");
         }
     }
 }
Exemple #2
0
 protected function _installExtension($extension)
 {
     /** verify package retrieved **/
     $installer = new InstallerModelDiscover();
     $results = $installer->purge();
     if ($results) {
     } else {
         JFactory::getApplication()->setUserState('com_jfoobar.message', JText::_('PLG_SYSTEM_CREATE_PURGE_DISCOVERY_FAILED'));
         return false;
     }
     /** verify package retrieved (discover does not return a condition) **/
     $result = $installer->discover();
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select('extension_id');
     $query->from('`#__extensions`');
     $query->where('`state`= -1');
     $query->where('`element`=' . $db->quote($extension));
     $db->setQuery((string) $query);
     $discoveredExtensionID = $db->loadResult();
     if ((int) $discoveredExtensionID > 0) {
     } else {
         JFactory::getApplication()->enqueueMessage(JText::_('PLG_SYSTEM_CREATE_RETRIEVE_EXTENSION_ID_FAILED') . ': ' . $discoveredExtensionID, 'error');
         return false;
     }
     /** install created extension **/
     $installer = JInstaller::getInstance();
     $result = $installer->discover_install($discoveredExtensionID);
     if ($result) {
     } else {
         JFactory::getApplication()->enqueueMessage(JText::_('PLG_SYSTEM_CREATE_MSG_DISCOVER_INSTALL_FAILED') . ': ' . $discoveredExtensionID, 'error');
         return false;
     }
     $this->setState('action', 'remove');
     $this->setState('name', $installer->get('name'));
     JFactory::getApplication()->setUserState('com_jfoobar.message', $installer->message);
     JFactory::getApplication()->setUserState('com_jfoobar.extension_message', $installer->get('extension_message'));
     /** double-check that the extension is no longer listed as not installed **/
     $query = 'SELECT extension_id FROM #__extensions where state = -1 AND extension_id = ' . (int) $discoveredExtensionID;
     $dbo = JFactory::getDBO();
     $query = $dbo->getQuery(true);
     $dbo->setQuery($query);
     $discoveredExtensionID = $dbo->loadResult();
     if ((int) $discoveredExtensionID > 0) {
         JFactory::getApplication()->setUserState('com_jfoobar.message', JText::_('PLG_SYSTEM_CREATE_INSTALL_EXTENSION_FAILED'));
         return false;
     }
     /** results **/
     JFactory::getApplication()->enqueueMessage(JText::sprintf('PLG_SYSTEM_CREATE_INSTALL_SUCCESS', JText::_('PLG_SYSTEM_CREATE_INSTALL_TYPE_' . strtoupper($this->getState('create.createtype')))));
     return true;
 }
 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;
             }
         }
     }
 }