Completed
Pull Request — master (#46)
by Matt
01:28
created

m5_remove_sites::remove_sites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * phpBB Media Embed PlugIn extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2019 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\mediaembed\migrations;
12
13
/**
14
 * Migration 5: Remove sites no longer supported in MediaEmbed from config_text storage
15
 */
16
class m5_remove_sites extends \phpbb\db\migration\container_aware_migration
17
{
18
	public static function depends_on()
19
	{
20
		return ['\phpbb\mediaembed\migrations\m1_install_data'];
21
	}
22
23
	public function update_data()
24
	{
25
		return [
26
			['config_text.update', ['media_embed_sites', call_user_func([$this, 'remove_sites'])]],
27
		];
28
	}
29
30
	/**
31
	 * Compare the sites currently stored in the config_text with the sites
32
	 * currently available in MediaEmbed. Remove any sites in config_text that
33
	 * are not found in MediaEmbed (which means they have been removed from it).
34
	 *
35
	 * @return string
36
	 */
37
	public function remove_sites()
38
	{
39
		$config_text = $this->container->get('config_text');
40
		$stored_sites = json_decode($config_text->get('media_embed_sites'), true);
41
42
		$configurator = $this->container->get('text_formatter.s9e.factory')->get_configurator();
43
		$available_sites = array_keys(iterator_to_array($configurator->MediaEmbed->defaultSites));
44
45
		return json_encode(array_values(array_intersect($stored_sites, $available_sites)));
46
	}
47
}
48