/** * Method to run after an install/update/uninstall method * * @param string $type * @param JInstallerAdapterComponent $parent * * @return void */ public function postflight($type, \JInstallerAdapterComponent $parent) { $db = JFactory::getDbo(); // Get install manifest // ======================================================================== $p_installer = $parent->getParent(); $installer = new JInstaller(); $manifest = $p_installer->manifest; $path = $p_installer->getPath('source'); $result = array(); $css = <<<CSS <style type="text/css"> #ak-install-img { } #ak-install-msg { } </style> CSS; echo $css; $installScript = dirname($path) . '/windwalker/src/System/installscript.php'; if (!is_file($installScript)) { $installScript = JPATH_LIBRARIES . '/windwalker/src/System/installscript.php'; } include $installScript; }
/** * Copying files * * @param string $type Installation type * @param JInstallerAdapterComponent $parent Installation adapter * * @return bool False if something happens */ public function postflight($type, $parent) { // Enabling Neno plugin $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->update('#__extensions')->set('enabled = 1')->where(array('type = ' . $db->quote('plugin'), 'folder = ' . $db->quote('system'), 'element = ' . $db->quote('neno'))); $db->setQuery($query); $db->execute(); $parent->getParent()->setRedirectURL(JRoute::_('index.php?option=com_neno&view=installation', false)); return true; }
/** * Copying files * * @param string $type Installation type * @param JInstallerAdapterComponent $parent Installation adapter * * @return bool False if something happens */ public function postflight($type, $parent) { $installationPath = $parent->getParent()->getPath('source'); jimport('joomla.filesystem.folder'); // If the layout folder exists, let's delete them first if (JFolder::exists(JPATH_ROOT . '/layouts/libraries/neno')) { JFolder::delete(JPATH_ROOT . '/layouts/libraries/neno'); } // Moving Layouts JFolder::move($installationPath . '/layouts', JPATH_ROOT . '/layouts/libraries/neno'); // If the media folder exists, let's delete them first if (JFolder::exists(JPATH_ROOT . '/media/neno')) { JFolder::delete(JPATH_ROOT . '/media/neno'); } // Moving media files JFolder::move($installationPath . '/media', JPATH_ROOT . '/media/neno'); return true; }
/** * Executed on install/update/discover * * @param string $type - the type of th einstallation * @param JInstallerAdapterComponent $parent - the parent JInstaller obeject * * @throws Exception - if library is not found * * @return boolean - true if everything is OK and we should continue with the installation */ public function preflight($type, $parent) { $path = $parent->getParent()->getPath('source') . '/libraries/compojoom/libraries/compojoom/include.php'; // Check if the file exists (on discover install it won't) if (JFile::exists($path)) { require_once $path; } else { // Try fallback to installed one $path = JPATH_ROOT . '/libraries/compojoom/include.php'; if (JFile::exists($path)) { require_once $path; } else { throw new Exception("Compojoom library not found", 404); } } $this->installer = new CompojoomInstaller($type, $parent, 'com_cmc'); if (!$this->installer->allowedInstall()) { return false; } return true; }
/** * Constructor * * @param string $type - the installation type * @param JInstallerAdapterComponent $parent - the parent object of the JInstaller * @param string $extName - the extension name */ public function __construct($type, $parent, $extName) { $this->type = $type; $this->parent = $parent; // Load the library lang files if ($type == 'uninstall') { CompojoomLanguage::load('lib_compojoom', JPATH_ROOT); CompojoomLanguage::load('lib_compojoom.sys', JPATH_ROOT); // Now les us load the extension files CompojoomLanguage::load($extName, JPATH_ADMINISTRATOR); CompojoomLanguage::load($extName . '.sys', JPATH_ADMINISTRATOR); } else { CompojoomLanguage::load('lib_compojoom', $parent->getParent()->getPath('source') . '/libraries/compojoom'); CompojoomLanguage::load('lib_compojoom.sys', $parent->getParent()->getPath('source') . '/libraries/compojoom'); // Now les us load the extension files CompojoomLanguage::load($extName, $parent->getParent()->getPath('source') . '/administrator'); CompojoomLanguage::load($extName . '.sys', $parent->getParent()->getPath('source') . '/administrator'); } // Since Joomla translates the message before it has loaded the correct lang files // let us translate themessage again $manifest = $parent->getParent()->getManifest(); $parent->getParent()->set('message', JText::_((string) $manifest->description)); $this->addCss(); }
/** * @param JInstallerAdapterComponent $parent * * @return bool * * @throws Exception When the Joomla! menu is FUBAR */ private function _createAdminMenus($parent) { $db = $db = F0FPlatform::getInstance()->getDbo(); /** @var JTableMenu $table */ $table = JTable::getInstance('menu'); $option = $parent->get('element'); // If a component exists with this option in the table then we don't need to add menus $query = $db->getQuery(true)->select('m.id, e.extension_id')->from('#__menu AS m')->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')->where('m.parent_id = 1')->where('m.client_id = 1')->where($db->qn('e') . '.' . $db->qn('type') . ' = ' . $db->q('component'))->where('e.element = ' . $db->quote($option)); $db->setQuery($query); $componentrow = $db->loadObject(); // Check if menu items exist if ($componentrow) { // @todo Return if the menu item already exists to save some time //return true; } // Let's find the extension id $query->clear()->select('e.extension_id')->from('#__extensions AS e')->where('e.type = ' . $db->quote('component'))->where('e.element = ' . $db->quote($option)); $db->setQuery($query); $component_id = $db->loadResult(); // Ok, now its time to handle the menus. Start with the component root menu, then handle submenus. $menuElement = $parent->get('manifest')->administration->menu; // We need to insert the menu item as the last child of Joomla!'s menu root node. By default this is the // menu item with ID=1. However, some crappy upgrade scripts enjoy screwing it up. Hey, ho, the workaround // way I go. $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('id') . ' = ' . $db->q(1)); $rootItemId = $db->setQuery($query)->loadResult(); if (is_null($rootItemId)) { // Guess what? The Problem has happened. Let's find the root node by title. $rootItemId = null; $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('title') . ' = ' . $db->q('Menu_Item_Root')); $rootItemId = $db->setQuery($query, 0, 1)->loadResult(); } if (is_null($rootItemId)) { // For crying out loud, did that idiot changed the title too?! Let's find it by alias. $rootItemId = null; $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('alias') . ' = ' . $db->q('root')); $rootItemId = $db->setQuery($query, 0, 1)->loadResult(); } if (is_null($rootItemId)) { // Dude. Dude! Duuuuuuude! The alias is screwed up, too?! Find it by component ID. $rootItemId = null; $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('component_id') . ' = ' . $db->q('0')); $rootItemId = $db->setQuery($query, 0, 1)->loadResult(); } if (is_null($rootItemId)) { // Your site is more of a "s***e" than a "site". Let's try with minimum lft value. $rootItemId = null; $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->order($db->qn('lft') . ' ASC'); $rootItemId = $db->setQuery($query, 0, 1)->loadResult(); } if (is_null($rootItemId)) { // I quit. Your site is broken. What the hell are you doing with it? I'll just throw an error. throw new Exception("Your site is broken. There is no root menu item. As a result it is impossible to create menu items. The installation of this component has failed. Please fix your database and retry!", 500); } if ($menuElement) { $data = array(); $data['menutype'] = 'main'; $data['client_id'] = 1; $data['title'] = (string) trim($menuElement); $data['alias'] = (string) $menuElement; $data['link'] = 'index.php?option=' . $option; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $component_id; $data['img'] = (string) $menuElement->attributes()->img ? (string) $menuElement->attributes()->img : 'class:component'; $data['home'] = 0; $data['path'] = ''; $data['params'] = ''; } else { $data = array(); $data['menutype'] = 'main'; $data['client_id'] = 1; $data['title'] = $option; $data['alias'] = $option; $data['link'] = 'index.php?option=' . $option; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $component_id; $data['img'] = 'class:component'; $data['home'] = 0; $data['path'] = ''; $data['params'] = ''; } try { $table->setLocation($rootItemId, 'last-child'); } catch (InvalidArgumentException $e) { if (class_exists('JLog')) { JLog::add($e->getMessage(), JLog::WARNING, 'jerror'); } return false; } if (!$table->bind($data) || !$table->check() || !$table->store()) { // The menu item already exists. Delete it and retry instead of throwing an error. $query->clear()->select('id')->from('#__menu')->where('menutype = ' . $db->quote('main'))->where('client_id = 1')->where('link = ' . $db->quote('index.php?option=' . $option))->where('type = ' . $db->quote('component'))->where('parent_id = 1')->where('home = 0'); $db->setQuery($query); $menu_ids_level1 = $db->loadColumn(); if (empty($menu_ids_level1)) { // Oops! Could not get the menu ID. Go back and rollback changes. JError::raiseWarning(1, $table->getError()); return false; } else { $ids = implode(',', $menu_ids_level1); $query->clear()->select('id')->from('#__menu')->where('menutype = ' . $db->quote('main'))->where('client_id = 1')->where('type = ' . $db->quote('component'))->where('parent_id in (' . $ids . ')')->where('level = 2')->where('home = 0'); $db->setQuery($query); $menu_ids_level2 = $db->loadColumn(); $ids = implode(',', array_merge($menu_ids_level1, $menu_ids_level2)); // Remove the old menu item $query->clear()->delete('#__menu')->where('id in (' . $ids . ')'); $db->setQuery($query); $db->query(); // Retry creating the menu item $table->setLocation($rootItemId, 'last-child'); if (!$table->bind($data) || !$table->check() || !$table->store()) { // Install failed, warn user and rollback changes JError::raiseWarning(1, $table->getError()); return false; } } } /* * Since we have created a menu item, we add it to the installation step stack * so that if we have to rollback the changes we can undo it. */ $parent->getParent()->pushStep(array('type' => 'menu', 'id' => $component_id)); /* * Process SubMenus */ if (!$parent->get('manifest')->administration->submenu) { return true; } $parent_id = $table->id; foreach ($parent->get('manifest')->administration->submenu->menu as $child) { $data = array(); $data['menutype'] = 'main'; $data['client_id'] = 1; $data['title'] = (string) trim($child); $data['alias'] = (string) $child; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = $parent_id; $data['component_id'] = $component_id; $data['img'] = (string) $child->attributes()->img ? (string) $child->attributes()->img : 'class:component'; $data['home'] = 0; // Set the sub menu link if ((string) $child->attributes()->link) { $data['link'] = 'index.php?' . $child->attributes()->link; } else { $request = array(); if ((string) $child->attributes()->act) { $request[] = 'act=' . $child->attributes()->act; } if ((string) $child->attributes()->task) { $request[] = 'task=' . $child->attributes()->task; } if ((string) $child->attributes()->controller) { $request[] = 'controller=' . $child->attributes()->controller; } if ((string) $child->attributes()->view) { $request[] = 'view=' . $child->attributes()->view; } if ((string) $child->attributes()->layout) { $request[] = 'layout=' . $child->attributes()->layout; } if ((string) $child->attributes()->sub) { $request[] = 'sub=' . $child->attributes()->sub; } $qstring = count($request) ? '&' . implode('&', $request) : ''; $data['link'] = 'index.php?option=' . $option . $qstring; } $table = JTable::getInstance('menu'); try { $table->setLocation($parent_id, 'last-child'); } catch (InvalidArgumentException $e) { return false; } if (!$table->bind($data) || !$table->check() || !$table->store()) { // Install failed, rollback changes return false; } /* * Since we have created a menu item, we add it to the installation step stack * so that if we have to rollback the changes we can undo it. */ $parent->getParent()->pushStep(array('type' => 'menu', 'id' => $component_id)); } return true; }
/** * Make sure the Component menu items are really published! * * @param JInstallerAdapterComponent $parent * * @return bool */ private function _reallyPublishAdminMenuItems($parent) { $db = $parent->getParent()->getDbo(); $option = $parent->get('element'); $query = $db->getQuery(true)->update('#__menu AS m')->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')->set($db->qn('published') . ' = ' . $db->q(1))->where('m.parent_id = 1')->where('m.client_id = 1')->where('e.element = ' . $db->quote($option)); $db->setQuery($query); try { $db->execute(); } catch (Exception $e) { // If it fails, it fails. Who cares. } }
/** * Removes obsolete update sites created for the component (we are now using an update site for the package, not the * component). * * @param JInstallerAdapterComponent $parent The parent installer */ protected function removeObsoleteUpdateSites($parent) { $db = $parent->getParent()->getDbo(); $query = $db->getQuery(true)->select($db->qn('extension_id'))->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('component'))->where($db->qn('name') . ' = ' . $db->q($this->componentName)); try { $extensionId = $db->setQuery($query)->loadResult(); } catch (Exception $e) { // Your database is broken. return; } if (!$extensionId) { return; } $query = $db->getQuery(true)->select($db->qn('update_site_id'))->from($db->qn('#__update_sites_extensions'))->where($db->qn('extension_id') . ' = ' . $db->q($extensionId)); try { $ids = $db->setQuery($query)->loadColumn(0); } catch (Exception $e) { // Your database is broken. return; } if (!is_array($ids) && empty($ids)) { return; } foreach ($ids as $id) { $query = $db->getQuery(true)->delete($db->qn('#__update_sites'))->where($db->qn('update_site_id') . ' = ' . $db->q($id)); $db->setQuery($query); try { $db->execute(); } catch (\Exception $e) { // Do not fail in this case } } }
/** * Method to run after an install/update/uninstall method * * @param string $type * @param JInstallerAdapterComponent $parent * * @return void */ public function postflight($type, \JInstallerAdapterComponent $parent) { $db = JFactory::getDbo(); // Get install manifest // ======================================================================== $p_installer = $parent->getParent(); $installer = new JInstaller(); $manifest = $p_installer->manifest; $path = $p_installer->getPath('source'); $result = array(); $css = <<<CSS <style type="text/css"> #ak-install-img { } #ak-install-msg { } </style> CSS; echo $css; $installScript = dirname($path) . '/windwalker/src/System/installscript.php'; if (!is_file($installScript)) { $installScript = JPATH_LIBRARIES . '/windwalker/src/System/installscript.php'; } include $installScript; // Set Module active // ======================================================================== if ($type == 'install') { $q = $db->getQuery(true); $q->select('*')->from('#__modules')->where("module='mod_akquickicons'"); $db->setQuery($q); $module = $db->loadObject(); $module->published = 1; $module->position = 'cpanel'; $params = new stdClass(); $params->catid = 1; $module->params = json_encode($params); $db->updateObject('#__modules', $module, 'id'); $in = new stdClass(); $in->moduleid = $module->id; $in->menuid = 0; $db->insertObject('#__modules_menu', $in); } }