mirror of
https://github.com/Karaka-Management/oms-OnlineResourceWatcher.git
synced 2026-01-11 16:08:41 +00:00
backup
This commit is contained in:
parent
7264b09cd2
commit
c061d367e4
|
|
@ -34,7 +34,9 @@ use phpOMS\Message\NotificationLevel;
|
|||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
use phpOMS\System\File\FileUtils;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
use phpOMS\System\MimeType;
|
||||
use phpOMS\System\OperatingSystem;
|
||||
use phpOMS\System\SystemType;
|
||||
use phpOMS\System\SystemUtils;
|
||||
|
|
@ -74,6 +76,12 @@ final class ApiController extends Controller
|
|||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
if ($request->hasData('path')) {
|
||||
// @todo: check if user has permission?
|
||||
$this->app->moduleManager->get('Media', 'Api')->apiMediaExport($request, $response, ['guard' => __DIR__ . '/../Files']);
|
||||
return;
|
||||
}
|
||||
|
||||
$path = '';
|
||||
$basePath = __DIR__ . '/../Files/' . $resource->path . '/' . $resource->lastVersionPath;
|
||||
|
||||
|
|
@ -124,7 +132,9 @@ final class ApiController extends Controller
|
|||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['uri'] = (!$request->hasData('uri') || \filter_var($request->getDataString('uri'), \FILTER_VALIDATE_URL) === false))
|
||||
|| ($val['uri'] = (!$request->hasData('uri')
|
||||
|| (\filter_var($request->getDataString('uri'), \FILTER_VALIDATE_URL) === false && \stripos($request->getDataString('uri'), 'www.') !== 0))
|
||||
)
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
|
@ -330,7 +340,7 @@ final class ApiController extends Controller
|
|||
$totalCount = \count($toCheck);
|
||||
$maxLoops = (int) \min(60 * 10, $totalCount * 10 / 4); // At most run 600 times or 2.5 times the resource count
|
||||
$startTime = \time();
|
||||
$minTime = $startTime + ((int) \max(10 * $totalCount, 60 * 5)); // At least run 10 seconds per element or 5 minutes
|
||||
$minTime = $startTime + ((int) \max(10 * $totalCount, 60)); // At least run 10 seconds per element or 5 minutes
|
||||
$maxTime = $startTime + ((int) \min(60 * $totalCount, 60 * 60 * 3)); // At most run 60 seconds per element or 3 hours
|
||||
|
||||
while (!empty($toCheck)) {
|
||||
|
|
@ -404,7 +414,20 @@ final class ApiController extends Controller
|
|||
continue;
|
||||
}
|
||||
|
||||
$extension = ($pos = \strrpos($file, '.')) !== false ? \substr($file, $pos + 1) : '';
|
||||
$extension = ($pos = \strrpos($file, '.')) !== false ? \substr($file, $pos + 1) : '';
|
||||
$possibleExtension = MimeType::mimeToExtension(\mime_content_type($path . '/' . $file));
|
||||
|
||||
$newFileName = FileUtils::makeSafeFileName($file);
|
||||
if ($possibleExtension !== null && $possibleExtension !== $extension) {
|
||||
$extension = $possibleExtension;
|
||||
$newFileName .= '.' . $extension;
|
||||
}
|
||||
|
||||
if ($file !== $newFileName) {
|
||||
\rename($path . '/' . $file, $path . '/' . $newFileName);
|
||||
$file = $newFileName;
|
||||
}
|
||||
|
||||
if (StringUtils::endsWith($file, '.' . $extension)) {
|
||||
$fileName = $file;
|
||||
$toCheck[$index]['handled'] = true;
|
||||
|
|
@ -666,10 +689,20 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
// Make sure that no wkhtmltoimage processes are running
|
||||
if (OperatingSystem::getSystem() === SystemType::LINUX) {
|
||||
SystemUtils::runProc('pkill', '-f wkhtmltoimage', true);
|
||||
} else {
|
||||
SystemUtils::runProc('taskkill', '/F /IM wkhtmltoimage.exe', true);
|
||||
$time = \time();
|
||||
if ($time - $minTime < 3) {
|
||||
// The shortest time interval we give the script to download the images
|
||||
\sleep(3);
|
||||
}
|
||||
|
||||
if ($time > $minTime) {
|
||||
// @todo: create a separate function which is called async minTime - time seconds after
|
||||
// This solution is just a workaround for small lists which would otherwise be forced to wait at least 60 seconds.
|
||||
if (OperatingSystem::getSystem() === SystemType::LINUX) {
|
||||
SystemUtils::runProc('pkill', '-f wkhtmltoimage', true);
|
||||
} else {
|
||||
SystemUtils::runProc('taskkill', '/F /IM wkhtmltoimage.exe', true);
|
||||
}
|
||||
}
|
||||
|
||||
Directory::delete($basePath . '/temp');
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ return ['OnlineResourceWatcher' => [
|
|||
'SignIn' => 'Sign In',
|
||||
'Status' => 'Status',
|
||||
'Submit' => 'Submit',
|
||||
'Title' => 'Title',
|
||||
'Terms' => 'Terms',
|
||||
'Trigger' => 'Trigger',
|
||||
'Type' => 'Type',
|
||||
|
|
|
|||
134
Theme/Backend/resource-comparison-inline.tpl.php
Normal file
134
Theme/Backend/resource-comparison-inline.tpl.php
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
use Modules\OnlineResourceWatcher\Models\ReportStatus;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
?>
|
||||
|
||||
<div class="row row-simple">
|
||||
<?php
|
||||
|
||||
$old = \reset($reports);
|
||||
$new = \end($reports);
|
||||
|
||||
$old = null;
|
||||
$new = null;
|
||||
|
||||
foreach ($reports as $report) {
|
||||
if ($report->status === ReportStatus::DOWNLOAD_ERROR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$old = $new;
|
||||
$new = $report;
|
||||
|
||||
if ($old === null) {
|
||||
$old = $report;
|
||||
}
|
||||
}
|
||||
|
||||
if ($resource->checkedAt !== null) :
|
||||
$type = '';
|
||||
|
||||
if ($new !== null) {
|
||||
$newBasePath = __DIR__ . '/../../Files/' . $resource->path . '/' . $new->versionPath;
|
||||
$newWebPath = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $new->versionPath;
|
||||
|
||||
if (\is_file($newBasePath . '/index.jpg')) {
|
||||
$type = 'img';
|
||||
$newWebPath .= '/index.jpg';
|
||||
} else {
|
||||
$files = \scandir($newBasePath);
|
||||
if ($files !== false) {
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newWebPath .= '/' . $file;
|
||||
|
||||
if (\stripos($file, '.jpg') !== false
|
||||
|| \stripos($file, '.jpeg') !== false
|
||||
|| \stripos($file, '.png') !== false
|
||||
|| \stripos($file, '.gif') !== false
|
||||
) {
|
||||
$type = 'img';
|
||||
break;
|
||||
} elseif (\stripos($file, '.pdf') !== false) {
|
||||
$type = 'pdf';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($old !== null) {
|
||||
$oldBasePath = __DIR__ . '/../../Files/' . $resource->path . '/' . $old->versionPath;
|
||||
$oldWebPath = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $old->versionPath;
|
||||
|
||||
if (\is_file($oldBasePath . '/index.jpg')) {
|
||||
$type = 'img';
|
||||
$oldWebPath .= '/index.jpg';
|
||||
} else {
|
||||
$files = \scandir($oldBasePath);
|
||||
if ($files !== false) {
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oldWebPath .= '/' . $file;
|
||||
|
||||
if (\stripos($file, '.jpg') !== false
|
||||
|| \stripos($file, '.jpeg') !== false
|
||||
|| \stripos($file, '.png') !== false
|
||||
|| \stripos($file, '.gif') !== false
|
||||
) {
|
||||
$type = 'img';
|
||||
break;
|
||||
} elseif (\stripos($file, '.pdf') !== false) {
|
||||
$type = 'pdf';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($type === 'img') : ?>
|
||||
<div class="col-xs-12 col-simple">
|
||||
<div class="portlet col-simple">
|
||||
<div class="portlet-body col-simple">
|
||||
<?php
|
||||
if ($old !== null) : ?>
|
||||
<div class="image-comparison">
|
||||
<div>
|
||||
<img src="<?= UriFactory::build($oldWebPath); ?>" alt="<?= $this->printHtml($resource->title); ?>">
|
||||
</div>
|
||||
<img src="<?= UriFactory::build($newWebPath); ?>" alt="<?= $this->printHtml($resource->title); ?>">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php else : ?>
|
||||
<div class="col-xs-6 col-simple">
|
||||
<div class="portlet col-simple">
|
||||
<div class="portlet-body col-simple">
|
||||
<iframe class="col-simple" id="iRenderFrame" src="Resources/mozilla/Pdf/web/viewer.html?file=<?= \urlencode(UriFactory::build('{/api}orw/resource/render?path=' . $oldWebPath)); ?>" loading="lazy" allowfullscreen></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-6 col-simple">
|
||||
<div class="portlet col-simple">
|
||||
<div class="portlet-body col-simple">
|
||||
<iframe class="col-simple" id="iRenderFrame" src="Resources/mozilla/Pdf/web/viewer.html?file=<?= \urlencode(UriFactory::build('{/api}orw/resource/render?path=' . $newWebPath)); ?>" loading="lazy" allowfullscreen></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
|
@ -78,61 +78,4 @@ $reports = $resource->reports;
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row col-simple">
|
||||
<div class="col-xs-12 col-simple">
|
||||
<?php if ($resource->checkedAt !== null) : ?>
|
||||
<div class="portlet col-simple">
|
||||
<div class="portlet-body col-simple">
|
||||
<?php
|
||||
|
||||
$type = '';
|
||||
$basePath = __DIR__ . '/../../Files/' . $resource->path . '/' . $resource->lastVersionPath;
|
||||
$path = '';
|
||||
$webPath = 'Modules/OnlineResourceWatcher/Files/' . $resource->path . '/' . $resource->lastVersionPath;
|
||||
|
||||
if (\is_file($basePath . '/index.jpg')) {
|
||||
$type = 'img';
|
||||
$path = $basePath . '/index.jpg';
|
||||
$webPath .= '/index.jpg';
|
||||
} else {
|
||||
$files = \scandir($basePath);
|
||||
|
||||
if ($files !== false) {
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $files === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $basePath . '/' . $file;
|
||||
$webPath .= '/' . $file;
|
||||
|
||||
if (\stripos($file, '.jpg') !== false
|
||||
|| \stripos($file, '.jpeg') !== false
|
||||
|| \stripos($file, '.png') !== false
|
||||
|| \stripos($file, '.gif') !== false
|
||||
) {
|
||||
$type = 'img';
|
||||
break;
|
||||
} elseif (\stripos($file, '.pdf') !== false) {
|
||||
$type = 'pdf';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($report->status !== ReportStatus::DOWNLOAD_ERROR) : ?>
|
||||
<?php if ($type === 'img') : ?>
|
||||
<img src="<?= UriFactory::build($webPath); ?>" alt="<?= $this->printHtml($resource->title); ?>">
|
||||
<?php elseif ($type === 'pdf') : ?>
|
||||
<iframe class="col-simple" id="iRenderFrame" src="Resources/mozilla/Pdf/web/viewer.html?file=<?= \urlencode($webPath); ?>" loading="lazy" allowfullscreen></iframe>
|
||||
<?php else : ?>
|
||||
<iframe class="col-simple" id="iRenderFrame" src="<?= UriFactory::build('{/api}orw/resource/render?id=' . $resource->id); ?>" loading="lazy" sandbox="allow-forms allow-scripts" allowfullscreen></iframe>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php include __DIR__ . '/resource-comparison-inline.tpl.php';
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ if (\defined('RESET') && RESET === '1') {
|
|||
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
||||
$db->exec('CREATE DATABASE IF NOT EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
||||
$db = null;
|
||||
} catch (\Throwable $t) {
|
||||
} catch (\Throwable $_) {
|
||||
echo "\nCouldn't connect to MYSQL DB\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -317,7 +317,7 @@ if (\defined('RESET') && RESET === '1') {
|
|||
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
||||
$db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
||||
$db = null;
|
||||
} catch (\Throwable $t) {
|
||||
} catch (\Throwable $_) {
|
||||
echo "\nCouldn't connect to POSTGRESQL DB\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ if (\defined('RESET') && RESET === '1') {
|
|||
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['mssql']['admin']['database']);
|
||||
$db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['mssql']['admin']['database']);
|
||||
$db = null;
|
||||
} catch (\Throwable $t) {
|
||||
} catch (\Throwable $_) {
|
||||
echo "\nCouldn't connect to MSSQL DB\n";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user