Skip to content

Commit 5dfcaa7

Browse files
author
github-actions
committed
Merge branch 'release-15.25.0'
2 parents e004a75 + 686287d commit 5dfcaa7

File tree

5 files changed

+198
-3
lines changed

5 files changed

+198
-3
lines changed

common/persistence/PersistenceManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ private function createPersistence($persistenceId)
131131
$config = $configs[$persistenceId];
132132
$driverString = $config['driver'];
133133

134-
$driverClassName = isset(self::DRIVER_MAP[$driverString]) ? self::DRIVER_MAP[$driverString] : $driverString;
134+
$driverClassName = self::DRIVER_MAP[$driverString] ?? (string)$driverString;
135135

136136
if (!class_exists($driverClassName)) {
137137
throw new \common_exception_Error(
138-
'Driver ' . $driverString . ' not found, check your database configuration'
138+
sprintf(
139+
'Driver "%s" not found, check your database configuration for %s.',
140+
$driverString,
141+
$persistenceId
142+
)
139143
);
140144
}
141145

core/data/event/CacheWarmupEvent.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2023(original work) Open Assessment Technologies SA;
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\generis\model\data\event;
24+
25+
use oat\oatbox\event\Event;
26+
use oat\oatbox\reporting\Report;
27+
28+
class CacheWarmupEvent implements Event
29+
{
30+
/**
31+
* @return Report[]
32+
*/
33+
private array $reports = [];
34+
35+
public function getName(): string
36+
{
37+
return self::class;
38+
}
39+
40+
public function addReport(Report $report): self
41+
{
42+
$this->reports[] = $report;
43+
44+
return $this;
45+
}
46+
47+
/**
48+
* @return Report[]
49+
*/
50+
public function getReports(): array
51+
{
52+
return $this->reports;
53+
}
54+
}

helpers/class.PhpTools.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ class helpers_PhpTools
3636
*/
3737
public static function getClassInfo($file)
3838
{
39+
$namespaceToken = PHP_VERSION_ID < 80000 ? T_STRING : T_NAME_QUALIFIED;
40+
3941
$buffer = file_get_contents($file);
4042
$tokens = @token_get_all($buffer);
4143
$class = $namespace = $buffer = '';
4244
for ($i = 0; $i < count($tokens); $i++) {
4345
if ($tokens[$i][0] === T_NAMESPACE) {
4446
for ($j = $i + 1; $j < count($tokens); $j++) {
45-
if ($tokens[$j][0] === T_STRING) {
47+
if ($tokens[$j][0] === $namespaceToken) {
4648
$namespace .= '\\' . $tokens[$j][1];
4749
} elseif ($tokens[$j] === '{' || $tokens[$j] === ';') {
4850
break;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2023 (original work) Open Assessment Technologies SA;
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\generis\scripts\tools;
24+
25+
use oat\generis\model\data\event\CacheWarmupEvent;
26+
use oat\oatbox\cache\SimpleCache;
27+
use oat\oatbox\event\EventManager;
28+
use oat\oatbox\extension\script\ScriptAction;
29+
use oat\oatbox\reporting\Report;
30+
31+
/**
32+
* php index.php 'oat\generis\scripts\tools\ApplicationCacheWarmup' --clear
33+
*/
34+
class ApplicationCacheWarmup extends ScriptAction
35+
{
36+
protected function showTime()
37+
{
38+
return true;
39+
}
40+
41+
protected function provideUsage(): array
42+
{
43+
return [
44+
'prefix' => 'h',
45+
'longPrefix' => 'help',
46+
'description' => 'Warmup TAO Cache',
47+
];
48+
}
49+
50+
protected function provideOptions(): array
51+
{
52+
return [
53+
'clear' => [
54+
'prefix' => 'c',
55+
'longPrefix' => 'clear',
56+
'flag' => true,
57+
'description' => 'Clear cache before warm it up.',
58+
'defaultValue' => false,
59+
],
60+
];
61+
}
62+
63+
protected function provideDescription(): string
64+
{
65+
return 'Warmup TAO Cache';
66+
}
67+
68+
protected function run(): Report
69+
{
70+
$reports = [];
71+
72+
$clearCache = (bool)$this->getOption('clear');
73+
if ($clearCache) {
74+
$this->getServiceLocator()->get(SimpleCache::SERVICE_ID)->clear();
75+
$reports[] = Report::createInfo('Cache was cleared.');
76+
}
77+
78+
try {
79+
$cacheWarmupEvent = new CacheWarmupEvent();
80+
/** @var EventManager $eventManager */
81+
$eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID);
82+
$eventManager->trigger($cacheWarmupEvent);
83+
84+
$reports = array_merge($reports, $cacheWarmupEvent->getReports());
85+
} catch (\Throwable $e) {
86+
return Report::createError(sprintf('Cache warmup failed: %s', $e->getMessage()));
87+
}
88+
89+
return Report::createSuccess('TAO cache warmed up!', null, $reports);
90+
}
91+
}

test/unit/helpers/PhpToolsTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2023 (original work) Open Assessment Technologies SA;
19+
*
20+
*/
21+
22+
namespace oat\generis\tests\unit\helpers;
23+
24+
use PHPUnit\Framework\TestCase;
25+
26+
class PhpToolsTest extends TestCase
27+
{
28+
public function testNamespaceAndClass(): void
29+
{
30+
$info = \helpers_PhpTools::getClassInfo(__FILE__);
31+
32+
$this->assertEquals('\oat\generis\tests\unit\helpers', $info['ns'], 'Namespace is wrong.');
33+
$this->assertEquals('PhpToolsTest', $info['class'], 'Class is wrong.');
34+
}
35+
36+
public function testNamespaceAndClassLegacy(): void
37+
{
38+
$reflectionHelper = new \ReflectionClass(\helpers_PhpTools::class);
39+
$info = \helpers_PhpTools::getClassInfo($reflectionHelper->getFileName());
40+
41+
$this->assertEquals('', $info['ns'], 'Namespace is wrong.');
42+
$this->assertEquals('helpers_PhpTools', $info['class'], 'Class is wrong.');
43+
}
44+
}

0 commit comments

Comments
 (0)