Compare commits

...

12 commits

Author SHA1 Message Date
Matt Friedman
491af32565
Merge 6b6b5ffc28 into 083ae1102b 2025-06-13 21:22:25 +02:00
Marc Alexander
083ae1102b Merge branch '3.3.x' 2025-06-13 18:52:53 +00:00
Marc Alexander
c726382d84
Merge pull request #6824 from iMattPro/ticket/17519
[ticket/17519] Correctly encode cron task urls
2025-06-13 20:41:22 +02:00
Marc Alexander
db19a4a578
Merge pull request #6828 from marc1706/ticket/17519-master
[ticket/17519] Correctly encode cron task urls -- master version
2025-06-13 20:41:18 +02:00
Marc Alexander
0b3897b8c3
[ticket/17519] Adapt wrapper test for master
PHPBB-17519
2025-06-12 21:38:55 +02:00
Marc Alexander
b2d48b679f
Merge branch 'ticket/17519' into ticket/17519-master 2025-06-12 21:15:38 +02:00
Marc Alexander
5deeea025f
[ticket/17519] Add unit tests for task wrapper
PHPBB-17519
2025-06-12 21:00:24 +02:00
Marc Alexander
d3bb7e5bd3
Merge pull request #6823 from CHItA/ticket/17516
[ticket/17516] Remove dependency on topological sort library
2025-06-11 17:25:52 +02:00
Matt Friedman
6947dc8c92 [ticket/17519] Correctly encode cron task urls
PHPBB-17519
2025-06-03 04:21:24 +00:00
Máté Bartus
b9df5bbbf0 [ticket/17516] Remove dependency on topological sort library
PHPBB-17516
2025-06-01 12:06:58 +01:00
Matt Friedman
6b6b5ffc28
[ticket/17513] Fix JS linting
PHPBB-17513
2025-05-20 12:11:39 -07:00
Matt Friedman
4f66ec8758
[ticket/17513] Wrap async logic inside event.waitUntil in push worker
PHPBB-17513
2025-05-20 10:23:00 -07:00
10 changed files with 222 additions and 96 deletions

View file

@ -33,7 +33,6 @@
"ext-sodium": "*",
"bantu/ini-get-wrapper": "~1.0",
"carlos-mg89/oauth": "^0.8.15",
"chita/topological_sort": "^3.0",
"composer/composer": "^2.0",
"composer/installers": "^1.9",
"composer/package-versions-deprecated": "^1.11",

43
phpBB/composer.lock generated
View file

@ -171,49 +171,6 @@
},
"time": "2025-02-08T12:14:07+00:00"
},
{
"name": "chita/topological_sort",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/CHItA/TopologicalSort.git",
"reference": "9e0401c712d0c7cf012f264cc105669844d2479e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/CHItA/TopologicalSort/zipball/9e0401c712d0c7cf012f264cc105669844d2479e",
"reference": "9e0401c712d0c7cf012f264cc105669844d2479e",
"shasum": ""
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"CHItA\\TopologicalSort\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Máté Bartus",
"email": "mate.bartus@gmail.com"
}
],
"description": "Topological sort function",
"support": {
"issues": "https://github.com/CHItA/TopologicalSort/issues",
"source": "https://github.com/CHItA/TopologicalSort/tree/v3.0.1"
},
"time": "2021-01-04T21:31:59+00:00"
},
{
"name": "composer/ca-bundle",
"version": "1.5.6",

View file

@ -14,21 +14,17 @@
namespace phpbb\db\migration;
use Closure;
use LogicException;
use phpbb\config\config;
use phpbb\db\driver\driver_interface;
use phpbb\db\migrator;
use phpbb\db\tools\tools_interface;
use UnexpectedValueException;
use CHItA\TopologicalSort\TopologicalSort;
/**
* The schema generator generates the schema based on the existing migrations
*/
class schema_generator
{
use TopologicalSort;
/** @var config */
protected $config;
@ -103,24 +99,56 @@ class schema_generator
return $this->tables;
}
$migrations = $this->class_names;
$filter = function($class_name) {
return !migrator::is_migration($class_name);
};
$edges = function($class_name) {
return $class_name::depends_on();
};
$apply_for_each = function($class_name) {
$this->apply_migration_to_schema($class_name);
};
try
$dependency_counts = [];
$dependencies = [];
$applicable_migrations = [];
$migration_count = 0;
foreach ($this->class_names as $class_name)
{
$this->topologicalSort($migrations, $edges, true, $apply_for_each, $filter);
if (!migrator::is_migration($class_name))
{
continue;
}
$migration_count++;
$migration_dependencies = $class_name::depends_on();
if (empty($migration_dependencies))
{
$applicable_migrations[] = $class_name;
continue;
}
$dependency_counts[$class_name] = count($migration_dependencies);
foreach ($migration_dependencies as $migration_dependency)
{
$dependencies[$migration_dependency][] = $class_name;
}
}
catch (LogicException $e)
$applied_migrations = 0;
while (!empty($applicable_migrations))
{
$migration = array_pop($applicable_migrations);
$this->apply_migration_to_schema($migration);
++$applied_migrations;
if (!array_key_exists($migration, $dependencies))
{
continue;
}
$dependents = $dependencies[$migration];
foreach ($dependents as $dependent)
{
$dependency_counts[$dependent]--;
if ($dependency_counts[$dependent] === 0)
{
$applicable_migrations[] = $dependent;
}
}
}
if ($migration_count !== $applied_migrations)
{
throw new UnexpectedValueException(
"Migrations either have circular dependencies or unsatisfiable dependencies."

View file

@ -34,41 +34,48 @@ self.addEventListener('push', event => {
notificationVersion = parseInt(notificationData.version, 10);
pushToken = notificationData.token;
} catch {
self.registration.showNotification(event.data.text());
event.waitUntil(self.registration.showNotification(event.data.text()));
return;
}
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
event.waitUntil((async() => {
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
// Force update if versions differ
if (assetsVersion !== notificationVersion) {
self.registration.update();
}
// Force update if versions differ
if (assetsVersion !== notificationVersion) {
await self.registration.update();
}
const formData = new FormData();
formData.append('item_id', itemId.toString(10));
formData.append('type_id', typeId.toString(10));
formData.append('user_id', userId.toString(10));
formData.append('token', pushToken);
const formData = new FormData();
formData.append('item_id', itemId.toString(10));
formData.append('type_id', typeId.toString(10));
formData.append('user_id', userId.toString(10));
formData.append('token', pushToken);
fetch(getNotificationUrl, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
body: formData,
})
.then(response => response.json())
.then(response => {
const responseBody = response.title + '\n' + response.text;
try {
const response = await fetch(getNotificationUrl, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
body: formData,
});
const responseData = await response.json();
const responseBody = responseData.title + '\n' + responseData.text;
const options = {
body: responseBody,
data: response,
icon: response.avatar.src,
data: responseData,
icon: responseData.avatar.src,
};
self.registration.showNotification(response.heading, options);
});
await self.registration.showNotification(responseData.heading, options);
} catch (e) {
console.error('Push error:', e);
}
})());
});
/**

View file

@ -4,4 +4,4 @@
to hide visually and `aria-hidden="true"` to hide from screen-readers; using
`hidden` or `display: none` would prevent the task from running.
#}
<img class="sr-only" aria-hidden="true" src="{{ CRON_TASK_URL|e('html_attr') }}" width="1" height="1" alt="">
<img class="sr-only" aria-hidden="true" src="{{ CRON_TASK_URL|e('url') }}" width="1" height="1" alt="">

131
tests/cron/wrapper_test.php Normal file
View file

@ -0,0 +1,131 @@
<?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.
*
*/
require_once __DIR__ . '/../template/template_test_case.php';
class phpbb_cron_wrapper_test extends phpbb_template_template_test_case
{
private $task;
private $routing_helper;
private $wrapper;
protected function setUp(): void
{
global $phpbb_root_path;
$this->setup_engine([], $phpbb_root_path . 'styles/all/template');
global $phpbb_filesystem;
$phpbb_filesystem = new \phpbb\filesystem\filesystem();
$this->task = $this->createMock(\phpbb\cron\task\task::class);
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
}
public function test_generate_template_pagination()
{
$this->task = $this->createMock(\phpbb\cron\task\parametrized::class);
$this->task->expects($this->any())
->method('get_parameters')
->willReturn(['f' => '5']);
$this->task->expects($this->any())
->method('get_name')
->willReturn('test_task');
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->routing_helper->expects($this->any())
->method('route')
->with('phpbb_cron_run', ['cron_type' => 'test_task', 'f' => '5'])
->willReturn('app.php/cron/foo?f=5');
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->assertEquals('<img class="sr-only" aria-hidden="true" src="app.php%2Fcron%2Ffoo%3Ff%3D5" width="1" height="1" alt="">', str_replace(["\n", "\t"], '', $this->wrapper->get_html_tag()));
}
public function test_is_parametrized_false()
{
$this->assertFalse($this->wrapper->is_parametrized());
}
public function test_is_ready()
{
$this->task->method('is_runnable')->willReturn(true);
$this->task->method('should_run')->willReturn(true);
$this->assertTrue($this->wrapper->is_ready());
}
public function test_get_url_non_parametrized()
{
$this->task->method('get_name')->willReturn('test_task');
$this->routing_helper->expects($this->once())
->method('route')
->with('phpbb_cron_run', ['cron_type' => 'test_task'])
->willReturn('/cron/url');
$this->assertEquals('/cron/url', $this->wrapper->get_url());
}
public function test_get_html_tag()
{
$this->template = $this->createMock(\phpbb\template\template::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->template->expects($this->once())
->method('set_filenames');
$this->template->expects($this->once())
->method('assign_var');
$this->template->expects($this->once())
->method('assign_display')
->willReturn('<img src="cron">');
$this->assertEquals('<img src="cron">', $this->wrapper->get_html_tag());
}
public function test_call_forwards_to_task()
{
$this->task = $this->getMockBuilder(\phpbb\cron\task\task::class)
->disableOriginalConstructor()
->setMethods(['get_name', 'run', 'is_runnable', 'should_run', 'some_method'])
->getMock();
$this->routing_helper = $this->createMock(\phpbb\routing\helper::class);
$this->wrapper = new \phpbb\cron\task\wrapper(
$this->task,
$this->routing_helper,
$this->template
);
$this->task->expects($this->once())
->method('some_method')
->with('arg1', 'arg2')
->willReturn('result');
$result = $this->wrapper->some_method('arg1', 'arg2');
$this->assertEquals('result', $result);
}
}

View file

@ -15,7 +15,7 @@ require_once __DIR__ . '/template_test_case.php';
class phpbb_template_extension_test extends phpbb_template_template_test_case
{
protected function setup_engine(array $new_config = [])
protected function setup_engine(array $new_config = [], string $template_path = '')
{
global $config, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx;

View file

@ -21,7 +21,7 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te
/** @var string */
protected $parent_template_path;
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = array(), string $template_path = '')
{
global $phpbb_root_path, $phpEx, $user;

View file

@ -1,4 +1,7 @@
<?php
use phpbb\template\twig\twig;
/**
*
* This file is part of the phpBB Forum Software package.
@ -14,6 +17,7 @@
class phpbb_template_template_test_case extends phpbb_test_case
{
protected $lang;
/** @var twig */
protected $template;
protected $template_path;
protected $user;
@ -68,7 +72,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
return $defaults;
}
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = array(), string $template_path = '')
{
global $phpbb_root_path, $phpEx;
@ -90,7 +94,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$phpEx
);
$this->template_path = $this->test_path . '/templates';
$this->template_path = $template_path ?: $this->test_path . '/templates';
$cache_path = $phpbb_root_path . 'cache/twig';
$context = new \phpbb\template\context();

View file

@ -21,7 +21,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
/** @var string */
protected $parent_template_path;
protected function setup_engine(array $new_config = array())
protected function setup_engine(array $new_config = [], string $template_path = '')
{
global $phpbb_root_path, $phpEx, $user;