/**
  * Save settings
  *
  * @param array $settingsList
  * @param array $settingsValues
  * @param string $currentlanguage
  * @param string $module
  * @return boolean|string
  */
 public function saveSettings(array $settingsList, array $settingsValues, $currentlanguage, $module)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         // save settings
         foreach ($settingsList as $setting) {
             if (array_key_exists($setting['name'], $settingsValues)) {
                 // remove previously value
                 $query = $this->delete('application_setting_value')->where(['setting_id' => $setting['id']])->where(!$setting['language_sensitive'] ? 'language is null' : ['language' => $currentlanguage]);
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
                 // insert new value
                 $extraValues = $setting['language_sensitive'] ? ['language' => $currentlanguage] : [];
                 $value = is_array($settingsValues[$setting['name']]) ? implode(self::SETTINGS_ARRAY_DIVIDER, $settingsValues[$setting['name']]) : (null != $settingsValues[$setting['name']] ? $settingsValues[$setting['name']] : '');
                 $query = $this->insert('application_setting_value')->values(array_merge(['setting_id' => $setting['id'], 'value' => $value], $extraValues));
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
             }
         }
         // clear cache
         $this->removeSettingsCache($currentlanguage);
         self::$settings = null;
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the change settings event
     ApplicationEvent::fireChangeSettingsEvent($module);
     return true;
 }
示例#2
0
文件: Module.php 项目: b-medias/bZF2
 public function getServiceConfig()
 {
     return array('factories' => array(__NAMESPACE__ . '/Service/' . __NAMESPACE__ . 'Service' => function ($serviceManager) {
         $service = new Service\ApplicationService();
         return $service->setServiceManager($serviceManager);
     }, __NAMESPACE__ . '/Repository/' . __NAMESPACE__ . 'Repository' => function ($serviceManager) {
         $repository = new Repository\ApplicationRepository();
         return $repository->setServiceManager($serviceManager);
     }, __NAMESPACE__ . '/Event/' . __NAMESPACE__ . 'Event' => function ($serviceManager) {
         $event = new Event\ApplicationEvent();
         return $event->setServiceManager($serviceManager);
     }, __NAMESPACE__ . '/Listener/' . __NAMESPACE__ . 'Listener' => function ($serviceManager) {
         $listener = new Listener\ApplicationListener();
         return $listener->setServiceManager($serviceManager);
     }));
 }
 /**
  * Settings
  */
 public function settingsAction()
 {
     // clear a layout caches
     $eventManager = ApplicationEvent::getEventManager();
     $eventManager->attach(ApplicationEvent::CHANGE_SETTINGS, function ($e) {
         $this->getModel()->clearLayoutCaches();
     });
     return new ViewModel(['settings_form' => parent::settingsForm('layout', 'layouts-administration', 'settings')]);
 }
 /**
  * Immediately send notification
  *
  * @param string $email
  * @param string $title
  * @param string $messageDesc
  * @return boolean|string
  */
 public static function immediatelySendNotification($email, $title, $messageDesc)
 {
     try {
         // fire the send email notification event
         ApplicationEvent::fireSendEmailNotificationEvent($email, $title);
         // add the mime type
         $message = new MimePart($messageDesc);
         $message->type = 'text/html';
         $body = new MimeMessage();
         $body->setParts([$message]);
         $messageInstance = new Message();
         $messageInstance->addFrom(ApplicationSettingService::getSetting('application_notification_from'))->addTo($email)->setSubject($title)->setBody($body)->setEncoding('UTF-8');
         self::getMessageTransport()->send($messageInstance);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         return 'Error: ' . $e->getMessage() . "\n";
     }
     return true;
 }
 /**
  * Clear cache
  */
 public function clearCacheAction()
 {
     // get a cache form
     $cacheForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Application\\Form\\ApplicationClearCache');
     $request = $this->getRequest();
     // validate the form
     if ($request->isPost()) {
         // fill the form with received values
         $cacheForm->getForm()->setData($request->getPost(), false);
         // check the form validation
         if ($cacheForm->getForm()->isValid()) {
             if (null != ($caches = $cacheForm->getForm()->getData()['cache'])) {
                 // clear selected caches
                 foreach ($caches as $cache) {
                     // check the permission and increase permission's actions track
                     if (true !== ($result = $this->aclCheckPermission())) {
                         return $result;
                     }
                     $clearResult = false;
                     switch ($cache) {
                         case self::CACHE_STATIC:
                             $clearResult = CacheUtility::clearStaticCache();
                             break;
                         case self::CACHE_DYNAMIC:
                             $clearResult = CacheUtility::clearDynamicCache();
                             break;
                         case self::CACHE_CONFIG:
                             $clearResult = CacheUtility::clearConfigCache();
                             break;
                         case self::CACHE_JS:
                             $clearResult = CacheUtility::clearJsCache();
                             break;
                         case self::CACHE_CSS:
                             $clearResult = CacheUtility::clearCssCache();
                             break;
                     }
                     if (false === $clearResult) {
                         $this->flashMessenger()->setNamespace('error')->addMessage(sprintf($this->getTranslator()->translate('Error clearing caches'), $cache));
                         break;
                     }
                 }
                 if (true === $clearResult) {
                     ApplicationEvent::fireClearCacheEvent($cache);
                     $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('Selected caches have been cleared'));
                 }
                 return $this->redirectTo('settings-administration', 'clear-cache');
             }
         }
     }
     return new ViewModel(['cacheForm' => $cacheForm->getForm()]);
 }
 /**
  * Upload custom module
  *
  * @param array $formData
  *      string login required
  *      string password required
  *      array module required
  * @param string $host
  * @return boolean|string
  */
 public function uploadCustomModule(array $formData, $host)
 {
     $uploadResult = true;
     try {
         // create a tmp dir
         $tmpDirName = $this->generateTmpDir();
         ApplicationFileSystemUtility::createDir($tmpDirName);
         // unzip a custom module into the tmp dir
         $this->unzipFiles($formData['module']['tmp_name'], $tmpDirName);
         // check the module's config
         if (!file_exists($tmpDirName . '/config.php')) {
             throw new ApplicationException('Cannot define the module\'s config file');
         }
         // get the module's config
         $moduleConfig = (include $tmpDirName . '/config.php');
         // get the module's path
         $modulePath = !empty($moduleConfig['module_path']) ? $tmpDirName . '/' . $moduleConfig['module_path'] : null;
         // check the module existing
         if (!$modulePath || !file_exists($modulePath) || !is_dir($modulePath)) {
             throw new ApplicationException('Cannot define the module\'s path into the config file');
         }
         if (!file_exists($modulePath . '/' . $this->moduleInstallConfig) || !file_exists($modulePath . '/' . $this->moduleConfig)) {
             throw new ApplicationException('Module not found');
         }
         // check the module layout existing
         $moduleLayoutPath = null;
         if (!empty($moduleConfig['layout_path'])) {
             $moduleLayoutPath = $tmpDirName . '/' . $moduleConfig['layout_path'];
             if (!file_exists($moduleLayoutPath) || !is_dir($moduleLayoutPath)) {
                 throw new ApplicationException('Cannot define the module\'s layout path into the config file');
             }
         }
         // check the module existing into modules and layouts dirs
         $moduleName = basename($modulePath);
         $globalModulePath = ApplicationService::getModulePath(false) . '/' . $moduleName;
         $moduleLayoutName = $moduleLayoutPath ? basename($moduleLayoutPath) : null;
         $localModulePath = APPLICATION_ROOT . '/' . $globalModulePath;
         $localModuleLayout = $moduleLayoutName ? ApplicationService::getBaseLayoutPath() . '/' . $moduleLayoutName : null;
         if (file_exists($localModulePath) || $localModuleLayout && file_exists($localModuleLayout)) {
             throw new ApplicationException('Module already uploaded');
         }
         // upload the module via FTP
         $ftp = new ApplicationFtpUtility($host, $formData['login'], $formData['password']);
         $ftp->createDirectory($globalModulePath);
         $ftp->copyDirectory($modulePath, $globalModulePath);
         // upload the module's layout
         if ($moduleLayoutPath) {
             $globalModuleLayoutPath = basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getBaseLayoutPath(false) . '/' . $moduleLayoutName;
             $ftp->createDirectory($globalModuleLayoutPath);
             $ftp->copyDirectory($moduleLayoutPath, $globalModuleLayoutPath);
         }
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         $uploadResult = $e->getMessage();
     }
     // remove the tmp dir
     if (file_exists($tmpDirName)) {
         ApplicationFileSystemUtility::deleteFiles($tmpDirName, [], false, true);
     }
     // fire the upload custom module event
     if (true === $uploadResult) {
         ApplicationEvent::fireUploadCustomModuleEvent($moduleName);
     }
     return $uploadResult;
 }