public function updateconfig() { $this->checkCsrfToken(); // confirm the forms authorisation key $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_ADMIN)); // get current module variables $vars = ModUtil::getVar($this->name); // get module variables from form $modvars = array(); $modvars['table_prefix'] = FormUtil::getPassedValue('table_prefix', 'phpbb_', 'POST'); $modvars['page_title'] = FormUtil::getPassedValue('page_title', '', 'POST'); $modvars['page_description'] = FormUtil::getPassedValue('page_description', '', 'POST'); $modvars['page_robots'] = FormUtil::getPassedValue('page_robots', '', 'POST'); // table prefix change if ($vars['table_prefix'] && $vars['table_prefix'] != $modvars['table_prefix']) { // table prefix is changed $mandatoryinprefix = 'phpbb'; if (strpos($modvars['table_prefix'], $mandatoryinprefix) === false) { return LogUtil::registerError($this->__('Error: table prefix must contain fragment <b>phpbb</b>.')); } // ok, let's change in db $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); $stmt = $connection->prepare("SHOW TABLES LIKE '%" . $vars['table_prefix'] . "_%'"); try { $stmt->execute(); } catch (Exception $e) { return LogUtil::registerError(__('Error: ') . $e->getMessage()); } $items = $stmt->fetchAll(Doctrine_Core::FETCH_NUM); $tablenames = ZphpBB2_Util::getTableNames(); foreach ($items as $item) { $table_stem = ZphpBB2_Util::getTableStem($item[0], $vars['table_prefix']); if (in_array($table_stem, $tablenames)) { $stmt = $connection->prepare('RENAME TABLE ' . $item[0] . " TO " . $modvars['table_prefix'] . $table_stem); try { $stmt->execute(); } catch (Exception $e) { return LogUtil::registerError(__('Error: ') . $e->getMessage()); } } } } // update module variables $this->setVars($modvars); // the module configuration has been updated successfuly LogUtil::registerStatus($this->__('Done! Module configuration updated.')); return System::redirect(ModUtil::url($this->name, 'admin', 'main')); }
/** * Delete module * * @return boolean true/false */ public function uninstall() { $table_prefix = ModUtil::getVar('ZphpBB2', 'table_prefix', 'phpbb_'); $tablenames = ZphpBB2_Util::getTableNames(); $connection = Doctrine_Manager::getInstance()->getCurrentConnection(); // str_replace is because _ is wildcard character, as % $stmt = $connection->prepare("SHOW TABLES LIKE '" . str_replace('_', '\\_', $table_prefix) . "%'"); try { $stmt->execute(); } catch (Exception $e) { return LogUtil::registerError(__('Error: ') . $e->getMessage()); } $items = $stmt->fetchAll(Doctrine_Core::FETCH_NUM); foreach ($items as $item) { $table_stem = ZphpBB2_Util::getTableStem($item[0], $table_prefix); if (in_array($table_stem, $tablenames)) { $stmt = $connection->prepare("DROP TABLE `" . $item[0] . "`"); try { $stmt->execute(); } catch (Exception $e) { return LogUtil::registerError(__('Error: ') . $e->getMessage()); } } } // Unregister event handlers EventUtil::unregisterPersistentModuleHandler('ZphpBB2', 'user.account.create', array('ZphpBB2_Listener_UsersSynch', 'createAccountListener')); EventUtil::unregisterPersistentModuleHandler('ZphpBB2', 'user.account.update', array('ZphpBB2_Listener_UsersSynch', 'updateAccountListener')); EventUtil::unregisterPersistentModuleHandler('ZphpBB2', 'user.account.delete', array('ZphpBB2_Listener_UsersSynch', 'deleteAccountListener')); return true; }