Augmentation vers version 3.3.0
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v30x;
|
||||
|
||||
class release_3_0_4_rc1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return phpbb_version_compare($this->config['version'], '3.0.4-RC1', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('\phpbb\db\migration\data\v30x\release_3_0_3');
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'profile_fields' => array(
|
||||
'field_show_profile' => array('BOOL', 0),
|
||||
),
|
||||
),
|
||||
'change_columns' => array(
|
||||
$this->table_prefix . 'styles' => array(
|
||||
'style_id' => array('UINT', NULL, 'auto_increment'),
|
||||
'template_id' => array('UINT', 0),
|
||||
'theme_id' => array('UINT', 0),
|
||||
'imageset_id' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'styles_imageset' => array(
|
||||
'imageset_id' => array('UINT', NULL, 'auto_increment'),
|
||||
),
|
||||
$this->table_prefix . 'styles_imageset_data' => array(
|
||||
'image_id' => array('UINT', NULL, 'auto_increment'),
|
||||
'imageset_id' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'styles_theme' => array(
|
||||
'theme_id' => array('UINT', NULL, 'auto_increment'),
|
||||
),
|
||||
$this->table_prefix . 'styles_template' => array(
|
||||
'template_id' => array('UINT', NULL, 'auto_increment'),
|
||||
),
|
||||
$this->table_prefix . 'styles_template_data' => array(
|
||||
'template_id' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'forums' => array(
|
||||
'forum_style' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'users' => array(
|
||||
'user_style' => array('UINT', 0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_columns' => array(
|
||||
$this->table_prefix . 'profile_fields' => array(
|
||||
'field_show_profile',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array(&$this, 'update_custom_profile_fields'))),
|
||||
|
||||
array('config.update', array('version', '3.0.4-RC1')),
|
||||
);
|
||||
}
|
||||
|
||||
public function update_custom_profile_fields()
|
||||
{
|
||||
// Update the Custom Profile Fields based on previous settings to the new \format
|
||||
$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
|
||||
FROM ' . PROFILE_FIELDS_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$sql_ary = array(
|
||||
'field_required' => 0,
|
||||
'field_show_on_reg' => 0,
|
||||
'field_hide' => 0,
|
||||
'field_show_profile'=> 0,
|
||||
);
|
||||
|
||||
if ($row['field_required'])
|
||||
{
|
||||
$sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
|
||||
}
|
||||
else if ($row['field_show_on_reg'])
|
||||
{
|
||||
$sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
|
||||
}
|
||||
else if ($row['field_hide'])
|
||||
{
|
||||
// Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
|
||||
$sql_ary['field_hide'] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// equivalent to "none", which is the "Display in user control panel" option
|
||||
$sql_ary['field_show_profile'] = 1;
|
||||
}
|
||||
|
||||
$this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v310;
|
||||
|
||||
class softdelete_p1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_visibility');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('\phpbb\db\migration\data\v310\dev');
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'forums' => array(
|
||||
'forum_posts_approved' => array('UINT', 0),
|
||||
'forum_posts_unapproved' => array('UINT', 0),
|
||||
'forum_posts_softdeleted' => array('UINT', 0),
|
||||
'forum_topics_approved' => array('UINT', 0),
|
||||
'forum_topics_unapproved' => array('UINT', 0),
|
||||
'forum_topics_softdeleted' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'posts' => array(
|
||||
'post_visibility' => array('TINT:3', 0),
|
||||
'post_delete_time' => array('TIMESTAMP', 0),
|
||||
'post_delete_reason' => array('STEXT_UNI', ''),
|
||||
'post_delete_user' => array('UINT', 0),
|
||||
),
|
||||
$this->table_prefix . 'topics' => array(
|
||||
'topic_visibility' => array('TINT:3', 0),
|
||||
'topic_delete_time' => array('TIMESTAMP', 0),
|
||||
'topic_delete_reason' => array('STEXT_UNI', ''),
|
||||
'topic_delete_user' => array('UINT', 0),
|
||||
'topic_posts_approved' => array('UINT', 0),
|
||||
'topic_posts_unapproved' => array('UINT', 0),
|
||||
'topic_posts_softdeleted' => array('UINT', 0),
|
||||
),
|
||||
),
|
||||
'add_index' => array(
|
||||
$this->table_prefix . 'posts' => array(
|
||||
'post_visibility' => array('post_visibility'),
|
||||
),
|
||||
$this->table_prefix . 'topics' => array(
|
||||
'topic_visibility' => array('topic_visibility'),
|
||||
'forum_vis_last' => array('forum_id', 'topic_visibility', 'topic_last_post_id'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_columns' => array(
|
||||
$this->table_prefix . 'forums' => array(
|
||||
'forum_posts_approved',
|
||||
'forum_posts_unapproved',
|
||||
'forum_posts_softdeleted',
|
||||
'forum_topics_approved',
|
||||
'forum_topics_unapproved',
|
||||
'forum_topics_softdeleted',
|
||||
),
|
||||
$this->table_prefix . 'posts' => array(
|
||||
'post_visibility',
|
||||
'post_delete_time',
|
||||
'post_delete_reason',
|
||||
'post_delete_user',
|
||||
),
|
||||
$this->table_prefix . 'topics' => array(
|
||||
'topic_visibility',
|
||||
'topic_delete_time',
|
||||
'topic_delete_reason',
|
||||
'topic_delete_user',
|
||||
'topic_posts_approved',
|
||||
'topic_posts_unapproved',
|
||||
'topic_posts_softdeleted',
|
||||
),
|
||||
),
|
||||
'drop_keys' => array(
|
||||
$this->table_prefix . 'posts' => array('post_visibility'),
|
||||
$this->table_prefix . 'topics' => array('topic_visibility', 'forum_vis_last'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array($this, 'update_post_visibility'))),
|
||||
array('custom', array(array($this, 'update_topic_visibility'))),
|
||||
array('custom', array(array($this, 'update_topics_post_counts'))),
|
||||
array('custom', array(array($this, 'update_forums_topic_and_post_counts'))),
|
||||
|
||||
array('permission.add', array('f_softdelete', false)),
|
||||
array('permission.add', array('m_softdelete', false)),
|
||||
);
|
||||
}
|
||||
|
||||
public function update_post_visibility()
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'posts
|
||||
SET post_visibility = post_approved';
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function update_topic_visibility()
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'topics
|
||||
SET topic_visibility = topic_approved';
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function update_topics_post_counts()
|
||||
{
|
||||
/*
|
||||
* Using sql_case here to avoid "BIGINT UNSIGNED value is out of range" errors.
|
||||
* As we update all topics in 2 queries, one broken topic would stop the conversion
|
||||
* for all topics and the suppressed error will cause the admin to not even notice it.
|
||||
*/
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'topics
|
||||
SET topic_posts_approved = topic_replies + 1,
|
||||
topic_posts_unapproved = ' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . '
|
||||
WHERE topic_visibility = ' . ITEM_APPROVED;
|
||||
$this->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'topics
|
||||
SET topic_posts_approved = 0,
|
||||
topic_posts_unapproved = (' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ') + 1
|
||||
WHERE topic_visibility = ' . ITEM_UNAPPROVED;
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
public function update_forums_topic_and_post_counts($start)
|
||||
{
|
||||
$start = (int) $start;
|
||||
$limit = 10;
|
||||
$converted_forums = 0;
|
||||
|
||||
if (!$start)
|
||||
{
|
||||
// Preserve the forum_posts value for link forums as it represents redirects.
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'forums
|
||||
SET forum_posts_approved = forum_posts
|
||||
WHERE forum_type = ' . FORUM_LINK;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
$sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved
|
||||
FROM ' . $this->table_prefix . 'topics
|
||||
GROUP BY forum_id, topic_visibility
|
||||
ORDER BY forum_id, topic_visibility';
|
||||
$result = $this->db->sql_query_limit($sql, $limit, $start);
|
||||
|
||||
$update_forums = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$converted_forums++;
|
||||
|
||||
$forum_id = (int) $row['forum_id'];
|
||||
if (!isset($update_forums[$forum_id]))
|
||||
{
|
||||
$update_forums[$forum_id] = array(
|
||||
'forum_posts_approved' => 0,
|
||||
'forum_posts_unapproved' => 0,
|
||||
'forum_topics_approved' => 0,
|
||||
'forum_topics_unapproved' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
$update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts_approved'];
|
||||
$update_forums[$forum_id]['forum_posts_unapproved'] += (int) $row['sum_posts_unapproved'];
|
||||
|
||||
$update_forums[$forum_id][(($row['topic_visibility'] == ITEM_APPROVED) ? 'forum_topics_approved' : 'forum_topics_unapproved')] += (int) $row['sum_topics'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
foreach ($update_forums as $forum_id => $forum_data)
|
||||
{
|
||||
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $forum_data) . '
|
||||
WHERE forum_id = ' . $forum_id;
|
||||
$this->sql_query($sql);
|
||||
}
|
||||
|
||||
if ($converted_forums < $limit)
|
||||
{
|
||||
// There are no more topics, we are done
|
||||
return;
|
||||
}
|
||||
|
||||
// There are still more topics to query, return the next start value
|
||||
return $start + $limit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class timezone_p3 extends \phpbb\db\migration\migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('\phpbb\db\migration\data\v310\timezone');
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.remove', array('board_dst')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class user_emoji_permission extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
$sql = 'SELECT auth_option_id
|
||||
FROM ' . ACL_OPTIONS_TABLE . "
|
||||
WHERE auth_option = 'u_emoji'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$auth_option_id = $this->db->sql_fetchfield('auth_option_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $auth_option_id !== false;
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v32x\v329rc1',
|
||||
];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['permission.add', ['u_emoji']],
|
||||
['permission.permission_set', ['REGISTERED', 'u_emoji', 'group']],
|
||||
];
|
||||
}
|
||||
}
|
||||
36
install/update/new/phpbb/db/migration/data/v32x/v328.php
Normal file
36
install/update/new/phpbb/db/migration/data/v32x/v328.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class v328 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return phpbb_version_compare($this->config['version'], '3.2.8', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\v328rc1',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.2.8')),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
install/update/new/phpbb/db/migration/data/v32x/v328rc1.php
Normal file
37
install/update/new/phpbb/db/migration/data/v32x/v328rc1.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class v328rc1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return phpbb_version_compare($this->config['version'], '3.2.8-RC1', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\timezone_p3',
|
||||
'\phpbb\db\migration\data\v32x\v327',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.2.8-RC1')),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
install/update/new/phpbb/db/migration/data/v32x/v329.php
Normal file
37
install/update/new/phpbb/db/migration/data/v32x/v329.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class v329 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return phpbb_version_compare($this->config['version'], '3.2.9', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\v329rc1',
|
||||
'\phpbb\db\migration\data\v32x\user_emoji_permission',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.2.9')),
|
||||
);
|
||||
}
|
||||
}
|
||||
36
install/update/new/phpbb/db/migration/data/v32x/v329rc1.php
Normal file
36
install/update/new/phpbb/db/migration/data/v32x/v329rc1.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v32x;
|
||||
|
||||
class v329rc1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return phpbb_version_compare($this->config['version'], '3.2.9-RC1', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\v328',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.2.9-RC1')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class add_display_unapproved_posts_config extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->config->offsetExists('display_unapproved_posts');
|
||||
}
|
||||
|
||||
public static function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v330\dev',];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['config.add', ['display_unapproved_posts', 1]],
|
||||
];
|
||||
}
|
||||
}
|
||||
36
install/update/new/phpbb/db/migration/data/v330/dev.php
Normal file
36
install/update/new/phpbb/db/migration/data/v330/dev.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class dev extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return version_compare($this->config['version'], '3.3.0-dev', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\v327',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.3.0-dev')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class forums_legend_limit extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->db_tools->sql_column_exists($this->table_prefix . 'forums', 'display_subforum_limit');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v330\v330b1'];
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return [
|
||||
'add_columns' => [
|
||||
$this->table_prefix . 'forums' => [
|
||||
'display_subforum_limit' => ['BOOL', 0, 'after' => 'display_subforum_list'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return [
|
||||
'drop_columns' => [
|
||||
$this->table_prefix . 'forums' => [
|
||||
'display_subforum_limit',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class jquery_update extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->config['load_jquery_url'] === '//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js';
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v330\dev',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js')),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class remove_attachment_flash extends \phpbb\db\migration\migration
|
||||
{
|
||||
// Following constants were deprecated in 3.3
|
||||
// and moved from constants.php to compatibility_globals.php,
|
||||
// thus define them as class constants
|
||||
const ATTACHMENT_CATEGORY_FLASH = 5;
|
||||
|
||||
protected $cat_id = array(
|
||||
self::ATTACHMENT_CATEGORY_FLASH,
|
||||
);
|
||||
|
||||
public static function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v330\dev',];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array($this, 'remove_flash_group'))),
|
||||
);
|
||||
}
|
||||
|
||||
public function remove_flash_group()
|
||||
{
|
||||
// select group ids of outdated media
|
||||
$sql = 'SELECT group_id
|
||||
FROM ' . EXTENSION_GROUPS_TABLE . '
|
||||
WHERE ' . $this->db->sql_in_set('cat_id', $this->cat_id);
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$group_ids = array();
|
||||
while ($group_id = (int) $this->db->sql_fetchfield('group_id'))
|
||||
{
|
||||
$group_ids[] = $group_id;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// nothing to do, admin has removed all the outdated media extension groups
|
||||
if (empty($group_ids))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// get the group id of downloadable files
|
||||
$sql = 'SELECT group_id
|
||||
FROM ' . EXTENSION_GROUPS_TABLE . "
|
||||
WHERE group_name = 'DOWNLOADABLE_FILES'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$download_id = (int) $this->db->sql_fetchfield('group_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (empty($download_id))
|
||||
{
|
||||
$sql = 'UPDATE ' . EXTENSIONS_TABLE . '
|
||||
SET group_id = 0
|
||||
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
|
||||
}
|
||||
else
|
||||
{
|
||||
// move outdated media extensions to downloadable files
|
||||
$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
|
||||
SET group_id = $download_id" . '
|
||||
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
|
||||
}
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// delete the now empty, outdated media extension groups
|
||||
$sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . '
|
||||
WHERE ' . $this->db->sql_in_set('group_id', $group_ids);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class remove_email_hash extends \phpbb\db\migration\migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return ['\phpbb\db\migration\data\v30x\release_3_0_0'];
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return [
|
||||
'add_index' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'user_email' => ['user_email'],
|
||||
],
|
||||
],
|
||||
'drop_keys' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'user_email_hash',
|
||||
],
|
||||
],
|
||||
'drop_columns' => [
|
||||
$this->table_prefix . 'users' => ['user_email_hash'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return [
|
||||
'add_columns' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'user_email_hash' => ['BINT', 0],
|
||||
],
|
||||
],
|
||||
'add_index' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'user_email_hash',
|
||||
],
|
||||
],
|
||||
'drop_keys' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'user_email' => ['user_email'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class remove_max_pass_chars extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return !$this->config->offsetExists('max_pass_chars');
|
||||
}
|
||||
|
||||
public static function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v330\dev',
|
||||
];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['config.remove', ['max_pass_chars']],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_data()
|
||||
{
|
||||
return [
|
||||
['config.add', ['max_pass_chars', 100]],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class reset_password extends \phpbb\db\migration\migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v330\dev',
|
||||
];
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return [
|
||||
'add_columns' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'reset_token' => ['VCHAR:64', '', 'after' => 'user_actkey'],
|
||||
'reset_token_expiration' => ['TIMESTAMP', 0, 'after' => 'reset_token'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return [
|
||||
'drop_columns' => [
|
||||
$this->table_prefix . 'users' => [
|
||||
'reset_token',
|
||||
'reset_token_expiration',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
37
install/update/new/phpbb/db/migration/data/v330/v330.php
Normal file
37
install/update/new/phpbb/db/migration/data/v330/v330.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class v330 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return version_compare($this->config['version'], '3.3.0', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v32x\v329',
|
||||
'\phpbb\db\migration\data\v330\v330rc1',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.3.0')),
|
||||
);
|
||||
}
|
||||
}
|
||||
41
install/update/new/phpbb/db/migration/data/v330/v330b1.php
Normal file
41
install/update/new/phpbb/db/migration/data/v330/v330b1.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class v330b1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return version_compare($this->config['version'], '3.3.0-b1', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v330\jquery_update',
|
||||
'\phpbb\db\migration\data\v330\reset_password',
|
||||
'\phpbb\db\migration\data\v330\remove_attachment_flash',
|
||||
'\phpbb\db\migration\data\v330\remove_max_pass_chars',
|
||||
'\phpbb\db\migration\data\v32x\v328',
|
||||
'\phpbb\db\migration\data\v330\dev',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.3.0-b1')),
|
||||
);
|
||||
}
|
||||
}
|
||||
39
install/update/new/phpbb/db/migration/data/v330/v330b2.php
Normal file
39
install/update/new/phpbb/db/migration/data/v330/v330b2.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class v330b2 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return version_compare($this->config['version'], '3.3.0-b2', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v330\add_display_unapproved_posts_config',
|
||||
'\phpbb\db\migration\data\v330\forums_legend_limit',
|
||||
'\phpbb\db\migration\data\v330\remove_email_hash',
|
||||
'\phpbb\db\migration\data\v330\v330b1',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.3.0-b2')),
|
||||
);
|
||||
}
|
||||
}
|
||||
36
install/update/new/phpbb/db/migration/data/v330/v330rc1.php
Normal file
36
install/update/new/phpbb/db/migration/data/v330/v330rc1.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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\data\v330;
|
||||
|
||||
class v330rc1 extends \phpbb\db\migration\migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return version_compare($this->config['version'], '3.3.0-RC1', '>=');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array(
|
||||
'\phpbb\db\migration\data\v330\v330b2',
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.update', array('version', '3.3.0-RC1')),
|
||||
);
|
||||
}
|
||||
}
|
||||
556
install/update/new/phpbb/db/migration/tool/module.php
Normal file
556
install/update/new/phpbb/db/migration/tool/module.php
Normal file
@@ -0,0 +1,556 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
class module implements \phpbb\db\migration\tool\tool_interface
|
||||
{
|
||||
/** @var \phpbb\cache\service */
|
||||
protected $cache;
|
||||
|
||||
/** @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;
|
||||
|
||||
/** @var string */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var string */
|
||||
protected $modules_table;
|
||||
|
||||
/** @var array */
|
||||
protected $module_categories = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @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_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'module';
|
||||
}
|
||||
|
||||
/**
|
||||
* Module Exists
|
||||
*
|
||||
* Check if a module exists
|
||||
*
|
||||
* @param string $class The module class(acp|mcp|ucp)
|
||||
* @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 you would like to
|
||||
* check for to see if it 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 in any given parent;
|
||||
* true if ignoring parent check and module exists class wide, false if not found at all.
|
||||
*/
|
||||
public function exists($class, $parent, $module, $lazy = false)
|
||||
{
|
||||
// the main root directory should return true
|
||||
if (!$module)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent_sqls = [];
|
||||
if ($parent !== false)
|
||||
{
|
||||
$parents = $this->get_parent_module_id($parent, $module, false);
|
||||
if ($parents === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ((array) $parents as $parent_id)
|
||||
{
|
||||
$parent_sqls[] = 'AND parent_id = ' . (int) $parent_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$parent_sqls[] = '';
|
||||
}
|
||||
|
||||
foreach ($parent_sqls as $parent_sql)
|
||||
{
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
$parent_sql
|
||||
AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'");
|
||||
$result = $this->db->sql_query($sql);
|
||||
$module_id = $this->db->sql_fetchfield('module_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!$lazy && !$module_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($lazy && $module_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true, if modules exist in all parents and false otherwise
|
||||
return !$lazy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Module Add
|
||||
*
|
||||
* Add a new module
|
||||
*
|
||||
* @param string $class The module class(acp|mcp|ucp)
|
||||
* @param int|string $parent The parent module_id|module_langname (0 for no parent)
|
||||
* @param array $data an array of the data on the new \module.
|
||||
* This can be setup in two different ways.
|
||||
* 1. The "manual" way. For inserting a category or one at a time.
|
||||
* It will be merged with the base array shown a bit below,
|
||||
* but at the least requires 'module_langname' to be sent, and,
|
||||
* if you want to create a module (instead of just a category) you must
|
||||
* send module_basename and module_mode.
|
||||
* array(
|
||||
* 'module_enabled' => 1,
|
||||
* 'module_display' => 1,
|
||||
* 'module_basename' => '',
|
||||
* 'module_class' => $class,
|
||||
* 'parent_id' => (int) $parent,
|
||||
* 'module_langname' => '',
|
||||
* 'module_mode' => '',
|
||||
* 'module_auth' => '',
|
||||
* )
|
||||
* 2. The "automatic" way. For inserting multiple at a time based on the
|
||||
* specs in the info file for the module(s). For this to work the
|
||||
* modules must be correctly setup in the info file.
|
||||
* An example follows (this would insert the settings, log, and flag
|
||||
* modes from the includes/acp/info/acp_asacp.php file):
|
||||
* array(
|
||||
* 'module_basename' => 'asacp',
|
||||
* 'modes' => array('settings', 'log', 'flag'),
|
||||
* )
|
||||
* Optionally you may not send 'modes' and it will insert all of the
|
||||
* modules in that info file.
|
||||
* path, specify that here
|
||||
* @return null
|
||||
* @throws \phpbb\db\migration\exception
|
||||
*/
|
||||
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))
|
||||
{
|
||||
$data = array('module_langname' => $data);
|
||||
}
|
||||
|
||||
$parents = (array) $this->get_parent_module_id($parent, $data);
|
||||
|
||||
if (!isset($data['module_langname']))
|
||||
{
|
||||
// The "automatic" way
|
||||
$basename = (isset($data['module_basename'])) ? $data['module_basename'] : '';
|
||||
$module = $this->get_module_info($class, $basename);
|
||||
|
||||
foreach ($module['modes'] as $mode => $module_info)
|
||||
{
|
||||
if (!isset($data['modes']) || in_array($mode, $data['modes']))
|
||||
{
|
||||
$new_module = array(
|
||||
'module_basename' => $basename,
|
||||
'module_langname' => $module_info['title'],
|
||||
'module_mode' => $mode,
|
||||
'module_auth' => $module_info['auth'],
|
||||
'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true,
|
||||
'before' => (isset($module_info['before'])) ? $module_info['before'] : false,
|
||||
'after' => (isset($module_info['after'])) ? $module_info['after'] : false,
|
||||
);
|
||||
|
||||
// Run the "manual" way with the data we've collected.
|
||||
foreach ($parents as $parent)
|
||||
{
|
||||
$this->add($class, $parent, $new_module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($parents as $parent)
|
||||
{
|
||||
$data['parent_id'] = $parent;
|
||||
|
||||
// The "manual" way
|
||||
if (!$this->exists($class, false, $parent))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent);
|
||||
}
|
||||
|
||||
if ($this->exists($class, $parent, $data['module_langname']))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_EXISTS', $data['module_langname']);
|
||||
}
|
||||
|
||||
$module_data = array(
|
||||
'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1,
|
||||
'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1,
|
||||
'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '',
|
||||
'module_class' => $class,
|
||||
'parent_id' => (int) $parent,
|
||||
'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '',
|
||||
'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '',
|
||||
'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '',
|
||||
);
|
||||
|
||||
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']);
|
||||
$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'])
|
||||
{
|
||||
$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 . "
|
||||
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');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND left_id >= $to_left
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = $to_left, right_id = " . ($to_left + 1) . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND module_id = {$module_data['module_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
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 . "
|
||||
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');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . "
|
||||
SET left_id = left_id + 2, right_id = right_id + 2
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
AND left_id >= $to_right
|
||||
AND left_id < {$module_data['left_id']}";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->modules_table . '
|
||||
SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . "
|
||||
WHERE module_class = '" . $this->db->sql_escape($class) . "'
|
||||
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
|
||||
$this->module_manager->remove_cache_file($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Module Remove
|
||||
*
|
||||
* Remove a module
|
||||
*
|
||||
* @param string $class The module class(acp|mcp|ucp)
|
||||
* @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
|
||||
* specify that here
|
||||
* @return null
|
||||
* @throws \phpbb\db\migration\exception
|
||||
*/
|
||||
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))
|
||||
{
|
||||
if (isset($module['module_langname']))
|
||||
{
|
||||
// Manual Method
|
||||
return $this->remove($class, $parent, $module['module_langname']);
|
||||
}
|
||||
|
||||
// Failed.
|
||||
if (!isset($module['module_basename']))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST');
|
||||
}
|
||||
|
||||
// Automatic method
|
||||
$basename = $module['module_basename'];
|
||||
$module_info = $this->get_module_info($class, $basename);
|
||||
|
||||
foreach ($module_info['modes'] as $mode => $info)
|
||||
{
|
||||
if (!isset($module['modes']) || in_array($mode, $module['modes']))
|
||||
{
|
||||
$this->remove($class, $parent, $info['title']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$this->exists($class, $parent, $module, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$parent_sql = '';
|
||||
if ($parent !== false)
|
||||
{
|
||||
$parents = (array) $this->get_parent_module_id($parent, $module);
|
||||
$parent_sql = 'AND ' . $this->db->sql_in_set('parent_id', $parents);
|
||||
}
|
||||
|
||||
$module_ids = array();
|
||||
if (!is_numeric($module))
|
||||
{
|
||||
$sql = 'SELECT module_id
|
||||
FROM ' . $this->modules_table . "
|
||||
WHERE module_langname = '" . $this->db->sql_escape($module) . "'
|
||||
AND module_class = '" . $this->db->sql_escape($class) . "'
|
||||
$parent_sql";
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($module_id = $this->db->sql_fetchfield('module_id'))
|
||||
{
|
||||
$module_ids[] = (int) $module_id;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
$module_ids[] = (int) $module;
|
||||
}
|
||||
|
||||
foreach ($module_ids as $module_id)
|
||||
{
|
||||
$this->module_manager->delete_module($module_id, $class);
|
||||
}
|
||||
|
||||
$this->module_manager->remove_cache_file($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reverse()
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
$original_call = array_shift($arguments);
|
||||
|
||||
$call = false;
|
||||
switch ($original_call)
|
||||
{
|
||||
case 'add':
|
||||
$call = 'remove';
|
||||
break;
|
||||
|
||||
case 'remove':
|
||||
$call = 'add';
|
||||
break;
|
||||
|
||||
case 'reverse':
|
||||
// Reversing a reverse is just the call itself
|
||||
$call = array_shift($arguments);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($call)
|
||||
{
|
||||
return call_user_func_array(array(&$this, $call), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for \acp_modules::get_module_infos()
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$module = $this->module_manager->get_module_infos($class, $basename, true);
|
||||
|
||||
if (empty($module))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename);
|
||||
}
|
||||
|
||||
return array_pop($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of installed module categories
|
||||
* key - module_id
|
||||
* value - module_langname
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_categories_list()
|
||||
{
|
||||
// Select the top level categories
|
||||
// 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
|
||||
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);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$this->module_categories[(int) $row['module_id']] = $row['module_langname'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent module id
|
||||
*
|
||||
* @param string|int $parent_id The parent module_id|module_langname
|
||||
* @param int|string|array $data The module_id, module_langname for existence 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, 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)
|
||||
{
|
||||
// Allow '' to be sent as 0
|
||||
$parent_id = $parent_id ?: 0;
|
||||
|
||||
if (!is_numeric($parent_id))
|
||||
{
|
||||
// Refresh the $module_categories array
|
||||
$this->get_categories_list();
|
||||
|
||||
// Search for the parent module_langname
|
||||
$ids = array_keys($this->module_categories, $parent_id);
|
||||
|
||||
switch (count($ids))
|
||||
{
|
||||
// No parent with the given module_langname exist
|
||||
case 0:
|
||||
if ($throw_exception)
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST', $parent_id);
|
||||
}
|
||||
|
||||
return false;
|
||||
break;
|
||||
|
||||
// Return the module id
|
||||
case 1:
|
||||
return (int) $ids[0];
|
||||
break;
|
||||
|
||||
default:
|
||||
// This represents the old behaviour of phpBB 3.0
|
||||
return $ids;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $parent_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user