mirror of
https://github.com/Karaka-Management/oms-OnlineResourceWatcher.git
synced 2026-02-15 15:38:40 +00:00
phpstan, phpcs, phpunit fixes
This commit is contained in:
parent
8f7b0eb7c4
commit
7d72ca7800
|
|
@ -15,21 +15,21 @@ declare(strict_types=1);
|
||||||
namespace Modules\OnlineResourceWatcher\Controller;
|
namespace Modules\OnlineResourceWatcher\Controller;
|
||||||
|
|
||||||
use Modules\Admin\Models\NullAccount;
|
use Modules\Admin\Models\NullAccount;
|
||||||
|
use Modules\OnlineResourceWatcher\Models\Report;
|
||||||
|
use Modules\OnlineResourceWatcher\Models\ReportMapper;
|
||||||
|
use Modules\OnlineResourceWatcher\Models\ReportStatus;
|
||||||
use Modules\OnlineResourceWatcher\Models\Resource;
|
use Modules\OnlineResourceWatcher\Models\Resource;
|
||||||
use Modules\OnlineResourceWatcher\Models\ResourceMapper;
|
use Modules\OnlineResourceWatcher\Models\ResourceMapper;
|
||||||
use Modules\OnlineResourceWatcher\Models\Report;
|
|
||||||
use Modules\OnlineResourceWatcher\Models\ReportStatus;
|
|
||||||
use Modules\OnlineResourceWatcher\Models\ReportMapper;
|
|
||||||
use Modules\OnlineResourceWatcher\Models\ResourceStatus;
|
use Modules\OnlineResourceWatcher\Models\ResourceStatus;
|
||||||
use phpOMS\Message\Http\RequestStatusCode;
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
use phpOMS\Message\NotificationLevel;
|
use phpOMS\Message\NotificationLevel;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Model\Message\FormValidation;
|
use phpOMS\Model\Message\FormValidation;
|
||||||
use phpOMS\System\SystemUtils;
|
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\Utils\StringUtils;
|
use phpOMS\System\SystemUtils;
|
||||||
use phpOMS\Utils\ImageUtils;
|
use phpOMS\Utils\ImageUtils;
|
||||||
|
use phpOMS\Utils\StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OnlineResourceWatcher controller class.
|
* OnlineResourceWatcher controller class.
|
||||||
|
|
@ -132,6 +132,7 @@ final class ApiController extends Controller
|
||||||
*/
|
*/
|
||||||
public function apiCheckResources(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
public function apiCheckResources(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||||
{
|
{
|
||||||
|
/** @var Resource[] $resources */
|
||||||
$resources = ResourceMapper::getAll()
|
$resources = ResourceMapper::getAll()
|
||||||
->where('status', ResourceStatus::ACTIVE)
|
->where('status', ResourceStatus::ACTIVE)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
@ -182,7 +183,7 @@ final class ApiController extends Controller
|
||||||
$report = new Report();
|
$report = new Report();
|
||||||
$report->resource = $resource->getId();
|
$report->resource = $resource->getId();
|
||||||
$report->versionPath = (string) $check['timestamp'];
|
$report->versionPath = (string) $check['timestamp'];
|
||||||
$report->status = ReportStatus::DOWNLOAD_ERROR;
|
$report->status = ReportStatus::DOWNLOAD_ERROR;
|
||||||
|
|
||||||
ReportMapper::create()->execute($report);
|
ReportMapper::create()->execute($report);
|
||||||
|
|
||||||
|
|
@ -206,9 +207,12 @@ final class ApiController extends Controller
|
||||||
// new resource
|
// new resource
|
||||||
if ($check['loop'] === 60 * 10 && !\is_dir($basePath . '/' . $id)) {
|
if ($check['loop'] === 60 * 10 && !\is_dir($basePath . '/' . $id)) {
|
||||||
$filesNew = \scandir($path);
|
$filesNew = \scandir($path);
|
||||||
|
if ($filesNew === false) {
|
||||||
|
$filesNew = [];
|
||||||
|
}
|
||||||
|
|
||||||
$fileName = '';
|
$fileName = '';
|
||||||
if (in_array('index.htm', $filesNew) || \in_array('index.html', $filesNew)) {
|
if (\in_array('index.htm', $filesNew) || \in_array('index.html', $filesNew)) {
|
||||||
$fileName = \in_array('index.htm', $filesNew) ? 'index.htm' : 'index.html';
|
$fileName = \in_array('index.htm', $filesNew) ? 'index.htm' : 'index.html';
|
||||||
} else {
|
} else {
|
||||||
foreach ($filesNew as $file) {
|
foreach ($filesNew as $file) {
|
||||||
|
|
@ -248,7 +252,7 @@ final class ApiController extends Controller
|
||||||
$resource->lastVersionPath = (string) $check['timestamp'];
|
$resource->lastVersionPath = (string) $check['timestamp'];
|
||||||
$resource->lastVersionDate = $report->createdAt;
|
$resource->lastVersionDate = $report->createdAt;
|
||||||
$resource->hash = $hash;
|
$resource->hash = $hash;
|
||||||
$resource->checkedAt = $report->createdAt;
|
$resource->checkedAt = $report->createdAt;
|
||||||
ResourceMapper::update()->execute($resource);
|
ResourceMapper::update()->execute($resource);
|
||||||
|
|
||||||
Directory::copy($path, $basePath . '/' . $id . '/' . $check['timestamp']);
|
Directory::copy($path, $basePath . '/' . $id . '/' . $check['timestamp']);
|
||||||
|
|
@ -263,13 +267,17 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
// existing resource
|
// existing resource
|
||||||
$resourcePaths = \scandir($basePath . '/' . $id);
|
$resourcePaths = \scandir($basePath . '/' . $id);
|
||||||
|
if ($resourcePaths === false) {
|
||||||
|
$resourcePaths = [];
|
||||||
|
}
|
||||||
|
|
||||||
\natsort($resourcePaths);
|
\natsort($resourcePaths);
|
||||||
|
|
||||||
$lastVersionTimestamp = \end($resourcePaths);
|
$lastVersionTimestamp = \end($resourcePaths);
|
||||||
if ($lastVersionTimestamp === '.' && $lastVersionTimestamp === '..') {
|
if ($lastVersionTimestamp === '.' || $lastVersionTimestamp === '..') {
|
||||||
$lastVersionTimestamp = \reset($resourcePaths);
|
$lastVersionTimestamp = \reset($resourcePaths);
|
||||||
|
|
||||||
if ($lastVersionTimestamp === '.' && $lastVersionTimestamp === '..') {
|
if ($lastVersionTimestamp === '.' || $lastVersionTimestamp === '..') {
|
||||||
Directory::delete($basePath . '/' . $id);
|
Directory::delete($basePath . '/' . $id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,9 +285,15 @@ final class ApiController extends Controller
|
||||||
$lastVersionPath = $basePath . '/' . $id . '/' . $lastVersionTimestamp;
|
$lastVersionPath = $basePath . '/' . $id . '/' . $lastVersionTimestamp;
|
||||||
|
|
||||||
$filesNew = \scandir($path);
|
$filesNew = \scandir($path);
|
||||||
|
if ($filesNew === false) {
|
||||||
|
$filesNew = [];
|
||||||
|
}
|
||||||
|
|
||||||
// Using this because the index.htm gets created last and at the time of the check below it may not yet exist.
|
// Using this because the index.htm gets created last and at the time of the check below it may not yet exist.
|
||||||
$filesOld = \scandir($lastVersionPath);
|
$filesOld = \scandir($lastVersionPath);
|
||||||
|
if ($filesOld === false) {
|
||||||
|
$filesOld = [];
|
||||||
|
}
|
||||||
|
|
||||||
$oldPath = '';
|
$oldPath = '';
|
||||||
$newPath = '';
|
$newPath = '';
|
||||||
|
|
@ -322,8 +336,13 @@ final class ApiController extends Controller
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$md5Old = $resource->hash;
|
$md5Old = $resource->hash;
|
||||||
$md5New = \md5_file($newPath);
|
$md5New = \md5_file($newPath);
|
||||||
|
|
||||||
|
if ($md5New === false) {
|
||||||
|
$md5New = '';
|
||||||
|
}
|
||||||
|
|
||||||
$hasDifferentHash = $md5Old !== $md5New;
|
$hasDifferentHash = $md5Old !== $md5New;
|
||||||
|
|
||||||
// @todo: check if old path exists and if not, don't calculate a diff
|
// @todo: check if old path exists and if not, don't calculate a diff
|
||||||
|
|
@ -331,12 +350,12 @@ final class ApiController extends Controller
|
||||||
$difference = 0;
|
$difference = 0;
|
||||||
if ($hasDifferentHash) {
|
if ($hasDifferentHash) {
|
||||||
if (\in_array($extension, ['md', 'txt', 'doc', 'docx', 'pdf', 'xls', 'xlsx'])) {
|
if (\in_array($extension, ['md', 'txt', 'doc', 'docx', 'pdf', 'xls', 'xlsx'])) {
|
||||||
$contentOld = \Modules\Media\Controller\ApiController::loadFileContent($oldPath);
|
$contentOld = \Modules\Media\Controller\ApiController::loadFileContent($oldPath, $extension);
|
||||||
$contentNew = \Modules\Media\Controller\ApiController::loadFileContent($newPath);
|
$contentNew = \Modules\Media\Controller\ApiController::loadFileContent($newPath, $extension);
|
||||||
|
|
||||||
$difference = \levenshtein($contentOld, $contentNew);
|
$difference = \levenshtein($contentOld, $contentNew);
|
||||||
} elseif (\in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) {
|
} elseif (\in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) {
|
||||||
$difference = ImageUtils::difference($oldPath, $newPath, $path . '/_' . $file, 0);
|
$difference = ImageUtils::difference($oldPath, $newPath, $path . '/_' . \basename($newPath), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ final class ResourceMapper extends DataMapperFactory
|
||||||
/**
|
/**
|
||||||
* Belongs to.
|
* Belongs to.
|
||||||
*
|
*
|
||||||
* @var array<string, array{mapper:string, external:string, column?:string, by?:string}>
|
* @var array<string, array{mapper:class-string, external:string, column?:string, by?:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const BELONGS_TO = [
|
public const BELONGS_TO = [
|
||||||
|
|
|
||||||
17
Theme/Backend/Lang/Navigation.de.lang.php
Normal file
17
Theme/Backend/Lang/Navigation.de.lang.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Karaka
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\Localization
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
return ['Navigation' => [
|
||||||
|
'OnlineResourceWatcher' => 'Online Resource Watcher',
|
||||||
|
]];
|
||||||
86
Theme/Backend/Lang/de.lang.php
Executable file
86
Theme/Backend/Lang/de.lang.php
Executable file
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Karaka
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\OnlineResourceWatcher
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
return [[
|
||||||
|
'Action' => 'Action',
|
||||||
|
'Add' => 'Add',
|
||||||
|
'Admin' => 'Admin',
|
||||||
|
'Back' => 'Back',
|
||||||
|
'Bills' => 'Bills',
|
||||||
|
'By' => 'By',
|
||||||
|
'Cancel' => 'Cancel',
|
||||||
|
'Checked' => 'Checked',
|
||||||
|
'Dashboard' => 'Dashboard',
|
||||||
|
'Date' => 'Date',
|
||||||
|
'Filter' => 'Filter',
|
||||||
|
'ForgotPassword' => 'Forgot Password',
|
||||||
|
'Home' => 'Home',
|
||||||
|
'ID' => 'ID',
|
||||||
|
'Imprint' => 'Imprint',
|
||||||
|
'Legal' => 'Legal',
|
||||||
|
'Log' => 'Log',
|
||||||
|
'Logo' => 'Logo',
|
||||||
|
'SignOut' => 'Sign Out',
|
||||||
|
'Logs' => 'Logs',
|
||||||
|
'Organization' => 'Organization',
|
||||||
|
'Organizations' => 'Organizations',
|
||||||
|
'Password' => 'Password',
|
||||||
|
'PrivacyPolicy' => 'Privacy Policy',
|
||||||
|
'Ref' => 'Ref',
|
||||||
|
'Report' => 'Report',
|
||||||
|
'Reports' => 'Reports',
|
||||||
|
'Reset' => 'Reset',
|
||||||
|
'Resource' => 'Resource',
|
||||||
|
'Resources' => 'Resources',
|
||||||
|
'Create' => 'Create',
|
||||||
|
'Delete' => 'Delete',
|
||||||
|
'Suspend' => 'Suspend',
|
||||||
|
'Send' => 'Send',
|
||||||
|
'Save' => 'Save',
|
||||||
|
'Search' => 'Search',
|
||||||
|
'Settings' => 'Settings',
|
||||||
|
'SignIn' => 'Sign In',
|
||||||
|
'Status' => 'Status',
|
||||||
|
'Submit' => 'Submit',
|
||||||
|
'Terms' => 'Terms',
|
||||||
|
'Trigger' => 'Trigger',
|
||||||
|
'Type' => 'Type',
|
||||||
|
'User' => 'User',
|
||||||
|
'Username' => 'Username',
|
||||||
|
'Users' => 'Users',
|
||||||
|
'New' => 'New',
|
||||||
|
'Number' => 'Number',
|
||||||
|
'CustomerNo' => 'Customer No.',
|
||||||
|
'CustomerName' => 'Customer Name',
|
||||||
|
'Amount' => 'Amount',
|
||||||
|
'Members' => 'Members',
|
||||||
|
'Name' => 'Name',
|
||||||
|
'Active' => 'Active',
|
||||||
|
'Address' => 'Address',
|
||||||
|
'Postal' => 'Postal',
|
||||||
|
'City' => 'City',
|
||||||
|
'BillingEmail' => 'Billing Email',
|
||||||
|
'Statistics' => 'Statistics',
|
||||||
|
'PlanSettings' => 'Plan Settings',
|
||||||
|
'BillingSettings' => 'Billing Settings',
|
||||||
|
'UserSettings' => 'User Settings',
|
||||||
|
'Login' => 'Login',
|
||||||
|
'Email' => 'Email',
|
||||||
|
'NewPassword' => 'New Password',
|
||||||
|
'CreateResource' => 'Create Resource',
|
||||||
|
'Inform' => 'Inform',
|
||||||
|
'Element' => 'Element',
|
||||||
|
'Exit' => 'Exit',
|
||||||
|
'Url' => 'Url',
|
||||||
|
]];
|
||||||
Loading…
Reference in New Issue
Block a user