phpBB

Code Changes

File: phpbb/db/migration/tool/module.php

  Unmodified   Added   Modified   Removed
Line 12Line 12
*/

namespace phpbb\db\migration\tool;

*/

namespace phpbb\db\migration\tool;

 

use phpbb\module\exception\module_exception;


/**
* Migration module management tool


/**
* Migration module management tool

Line 26Line 28

/** @var \phpbb\user */
protected $user;


/** @var \phpbb\user */
protected $user;

 

/** @var \phpbb\module\module_manager */
protected $module_manager;


/** @var string */
protected $phpbb_root_path;


/** @var string */
protected $phpbb_root_path;

Line 45Line 50
	* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\user $user

	* @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
*/

	* @param string $phpbb_root_path
* @param string $php_ext
* @param string $modules_table
*/

	public function __construct(\phpbb\db\driver\driver_interface $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->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;

		$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->modules_table = $modules_table;

Line 90Line 97
		$parent_sql = '';
if ($parent !== false)
{

		$parent_sql = '';
if ($parent !== false)
{

			$parent = $this->get_parent_module_id($parent, $module);






			$parent = $this->get_parent_module_id($parent, $module, false);
if ($parent === false)
{
return false;
}


			$parent_sql = 'AND parent_id = ' . (int) $parent;
}


			$parent_sql = 'AND parent_id = ' . (int) $parent;
}


Line 152Line 164
	*/
public function add($class, $parent = 0, $data = array())
{

	*/
public function add($class, $parent = 0, $data = array())
{

 
		global $user, $phpbb_log;


		// allow sending the name as a string in $data to create a category
if (!is_array($data))
{

		// allow sending the name as a string in $data to create a category
if (!is_array($data))
{

Line 166Line 180
			$basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';
$module = $this->get_module_info($class, $basename);


			$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']))

			foreach ($module['modes'] as $mode => $module_info)
{
if (!isset($data['modes']) || in_array($mode, $data['modes']))

Line 197Line 210

if ($this->exists($class, $parent, $data['module_langname']))
{


if ($this->exists($class, $parent, $data['module_langname']))
{

			throw new \phpbb\db\migration\exception('MODULE_EXISTS', $module_id);

			throw new \phpbb\db\migration\exception('MODULE_EXISTS', $data['module_langname']);

		}

		}


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_data = array(
'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,

Line 217Line 223
			'module_mode'		=> (isset($data['module_mode'])) ? $data['module_mode'] : '',
'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
);

			'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']);

			// 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'])


// Move the module if requested above/below an existing one
if (isset($data['before']) && $data['before'])

Line 278Line 279
						AND module_id = {$module_data['module_id']}";
$this->db->sql_query($sql);
}

						AND module_id = {$module_data['module_id']}";
$this->db->sql_query($sql);
}

 
		}
catch (module_exception $e)
{
// Error
throw new \phpbb\db\migration\exception('MODULE_ERROR', $e->getMessage());

		}

// Clear the Modules Cache

		}

// Clear the Modules Cache

Line 359Line 365
			{
$module_ids[] = (int) $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)
{


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");

			}

$this->cache->destroy("_modules_$class");

Line 422Line 416
	*/
protected function get_module_info($class, $basename)
{

	*/
protected function get_module_info($class, $basename)
{

		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 = $acp_modules->get_module_infos($basename, $class, true);

		$module = $this->module_manager->get_module_infos($class, $basename, true);








if (empty($module))
{


if (empty($module))
{

Line 448Line 436
	protected function get_categories_list()
{
// Select the top level categories

	protected function get_categories_list()
{
// Select the top level categories

		// and 2nd level [sub]categories which exist for ACP only

		// and 2nd level [sub]categories

		$sql = 'SELECT m2.module_id, m2.module_langname
FROM ' . $this->modules_table . ' m1, ' . $this->modules_table . " m2
WHERE m1.parent_id = 0

		$sql = 'SELECT m2.module_id, m2.module_langname
FROM ' . $this->modules_table . ' m1, ' . $this->modules_table . " m2
WHERE m1.parent_id = 0

				AND (m1.module_id = m2.module_id
OR m2.module_class = 'acp' AND m2.parent_id = m1.module_id)

				AND (m1.module_id = m2.module_id OR m2.parent_id = m1.module_id)


			ORDER BY m1.module_id, m2.module_id ASC";

$result = $this->db->sql_query($sql);

			ORDER BY m1.module_id, m2.module_id ASC";

$result = $this->db->sql_query($sql);

Line 469Line 456
	*
* @param string|int $parent_id The parent module_id|module_langname
* @param int|string|array $data The module_id, module_langname for existance checking or module data array for adding

	*
* @param string|int $parent_id The parent module_id|module_langname
* @param int|string|array $data The module_id, module_langname for existance checking or module data array for adding

	* @return int The parent module_id


	* @param bool $throw_exception The flag indicating if exception should be thrown on error
* @return mixed The int parent module_id or false

	* @throws \phpbb\db\migration\exception
*/

	* @throws \phpbb\db\migration\exception
*/

	public function get_parent_module_id($parent_id, $data = '')

	public function get_parent_module_id($parent_id, $data = '', $throw_exception = true)

	{

	{

 
		// Initialize exception object placeholder
$exception = false;


		// Allow '' to be sent as 0
$parent_id = $parent_id ?: 0;


		// Allow '' to be sent as 0
$parent_id = $parent_id ?: 0;


Line 495Line 486
			{
// No parent with the given module_langname exist
case 0:

			{
// No parent with the given module_langname exist
case 0:

					throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);

					$exception = new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);

				break;

// Return the module id

				break;

// Return the module id

Line 517Line 508
						$parent_id = (int) $this->db->sql_fetchfield('parent_id');
if (!$parent_id)
{

						$parent_id = (int) $this->db->sql_fetchfield('parent_id');
if (!$parent_id)
{

							throw new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);

							$exception = new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);

						}
}
else if (!empty($data) && !is_array($data))

						}
}
else if (!empty($data) && !is_array($data))

Line 535Line 526
					else
{
//Unable to get the parent module id, throwing an exception

					else
{
//Unable to get the parent module id, throwing an exception

						throw new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);

						$exception = new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);

					}
break;
}

					}
break;
}

 
		}

if ($exception !== false)
{
if ($throw_exception)
{
throw $exception;
}
return false;

		}

return $parent_id;

		}

return $parent_id;