[ticket/17361] Fix migrations

PHPBB-17361
This commit is contained in:
Ruben Calvo 2024-11-30 03:22:46 +01:00
parent a44295a1ba
commit 1f7ae9e2b0
No known key found for this signature in database
7 changed files with 103 additions and 7 deletions

View file

@ -162,12 +162,7 @@ class acp_database
throw new \phpbb\exception\runtime_exception('CANNOT_OPEN_FILE');
}
$storage->write_stream($file, $fp);
if (is_resource($fp))
{
fclose($fp);
}
$storage->write($file, $fp);
// Remove file from tmp
@unlink($temp_dir . '/' . $file);

View file

@ -38,4 +38,13 @@ class storage_attachment extends migration
['config.remove', ['upload_path']],
];
}
public function revert_data()
{
return [
['config.remove', ['storage\\attachment\\provider']],
['config.remove', ['storage\\attachment\\config\\path']],
['config.add', ['upload_path', 'files']],
];
}
}

View file

@ -38,4 +38,13 @@ class storage_avatar extends migration
['config.remove', ['avatar_path']],
];
}
public function revert_data()
{
return [
['config.remove', ['storage\\avatar\\provider']],
['config.remove', ['storage\\avatar\\config\\path']],
['config.add', ['avatar_path', 'images/avatars/upload']],
];
}
}

View file

@ -45,6 +45,15 @@ class storage_backup extends migration
];
}
public function revert_schema()
{
return [
'drop_tables' => [
$this->table_prefix . 'backups',
],
];
}
public function update_data()
{
return [
@ -52,4 +61,12 @@ class storage_backup extends migration
['config.add', ['storage\\backup\\config\\path', 'store']],
];
}
public function revert_data()
{
return [
['config.remove', ['storage\\backup\\provider']],
['config.remove', ['storage\\backup\\config\\path']],
];
}
}

View file

@ -0,0 +1,65 @@
<?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\v400;
use phpbb\db\migration\migration;
class storage_backup_data extends migration
{
public static function depends_on()
{
return [
'\phpbb\db\migration\data\v400\storage_backup',
];
}
public function update_data()
{
return [
['custom', [[$this, 'update_backup_data']]],
];
}
public function update_backup_data()
{
$methods = ['sql', 'sql.gz', 'sql.bz2'];
$dir = $this->phpbb_root_path . 'store/';
$dh = @opendir($dir);
if ($dh)
{
while (($file = readdir($dh)) !== false)
{
echo "FILE $file\n";
if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
{
if (in_array($matches[2], $methods))
{
$insert_ary = [
'filename' => $file,
];
$sql = 'INSERT INTO ' . $this->table_prefix . 'backups ' . $this->db->sql_build_array('INSERT', $insert_ary);
$this->db->sql_query($sql);
}
}
}
closedir($dh);
}
}
}

View file

@ -30,6 +30,7 @@ class storage_track extends container_aware_migration
'\phpbb\db\migration\data\v400\storage_attachment',
'\phpbb\db\migration\data\v400\storage_avatar',
'\phpbb\db\migration\data\v400\storage_backup',
'\phpbb\db\migration\data\v400\storage_backup_data',
];
}

View file

@ -89,7 +89,7 @@ class adapter_factory
}
$adapter = $this->adapters->get_by_class($provider->get_adapter_class());
$options['storage'] = $storage_name;
$options['storage'] = $storage_name; // Inject storage name into options so it can be used by extensiosn
$adapter->configure($options);
return $adapter;