[ticket/10824] Use json_sanitzer::decode and improve migrations from pre 3.2

PHPBB3-10824
This commit is contained in:
Marc Alexander 2018-12-28 11:15:40 +01:00
parent 5dc2e500f5
commit 204f81c6f7
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
6 changed files with 35 additions and 15 deletions

View file

@ -1191,6 +1191,7 @@ class acp_styles
* Read style composer.json file * Read style composer.json file
* *
* @param string $dir style directory * @param string $dir style directory
*
* @return array Style data * @return array Style data
* @throws \DomainException in case of error * @throws \DomainException in case of error
*/ */
@ -1203,7 +1204,7 @@ class acp_styles
} }
$json = file_get_contents($this->styles_path . $dir . '/composer.json'); $json = file_get_contents($this->styles_path . $dir . '/composer.json');
$style_data = \phpbb\json_sanitizer::sanitize(json_decode($json, true)); $style_data = \phpbb\json_sanitizer::decode($json);
if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style') if (!is_array($style_data) || !isset($style_data['type']) || $style_data['type'] !== 'phpbb-style')
{ {

View file

@ -13,6 +13,8 @@
namespace phpbb\cache; namespace phpbb\cache;
use phpbb\json_sanitizer;
/** /**
* Class for grabbing/handling cached entries * Class for grabbing/handling cached entries
*/ */
@ -355,7 +357,7 @@ class service
{ {
// Re-parse cfg file // Re-parse cfg file
$json = file_get_contents($filename); $json = file_get_contents($filename);
$parsed_array = json_decode($json, true); $parsed_array = json_sanitizer::decode($json);
$parsed_array['filetime'] = @filemtime($filename); $parsed_array['filetime'] = @filemtime($filename);
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array); $this->driver->put('_cfg_' . $style['style_path'], $parsed_array);

View file

@ -13,6 +13,8 @@
namespace phpbb\db\migration\data\v310; namespace phpbb\db\migration\data\v310;
use phpbb\json_sanitizer;
class style_update_p1 extends \phpbb\db\migration\migration class style_update_p1 extends \phpbb\db\migration\migration
{ {
public function effectively_installed() public function effectively_installed()
@ -69,14 +71,26 @@ class style_update_p1 extends \phpbb\db\migration\migration
$skip_dirs = array('.', '..', 'prosilver'); $skip_dirs = array('.', '..', 'prosilver');
foreach ($iterator as $fileinfo) foreach ($iterator as $fileinfo)
{ {
if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/composer.json')) if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs))
{ {
$json = file_get_contents($fileinfo->getPathname() . '/composer.json'); if (file_exists($fileinfo->getPathname() . '/style.cfg'))
$style_data = json_decode($json, true);
if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.1.0-dev', '>='))
{ {
// 3.1 style $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
$available_styles[] = $fileinfo->getFilename(); if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>='))
{
// 3.1 & 3.2 style
$available_styles[] = $fileinfo->getFilename();
}
}
else if (file_exists($fileinfo->getPathname() . '/composer.json'))
{
$json = file_get_contents($fileinfo->getPathname() . '/composer.json');
$style_data = json_sanitizer::decode($json);
if (isset($style_data['extra']['phpbb-version']) && version_compare($style_data['extra']['phpbb-version'], '3.3.0-dev', '>='))
{
// 3.3 style
$available_styles[] = $fileinfo->getFilename();
}
} }
} }
} }

View file

@ -49,8 +49,11 @@ class style_update extends \phpbb\db\migration\migration
// Install prosilver if no style is available and prosilver can be installed // Install prosilver if no style is available and prosilver can be installed
if (empty($style_paths) && in_array('prosilver', $styles)) if (empty($style_paths) && in_array('prosilver', $styles))
{ {
// Stop running this if prosilver composer.json file can't be read // Try to parse config file
if (file_exists($this->phpbb_root_path . 'styles/prosilver/composer.json')) $cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg');
// Stop running this if both prosilver cfg file and composer.json file can't be read
if (empty($cfg) && !file_exists($this->phpbb_root_path . 'styles/prosilver/composer.json'))
{ {
throw new \RuntimeException('No styles available and could not fall back to prosilver.'); throw new \RuntimeException('No styles available and could not fall back to prosilver.');
} }
@ -120,7 +123,7 @@ class style_update extends \phpbb\db\migration\migration
continue; continue;
} }
if (file_exists("{$dir}/composer.json")) if (file_exists("{$dir}/composer.json") || file_exists("{$dir}/style.cfg"))
{ {
$styles[] = $file; $styles[] = $file;
} }

View file

@ -13,6 +13,7 @@
namespace phpbb\language; namespace phpbb\language;
use phpbb\json_sanitizer;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
/** /**
@ -54,7 +55,7 @@ class language_file_helper
foreach ($finder as $file) foreach ($finder as $file)
{ {
$json = $file->getContents(); $json = $file->getContents();
$data = \phpbb\json_sanitizer::sanitize(json_decode($json, true)); $data = json_sanitizer::decode($json);
$available_languages[] = $this->get_language_data_from_json($data); $available_languages[] = $this->get_language_data_from_json($data);
} }
@ -71,7 +72,7 @@ class language_file_helper
public function get_language_data_from_composer_file($path) public function get_language_data_from_composer_file($path)
{ {
$json_data = file_get_contents($path); $json_data = file_get_contents($path);
return $this->get_language_data_from_json(json_decode($json_data, true)); return $this->get_language_data_from_json(json_sanitizer::decode($json_data));
} }
/** /**
@ -101,7 +102,6 @@ class language_file_helper
return array( return array(
'iso' => $data['extra']['language-iso'], 'iso' => $data['extra']['language-iso'],
'name' => $data['extra']['english-name'], 'name' => $data['extra']['english-name'],
'local_name' => $data['extra']['local-name'], 'local_name' => $data['extra']['local-name'],
'author' => implode(', ', $authors), 'author' => implode(', ', $authors),

View file

@ -390,7 +390,7 @@ class version_helper
} }
// Sanitize any data we retrieve from a server // Sanitize any data we retrieve from a server
$info = \phpbb\json_sanitizer::sanitize(json_decode($info, true)); $info = json_sanitizer::decode($info);
if (empty($info['stable']) && empty($info['unstable'])) if (empty($info['stable']) && empty($info['unstable']))
{ {