phpBB

Code Changes

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

  Unmodified   Added   Modified   Removed
Line 84Line 84
	*		Use false to ignore the parent check and check class wide.
* @param int|string $module The module_id|module_langname you would like to
* check for to see if it exists

	*		Use false to ignore the parent check and check class wide.
* @param int|string $module The module_id|module_langname you would like to
* check for to see if it exists

	* @return bool true/false if module exists



	* @param bool $lazy Checks lazily if the module exists. Returns true if it exists in at
* least one given parent.
* @return bool true if module exists in *all* given parents, false if not

	*/

	*/

	public function exists($class, $parent, $module)

	public function exists($class, $parent, $module, $lazy = false)

	{
// the main root directory should return true
if (!$module)

	{
// the main root directory should return true
if (!$module)

Line 94Line 96
			return true;
}


			return true;
}


		$parent_sql = '';

		$parent_sqls = [];

		if ($parent !== false)
{

		if ($parent !== false)
{

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

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

			{
return false;
}


			{
return false;
}


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




			foreach ((array) $parents as $parent_id)
{
$parent_sqls[] = 'AND parent_id = ' . (int) $parent_id;
}

		}


		}


 
		foreach ($parent_sqls as $parent_sql)
{

		$sql = 'SELECT module_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'

		$sql = 'SELECT module_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'

Line 115Line 122
		$module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);


		$module_id = $this->db->sql_fetchfield('module_id');
$this->db->sql_freeresult($result);


		if ($module_id)





			if (!$lazy && !$module_id)
{
return false;
}
else if ($lazy && $module_id)

		{
return true;

		{
return true;

 
			}

		}


		}


		return false;


		// Returns true, if modules exist in all parents and false otherwise
return !$lazy;

	}

/**

	}

/**

Line 172Line 185
			$data = array('module_langname' => $data);
}


			$data = array('module_langname' => $data);
}


		$parent = $data['parent_id'] = $this->get_parent_module_id($parent, $data);

		$parents = (array) $this->get_parent_module_id($parent, $data);


if (!isset($data['module_langname']))
{


if (!isset($data['module_langname']))
{

Line 195Line 208
					);

// Run the "manual" way with the data we've collected.

					);

// Run the "manual" way with the data we've collected.

 
					foreach ($parents as $parent)
{

					$this->add($class, $parent, $new_module);

					$this->add($class, $parent, $new_module);

 
					}

				}
}

return;
}

				}
}

return;
}

 

foreach ($parents as $parent)
{
$data['parent_id'] = $parent;


// The "manual" way
if (!$this->exists($class, false, $parent))


// The "manual" way
if (!$this->exists($class, false, $parent))

Line 235Line 255
			// 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'])
{

 
					$before_mode = $before_langname = '';
if (is_array($data['before']))
{
// Restore legacy-legacy behaviour from phpBB 3.0
list($before_mode, $before_langname) = $data['before'];
}
else
{
// Legacy behaviour from phpBB 3.1+
$before_langname = $data['before'];
}


				$sql = 'SELECT left_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'
AND parent_id = " . (int) $parent . "

				$sql = 'SELECT left_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'
AND parent_id = " . (int) $parent . "

						AND module_langname = '" . $this->db->sql_escape($data['before']) . "'";
$this->db->sql_query($sql);


						AND module_langname = '" . $this->db->sql_escape($before_langname) . "'"
. (($before_mode) ? " AND module_mode = '" . $this->db->sql_escape($before_mode) . "'" : '');
$result = $this->db->sql_query($sql);

				$to_left = (int) $this->db->sql_fetchfield('left_id');

				$to_left = (int) $this->db->sql_fetchfield('left_id');

 
					$this->db->sql_freeresult($result);


$sql = 'UPDATE ' . $this->modules_table . "
SET left_id = left_id + 2, right_id = right_id + 2


$sql = 'UPDATE ' . $this->modules_table . "
SET left_id = left_id + 2, right_id = right_id + 2

Line 258Line 292
			}
else if (isset($data['after']) && $data['after'])
{

			}
else if (isset($data['after']) && $data['after'])
{

 
					$after_mode = $after_langname = '';
if (is_array($data['after']))
{
// Restore legacy-legacy behaviour from phpBB 3.0
list($after_mode, $after_langname) = $data['after'];
}
else
{
// Legacy behaviour from phpBB 3.1+
$after_langname = $data['after'];
}


				$sql = 'SELECT right_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'
AND parent_id = " . (int) $parent . "

				$sql = 'SELECT right_id
FROM ' . $this->modules_table . "
WHERE module_class = '" . $this->db->sql_escape($class) . "'
AND parent_id = " . (int) $parent . "

						AND module_langname = '" . $this->db->sql_escape($data['after']) . "'";
$this->db->sql_query($sql);


						AND module_langname = '" . $this->db->sql_escape($after_langname) . "'"
. (($after_mode) ? " AND module_mode = '" . $this->db->sql_escape($after_mode) . "'" : '');
$result = $this->db->sql_query($sql);

				$to_right = (int) $this->db->sql_fetchfield('right_id');

				$to_right = (int) $this->db->sql_fetchfield('right_id');

 
					$this->db->sql_freeresult($result);


$sql = 'UPDATE ' . $this->modules_table . "
SET left_id = left_id + 2, right_id = right_id + 2


$sql = 'UPDATE ' . $this->modules_table . "
SET left_id = left_id + 2, right_id = right_id + 2

Line 284Line 332
		{
// Error
throw new \phpbb\db\migration\exception('MODULE_ERROR', $e->getMessage());

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

 
			}

		}

// Clear the Modules Cache

		}

// Clear the Modules Cache

Line 334Line 383
		}
else
{

		}
else
{

			if (!$this->exists($class, $parent, $module))

			if (!$this->exists($class, $parent, $module, true))

			{
return;
}

			{
return;
}

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

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

				$parent = $this->get_parent_module_id($parent, $module);
$parent_sql = 'AND parent_id = ' . (int) $parent;

				$parents = (array) $this->get_parent_module_id($parent, $module);
$parent_sql = 'AND ' . $this->db->sql_in_set('parent_id', $parents);

			}

$module_ids = array();

			}

$module_ids = array();

Line 457Line 506
	* @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 bool $throw_exception The flag indicating if exception should be thrown on error

	* @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 bool $throw_exception The flag indicating if exception should be thrown on error

	* @return mixed The int parent module_id or false

	* @return mixed The int parent module_id, an array of int parent module_id values or false

	* @throws \phpbb\db\migration\exception
*/
public function get_parent_module_id($parent_id, $data = '', $throw_exception = true)
{

	* @throws \phpbb\db\migration\exception
*/
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;

// If automatic adding is in action, convert array back to string to simplify things

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

// If automatic adding is in action, convert array back to string to simplify things

		if (is_array($data) && sizeof($data) == 1)

		if (is_array($data) && count($data) == 1)

		{
$data = $data['module_langname'];
}

		{
$data = $data['module_langname'];
}

Line 482Line 528
			// Search for the parent module_langname
$ids = array_keys($this->module_categories, $parent_id);


			// Search for the parent module_langname
$ids = array_keys($this->module_categories, $parent_id);


			switch (sizeof($ids))

			switch (count($ids))

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

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

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






					if ($throw_exception)
{
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
}

return false;

				break;

// Return the module id
case 1:

				break;

// Return the module id
case 1:

					$parent_id = (int) $ids[0];

					return (int) $ids[0];

				break;


				break;


				// Several modules with the given module_langname were found
// Try to determine the parent_id by the neighbour module parent

 
				default:

				default:

					if (is_array($data) && (isset($data['before']) || isset($data['after'])))
{
$neighbour_module_langname = isset($data['before']) ? $data['before'] : $data['after'];
$sql = 'SELECT parent_id
FROM ' . $this->modules_table . "
WHERE module_langname = '" . $this->db->sql_escape($neighbour_module_langname) . "'
AND " . $this->db->sql_in_set('parent_id', $ids);
$result = $this->db->sql_query($sql);
$parent_id = (int) $this->db->sql_fetchfield('parent_id');
if (!$parent_id)
{
$exception = new \phpbb\db\migration\exception('PARENT_MODULE_FIND_ERROR', $data['parent_id']);
}
}
else if (!empty($data) && !is_array($data))
{
// The module_langname is set, checking for the module existance
// As more than 1 parents were found already, there's no way for null parent_id here
$sql = 'SELECT m2.module_id as module_parent_id
FROM ' . $this->modules_table . ' m1, ' . $this->modules_table . " m2
WHERE " . ((is_numeric($data)) ? 'm1.module_id = ' . (int) $data : "m1.module_langname = '" . $this->db->sql_escape($data)) . "'
AND m2.module_id = m1.parent_id
AND " . $this->db->sql_in_set('m2.module_id', $ids);
$result = $this->db->sql_query($sql);
$parent_id = (int) $this->db->sql_fetchfield('module_parent_id');
}
else
{
//Unable to get the parent module id, throwing an exception
$exception = new \phpbb\db\migration\exception('MODULE_EXIST_MULTIPLE', $parent_id);
}

					// This represents the old behaviour of phpBB 3.0
return $ids;






























				break;
}

				break;
}

		}

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

 
		}

return $parent_id;

		}

return $parent_id;