diff options
Diffstat (limited to 'phpBB/phpbb/db/migration/tool/module.php')
| -rw-r--r-- | phpBB/phpbb/db/migration/tool/module.php | 101 | 
1 files changed, 38 insertions, 63 deletions
| diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php index 3e39d87c04..a5ed62fd65 100644 --- a/phpBB/phpbb/db/migration/tool/module.php +++ b/phpBB/phpbb/db/migration/tool/module.php @@ -1,30 +1,37 @@  <?php  /**  * -* @package migration -* @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */  namespace phpbb\db\migration\tool; +use phpbb\module\exception\module_exception; +  /**  * Migration module management tool -* -* @package db  */  class module implements \phpbb\db\migration\tool\tool_interface  {  	/** @var \phpbb\cache\service */  	protected $cache; -	/** @var dbal */ +	/** @var \phpbb\db\driver\driver_interface */  	protected $db;  	/** @var \phpbb\user */  	protected $user; +	/** @var \phpbb\module\module_manager */ +	protected $module_manager; +  	/** @var string */  	protected $phpbb_root_path; @@ -37,18 +44,20 @@ class module implements \phpbb\db\migration\tool\tool_interface  	/**  	* Constructor  	* -	* @param \phpbb\db\driver\driver $db -	* @param mixed $cache +	* @param \phpbb\db\driver\driver_interface $db +	* @param \phpbb\cache\service $cache  	* @param \phpbb\user $user +	* @param \phpbb\module\module_manager	$module_manager  	* @param string $phpbb_root_path  	* @param string $php_ext  	* @param string $modules_table  	*/ -	public function __construct(\phpbb\db\driver\driver $db, \phpbb\cache\service $cache, \phpbb\user $user, $phpbb_root_path, $php_ext, $modules_table) +	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\user $user, \phpbb\module\module_manager $module_manager, $phpbb_root_path, $php_ext, $modules_table)  	{  		$this->db = $db;  		$this->cache = $cache;  		$this->user = $user; +		$this->module_manager = $module_manager;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext;  		$this->modules_table = $modules_table; @@ -163,12 +172,14 @@ class module implements \phpbb\db\migration\tool\tool_interface  	* 		)  	* 		Optionally you may not send 'modes' and it will insert all of the  	* 			modules in that info file. -	* @param string|bool $include_path If you would like to use a custom include  	* 	path, specify that here  	* @return null +	* @throws \phpbb\db\migration\exception  	*/ -	public function add($class, $parent = 0, $data = array(), $include_path = false) +	public function add($class, $parent = 0, $data = array())  	{ +		global $user, $phpbb_log; +  		// Allows '' to be sent as 0  		$parent = $parent ?: 0; @@ -184,7 +195,6 @@ class module implements \phpbb\db\migration\tool\tool_interface  			$basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';  			$module = $this->get_module_info($class, $basename); -			$result = '';  			foreach ($module['modes'] as $mode => $module_info)  			{  				if (!isset($data['modes']) || in_array($mode, $data['modes'])) @@ -235,13 +245,6 @@ class module implements \phpbb\db\migration\tool\tool_interface  			return;  		} -		if (!class_exists('acp_modules')) -		{ -			include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); -			$this->user->add_lang('acp/modules'); -		} -		$acp_modules = new \acp_modules(); -  		$module_data = array(  			'module_enabled'	=> (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,  			'module_display'	=> (isset($data['module_display'])) ? $data['module_display'] : 1, @@ -252,19 +255,14 @@ class module implements \phpbb\db\migration\tool\tool_interface  			'module_mode'		=> (isset($data['module_mode'])) ? $data['module_mode'] : '',  			'module_auth'		=> (isset($data['module_auth'])) ? $data['module_auth'] : '',  		); -		$result = $acp_modules->update_module_data($module_data, true); -		// update_module_data can either return a string or an empty array... -		if (is_string($result)) -		{ -			// Error -			throw new \phpbb\db\migration\exception('MODULE_ERROR', $result); -		} -		else +		try  		{ +			$this->module_manager->update_module_data($module_data); +  			// Success  			$module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']); -			add_log('admin', 'LOG_MODULE_ADD', $module_log_name); +			$phpbb_log->add('admin', (isset($user->data['user_id'])) ? $user->data['user_id'] : ANONYMOUS, $user->ip, 'LOG_MODULE_ADD', false, array($module_log_name));  			// Move the module if requested above/below an existing one  			if (isset($data['before']) && $data['before']) @@ -314,6 +312,11 @@ class module implements \phpbb\db\migration\tool\tool_interface  				$this->db->sql_query($sql);  			}  		} +		catch (module_exception $e) +		{ +			// Error +			throw new \phpbb\db\migration\exception('MODULE_ERROR', $e->getMessage()); +		}  		// Clear the Modules Cache  		$this->cache->destroy("_modules_$class"); @@ -328,11 +331,11 @@ class module implements \phpbb\db\migration\tool\tool_interface  	* @param int|string|bool $parent The parent module_id|module_langname(0 for no parent).  	* 	Use false to ignore the parent check and check class wide.  	* @param int|string $module The module id|module_langname -	* @param string|bool $include_path If you would like to use a custom include path,  	* 	specify that here  	* @return null +	* @throws \phpbb\db\migration\exception  	*/ -	public function remove($class, $parent = 0, $module = '', $include_path = false) +	public function remove($class, $parent = 0, $module = '')  	{  		// Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto  		if (is_array($module)) @@ -340,7 +343,7 @@ class module implements \phpbb\db\migration\tool\tool_interface  			if (isset($module['module_langname']))  			{  				// Manual Method -				return $this->remove($class, $parent, $module['module_langname'], $include_path); +				return $this->remove($class, $parent, $module['module_langname']);  			}  			// Failed. @@ -407,39 +410,15 @@ class module implements \phpbb\db\migration\tool\tool_interface  					$module_ids[] = (int) $module_id;  				}  				$this->db->sql_freeresult($result); - -				$module_name = $module;  			}  			else  			{ -				$module = (int) $module; -				$sql = 'SELECT module_langname -					FROM ' . $this->modules_table . " -					WHERE module_id = $module -						AND module_class = '" . $this->db->sql_escape($class) . "' -						$parent_sql"; -				$result = $this->db->sql_query($sql); -				$module_name = $this->db->sql_fetchfield('module_id'); -				$this->db->sql_freeresult($result); - -				$module_ids[] = $module; +				$module_ids[] = (int) $module;  			} -			if (!class_exists('acp_modules')) -			{ -				include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); -				$this->user->add_lang('acp/modules'); -			} -			$acp_modules = new \acp_modules(); -			$acp_modules->module_class = $class; -  			foreach ($module_ids as $module_id)  			{ -				$result = $acp_modules->delete_module($module_id); -				if (!empty($result)) -				{ -					return; -				} +				$this->module_manager->delete_module($module_id, $class);  			}  			$this->cache->destroy("_modules_$class"); @@ -478,15 +457,11 @@ class module implements \phpbb\db\migration\tool\tool_interface  	* @param string $class Module Class  	* @param string $basename Module Basename  	* @return array Module Information +	* @throws \phpbb\db\migration\exception  	*/  	protected function get_module_info($class, $basename)  	{ -		if (!class_exists('acp_modules')) -		{ -			include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); -		} -		$acp_modules = new \acp_modules(); -		$module = $acp_modules->get_module_infos($basename, $class, true); +		$module = $this->module_manager->get_module_infos($class, $basename, true);  		if (empty($module))  		{ | 
