Example #1
0
 /**
  * Upgrade a module.
  *
  * @param mixed[] $args {
  *      @type int     $id                  The module ID
  *      @type boolean $interactive_upgrade Whether or not to upgrade in interactive mode
  *                       }
  *
  * @return boolean True on success, false on failure
  *
  * @throws \InvalidArgumentException Thrown if the module id parameter is either not set or not numeric
  * @throws \RuntimeException Thrown if the module id isn't a valid module
  * @throws \RuntimeException Thrown if the module state prevents upgrade or if
  *                                  if the module isn't compatible with this version of Zikula or
  *                                  if the installer class isn't of the correct type
  */
 public function upgrade($args)
 {
     // Argument check
     if (!isset($args['id']) || !is_numeric($args['id'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received'));
     }
     // Get module information
     $modinfo = ModUtil::getInfo($args['id']);
     if (empty($modinfo)) {
         throw new \RuntimeException($this->__('Error! No such module ID exists.'));
     }
     switch ($modinfo['state']) {
         case ModUtil::STATE_NOTALLOWED:
             throw new \RuntimeException($this->__f('Error! No permission to upgrade %s.', $modinfo['name']));
             break;
         default:
             if ($modinfo['state'] > 10) {
                 throw new \RuntimeException($this->__f('Error! %s is not compatible with this version of Zikula.', $modinfo['name']));
             }
     }
     $osdir = DataUtil::formatForOS($modinfo['directory']);
     ModUtil::dbInfoLoad($modinfo['name'], $osdir);
     $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules';
     // add autoloaders for 1.3-type modules
     if (false === strpos($osdir, '/') && is_dir("{$modpath}/{$osdir}/lib")) {
         ZLoader::addAutoloader($osdir, array($modpath, "{$modpath}/{$osdir}/lib"));
     }
     $module = ModUtil::getModule($modinfo['name'], true);
     $bootstrap = "{$modpath}/{$osdir}/bootstrap.php";
     if (file_exists($bootstrap)) {
         include_once $bootstrap;
     }
     $installer = $this->getInstaller($module, $modinfo);
     // perform the actual upgrade of the module
     $func = array($installer, 'upgrade');
     if (is_callable($func)) {
         $result = call_user_func($func, $modinfo['version']);
         if (is_string($result)) {
             if ($result != $modinfo['version']) {
                 // update the last successful updated version
                 $item = $this->entityManager->getRepository(self::EXTENSION_ENTITY)->find($modinfo['id']);
                 $item['version'] = $result;
                 $this->entityManager->flush();
             }
             return false;
         } elseif ($result != true) {
             return false;
         }
     }
     $modversion['version'] = '0';
     $modversion = ExtensionsUtil::getVersionMeta($modinfo['name'], $modpath, $module);
     $version = $modversion['version'];
     // Update state of module
     $result = $this->setState(array('id' => $args['id'], 'state' => ModUtil::STATE_ACTIVE));
     if ($result) {
         LogUtil::registerStatus($this->__("Done! Module has been upgraded. Its status is now 'Active'."));
     } else {
         return false;
     }
     // update the module with the new version
     $item = $this->entityManager->getRepository(self::EXTENSION_ENTITY)->find($args['id']);
     $item['version'] = $version;
     $this->entityManager->flush();
     // clear the cache before calling events
     /** @var $cacheClearer \Zikula\Bundle\CoreBundle\CacheClearer */
     $cacheClearer = $this->get('zikula.cache_clearer');
     $cacheClearer->clear('symfony.config');
     if (!System::isInstalling()) {
         // Upgrade succeeded, issue event.
         // remove this legacy in 1.5.0
         $event = new GenericEvent(null, $modinfo);
         $this->getDispatcher()->dispatch('installer.module.upgraded', $event);
         $event = new ModuleStateEvent($module, $module === null ? $modinfo : null);
         $this->getDispatcher()->dispatch(CoreEvents::MODULE_UPGRADE, $event);
     }
     // Success
     return true;
 }
Example #2
0
 /**
  * @Route("/hooks/{moduleName}", options={"zkNoBundlePrefix" = 1})
  * @Method("GET")
  *
  * Display hooks user interface
  *
  * @return Response
  * @throws AccessDeniedException Thrown if the user doesn't have admin permissions over the module
  * @internal param $moduleName
  */
 public function hooksAction($moduleName)
 {
     // get module's name and assign it to template
     $this->view->assign('currentmodule', $moduleName);
     // check if user has admin permission on this module
     if (!SecurityUtil::checkPermission($moduleName . '::', '::', ACCESS_ADMIN)) {
         throw new AccessDeniedException();
     }
     // create an instance of the module's version
     // we will use it to get the bundles
     $moduleVersionObj = ExtensionsUtil::getVersionMeta($moduleName);
     if ($moduleVersionObj instanceof MetaData) {
         // Core-2.0 Spec module
         $moduleVersionObj = $this->get('zikula_extensions_module.api.hook')->getHookContainerInstance($moduleVersionObj);
     }
     // find out the capabilities of the module
     $isProvider = HookUtil::isProviderCapable($moduleName) ? true : false;
     $this->view->assign('isProvider', $isProvider);
     $isSubscriber = HookUtil::isSubscriberCapable($moduleName) ? true : false;
     $this->view->assign('isSubscriber', $isSubscriber);
     $isSubscriberSelfCapable = HookUtil::isSubscriberSelfCapable($moduleName) ? true : false;
     $this->view->assign('isSubscriberSelfCapable', $isSubscriberSelfCapable);
     // get areas of module and bundle titles also
     if ($isProvider) {
         $providerAreas = HookUtil::getProviderAreasByOwner($moduleName);
         $this->view->assign('providerAreas', $providerAreas);
         $providerAreasToTitles = array();
         foreach ($providerAreas as $providerArea) {
             $providerAreasToTitles[$providerArea] = $this->view->__($moduleVersionObj->getHookProviderBundle($providerArea)->getTitle());
         }
         $this->view->assign('providerAreasToTitles', $providerAreasToTitles);
     }
     if ($isSubscriber) {
         $subscriberAreas = HookUtil::getSubscriberAreasByOwner($moduleName);
         $this->view->assign('subscriberAreas', $subscriberAreas);
         $subscriberAreasToTitles = array();
         foreach ($subscriberAreas as $subscriberArea) {
             $subscriberAreasToTitles[$subscriberArea] = $this->view->__($moduleVersionObj->getHookSubscriberBundle($subscriberArea)->getTitle());
         }
         $this->view->assign('subscriberAreasToTitles', $subscriberAreasToTitles);
         $subscriberAreasToCategories = array();
         foreach ($subscriberAreas as $subscriberArea) {
             $category = $this->view->__($moduleVersionObj->getHookSubscriberBundle($subscriberArea)->getCategory());
             $subscriberAreasToCategories[$subscriberArea] = $category;
         }
         $this->view->assign('subscriberAreasToCategories', $subscriberAreasToCategories);
         $subscriberAreasAndCategories = array();
         foreach ($subscriberAreas as $subscriberArea) {
             $category = $this->view->__($moduleVersionObj->getHookSubscriberBundle($subscriberArea)->getCategory());
             $subscriberAreasAndCategories[$category][] = $subscriberArea;
         }
         $this->view->assign('subscriberAreasAndCategories', $subscriberAreasAndCategories);
     }
     // get available subscribers that can attach to provider
     if ($isProvider && !empty($providerAreas)) {
         $hooksubscribers = HookUtil::getHookSubscribers();
         $total_hooksubscribers = count($hooksubscribers);
         $total_available_subscriber_areas = 0;
         for ($i = 0; $i < $total_hooksubscribers; $i++) {
             // don't allow subscriber and provider to be the same
             // unless subscriber has the ability to connect to it's own providers
             if ($hooksubscribers[$i]['name'] == $moduleName) {
                 unset($hooksubscribers[$i]);
                 continue;
             }
             // does the user have admin permissions on the subscriber module?
             if (!SecurityUtil::checkPermission($hooksubscribers[$i]['name'] . "::", '::', ACCESS_ADMIN)) {
                 unset($hooksubscribers[$i]);
                 continue;
             }
             // create an instance of the subscriber's version
             $hooksubscriberVersionObj = ExtensionsUtil::getVersionMeta($hooksubscribers[$i]['name']);
             if ($hooksubscriberVersionObj instanceof MetaData) {
                 // Core-2.0 Spec module
                 $hooksubscriberVersionObj = $this->get('zikula_extensions_module.api.hook')->getHookContainerInstance($hooksubscriberVersionObj);
             }
             // get the areas of the subscriber
             $hooksubscriberAreas = HookUtil::getSubscriberAreasByOwner($hooksubscribers[$i]['name']);
             $hooksubscribers[$i]['areas'] = $hooksubscriberAreas;
             $total_available_subscriber_areas += count($hooksubscriberAreas);
             // and get the titles
             $hooksubscriberAreasToTitles = array();
             foreach ($hooksubscriberAreas as $hooksubscriberArea) {
                 $hooksubscriberAreasToTitles[$hooksubscriberArea] = $this->view->__($hooksubscriberVersionObj->getHookSubscriberBundle($hooksubscriberArea)->getTitle());
             }
             $hooksubscribers[$i]['areasToTitles'] = $hooksubscriberAreasToTitles;
             // and get the categories
             $hooksubscriberAreasToCategories = array();
             foreach ($hooksubscriberAreas as $hooksubscriberArea) {
                 $category = $this->view->__($hooksubscriberVersionObj->getHookSubscriberBundle($hooksubscriberArea)->getCategory());
                 $hooksubscriberAreasToCategories[$hooksubscriberArea] = $category;
             }
             $hooksubscribers[$i]['areasToCategories'] = $hooksubscriberAreasToCategories;
         }
         $this->view->assign('hooksubscribers', $hooksubscribers);
         $this->view->assign('total_available_subscriber_areas', $total_available_subscriber_areas);
     } else {
         $this->view->assign('total_available_subscriber_areas', 0);
     }
     // get providers that are already attached to the subscriber
     // and providers that can attach to the subscriber
     if ($isSubscriber && !empty($subscriberAreas)) {
         // get current sorting
         $currentSortingTitles = array();
         $currentSorting = array();
         $total_attached_provider_areas = 0;
         for ($i = 0; $i < count($subscriberAreas); $i++) {
             $sortsByArea = HookUtil::getBindingsFor($subscriberAreas[$i]);
             foreach ($sortsByArea as $sba) {
                 $areaname = $sba['areaname'];
                 $category = $sba['category'];
                 if (!isset($currentSorting[$category])) {
                     $currentSorting[$category] = array();
                 }
                 if (!isset($currentSorting[$category][$subscriberAreas[$i]])) {
                     $currentSorting[$category][$subscriberAreas[$i]] = array();
                 }
                 array_push($currentSorting[$category][$subscriberAreas[$i]], $areaname);
                 $total_attached_provider_areas++;
                 // get hook provider from it's area
                 $sbaProviderModule = HookUtil::getOwnerByArea($areaname);
                 // create an instance of the provider's version
                 $sbaProviderModuleVersionObj = ExtensionsUtil::getVersionMeta($sbaProviderModule);
                 if ($sbaProviderModuleVersionObj instanceof MetaData) {
                     // Core-2.0 Spec module
                     $sbaProviderModuleVersionObj = $this->get('zikula_extensions_module.api.hook')->getHookContainerInstance($sbaProviderModuleVersionObj);
                 }
                 // get the bundle title
                 $currentSortingTitles[$areaname] = $this->view->__($sbaProviderModuleVersionObj->getHookProviderBundle($areaname)->getTitle());
             }
         }
         $this->view->assign('areasSorting', $currentSorting);
         $this->view->assign('areasSortingTitles', $currentSortingTitles);
         $this->view->assign('total_attached_provider_areas', $total_attached_provider_areas);
         // get available providers
         $hookproviders = HookUtil::getHookProviders();
         $total_hookproviders = count($hookproviders);
         $total_available_provider_areas = 0;
         for ($i = 0; $i < $total_hookproviders; $i++) {
             // don't allow subscriber and provider to be the same
             // unless subscriber has the ability to connect to it's own providers
             if ($hookproviders[$i]['name'] == $moduleName && !$isSubscriberSelfCapable) {
                 unset($hookproviders[$i]);
                 continue;
             }
             // does the user have admin permissions on the provider module?
             if (!SecurityUtil::checkPermission($hookproviders[$i]['name'] . "::", '::', ACCESS_ADMIN)) {
                 unset($hookproviders[$i]);
                 continue;
             }
             // create an instance of the provider's version
             $hookproviderVersionObj = ExtensionsUtil::getVersionMeta($hookproviders[$i]['name']);
             if ($hookproviderVersionObj instanceof MetaData) {
                 // Core-2.0 Spec module
                 $hookproviderVersionObj = $this->get('zikula_extensions_module.api.hook')->getHookContainerInstance($hookproviderVersionObj);
             }
             // get the areas of the provider
             $hookproviderAreas = HookUtil::getProviderAreasByOwner($hookproviders[$i]['name']);
             $hookproviders[$i]['areas'] = $hookproviderAreas;
             $total_available_provider_areas += count($hookproviderAreas);
             // and get the titles
             $hookproviderAreasToTitles = array();
             foreach ($hookproviderAreas as $hookproviderArea) {
                 $hookproviderAreasToTitles[$hookproviderArea] = $this->view->__($hookproviderVersionObj->getHookProviderBundle($hookproviderArea)->getTitle());
             }
             $hookproviders[$i]['areasToTitles'] = $hookproviderAreasToTitles;
             // and get the categories
             $hookproviderAreasToCategories = array();
             foreach ($hookproviderAreas as $hookproviderArea) {
                 $hookproviderAreasToCategories[$hookproviderArea] = $this->view->__($hookproviderVersionObj->getHookProviderBundle($hookproviderArea)->getCategory());
             }
             $hookproviders[$i]['areasToCategories'] = $hookproviderAreasToCategories;
             // and build array with category => areas
             $hookproviderAreasAndCategories = array();
             foreach ($hookproviderAreas as $hookproviderArea) {
                 $category = $this->view->__($hookproviderVersionObj->getHookProviderBundle($hookproviderArea)->getCategory());
                 $hookproviderAreasAndCategories[$category][] = $hookproviderArea;
             }
             $hookproviders[$i]['areasAndCategories'] = $hookproviderAreasAndCategories;
         }
         $this->view->assign('hookproviders', $hookproviders);
         $this->view->assign('total_available_provider_areas', $total_available_provider_areas);
     } else {
         $this->view->assign('hookproviders', array());
     }
     return new Response($this->view->fetch('Admin/HookUi/hooks.tpl'));
 }
Example #3
0
 private function init()
 {
     $conn = $this->container->get('doctrine.dbal.default_connection');
     /** @var \ZikulaKernel $kernel */
     $kernel = $this->container->get('kernel');
     $res = $conn->executeQuery("SELECT name FROM modules WHERE name = 'ZikulaExtensionsModule'");
     $result = $res->fetch();
     if ($result) {
         // nothing to do, already converted.
         return '';
     }
     // remove event handlers that were replaced by DependencyInjection
     $conn->executeQuery("DELETE FROM module_vars WHERE modname = '/EventHandlers' AND name IN ('Extensions', 'Users', 'Search', 'Settings')");
     // remove old Errors module from modules table (uninstall and delete)
     $conn->executeQuery("DELETE FROM modules WHERE name = 'Errors'");
     // rename modules in tables: modules, module_vars, group_perms
     $oldModuleNames = array('Admin', 'Blocks', 'Categories', 'Extensions', 'Groups', 'Mailer', 'PageLock', 'Permissions', 'Search', 'SecurityCenter', 'Settings', 'Theme', 'Users');
     foreach ($oldModuleNames as $module) {
         $conn->executeQuery("UPDATE modules SET name = 'Zikula{$module}Module', directory = '{$module}Module' WHERE name = '{$module}'");
         $conn->executeQuery("UPDATE module_vars SET modname = 'Zikula{$module}Module' WHERE modname = '{$module}'");
         $strlen = strlen($module) + 1;
         $conn->executeQuery("UPDATE group_perms SET component = CONCAT('Zikula{$module}Module', SUBSTRING(component, {$strlen})) WHERE component LIKE '{$module}%'");
     }
     // rename themes in tables: themes
     $oldThemeNames = array('Andreas08', 'Atom', 'SeaBreeze', 'Mobile', 'Printer');
     foreach ($oldThemeNames as $theme) {
         $conn->executeQuery("UPDATE themes SET name = 'Zikula{$theme}Theme', directory = '{$theme}Theme' WHERE name = '{$theme}'");
     }
     $conn->executeQuery("UPDATE themes SET name = 'ZikulaRssTheme', directory = 'RssTheme' WHERE name = 'RSS'");
     // update 'Users' -> 'ZikulaUsersModule' in all the hook tables
     $sqls = array();
     $sqls[] = "UPDATE hook_area SET owner = 'ZikulaUsersModule' WHERE owner = 'Users'";
     $sqls[] = "UPDATE hook_binding SET sowner = 'ZikulaUsersModule' WHERE sowner = 'Users'";
     $sqls[] = "UPDATE hook_runtime SET sowner = 'ZikulaUsersModule' WHERE sowner = 'Users'";
     $sqls[] = "UPDATE hook_subscriber SET owner = 'ZikulaUsersModule' WHERE owner = 'Users'";
     foreach ($sqls as $sql) {
         $conn->executeQuery($sql);
     }
     // update default theme name
     $conn->executeQuery("UPDATE module_vars SET value = 's:20:\"ZikulaAndreas08Theme\";' WHERE modname = 'ZConfig' AND name = 'Default_Theme'");
     // confirm custom module urls are valid with new routes, reset if not
     $modules = $conn->fetchAll("SELECT * FROM modules");
     foreach ($modules as $module) {
         $path = realpath($kernel->getRootDir() . '/../' . $module['url']);
         if (is_dir($path)) {
             $meta = \Zikula\ExtensionsModule\Util::getVersionMeta($module['name']);
             $conn->executeQuery("UPDATE modules SET url = '{$meta['url']}' WHERE id = {$modules['id']}");
         }
     }
     // ensure data in modules:capabilities is valid
     $conn->executeQuery("UPDATE `modules` SET `capabilities`='a:0:{}' WHERE `capabilities`=''");
     // install Bundles table
     $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap();
     $helper = new \Zikula\Bundle\CoreBundle\Bundle\Helper\BootstrapHelper($boot->getConnection($kernel));
     $helper->createSchema();
     $helper->load();
     $bundles = array();
     // this neatly autoloads
     $boot->getPersistedBundles($kernel, $bundles);
 }