first commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/doi/DepositIssue.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class DepositIssue
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Job to deposit issue DOI and metadata to the configured registration agency
|
||||
*/
|
||||
|
||||
namespace APP\jobs\doi;
|
||||
|
||||
use APP\facades\Repo;
|
||||
use APP\plugins\IDoiRegistrationAgency;
|
||||
use PKP\context\Context;
|
||||
use PKP\job\exceptions\JobException;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class DepositIssue extends BaseJob
|
||||
{
|
||||
protected int $issueId;
|
||||
|
||||
protected Context $context;
|
||||
|
||||
/**
|
||||
* @var IDoiRegistrationAgency The configured DOI registration agency
|
||||
*/
|
||||
protected IDoiRegistrationAgency $agency;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
*/
|
||||
public function __construct(int $issueId, Context $context, IDoiRegistrationAgency $agency)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->issueId = $issueId;
|
||||
$this->context = $context;
|
||||
$this->agency = $agency;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$issue = Repo::issue()->get($this->issueId);
|
||||
|
||||
if (!$issue || !$this->agency) {
|
||||
throw new JobException(JobException::INVALID_PAYLOAD);
|
||||
}
|
||||
$retResults = $this->agency->depositIssues([$issue], $this->context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/notifications/IssuePublishedMailUsers.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class IssuePublishedNotifyUsers
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Class to send emails when a new issue is published
|
||||
*/
|
||||
|
||||
namespace APP\jobs\notifications;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\facades\Repo;
|
||||
use APP\issue\Issue;
|
||||
use APP\mail\mailables\IssuePublishedNotify;
|
||||
use APP\notification\Notification;
|
||||
use APP\notification\NotificationManager;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PKP\context\Context;
|
||||
use PKP\emailTemplate\EmailTemplate;
|
||||
use PKP\jobs\BaseJob;
|
||||
use PKP\user\User;
|
||||
|
||||
class IssuePublishedNotifyUsers extends BaseJob
|
||||
{
|
||||
use Batchable;
|
||||
|
||||
protected Collection $recipientIds;
|
||||
protected int $contextId;
|
||||
protected Issue $issue;
|
||||
protected string $locale;
|
||||
|
||||
// The sender of the email
|
||||
protected ?User $sender;
|
||||
|
||||
public function __construct(
|
||||
Collection $recipientIds,
|
||||
int $contextId,
|
||||
Issue $issue,
|
||||
string $locale,
|
||||
?User $sender = null // Leave null to not send an email
|
||||
) {
|
||||
parent::__construct();
|
||||
|
||||
$this->recipientIds = $recipientIds;
|
||||
$this->contextId = $contextId;
|
||||
$this->issue = $issue;
|
||||
$this->locale = $locale;
|
||||
$this->sender = $sender;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$context = Application::getContextDAO()->getById($this->contextId);
|
||||
$template = Repo::emailTemplate()->getByKey($this->contextId, IssuePublishedNotify::getEmailTemplateKey());
|
||||
|
||||
foreach ($this->recipientIds as $recipientId) {
|
||||
/** @var int $recipientId */
|
||||
$recipient = Repo::user()->get($recipientId);
|
||||
|
||||
if (!$recipient) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notificationManager = new NotificationManager();
|
||||
$notification = $notificationManager->createNotification(
|
||||
null,
|
||||
$recipientId,
|
||||
Notification::NOTIFICATION_TYPE_PUBLISHED_ISSUE,
|
||||
$this->contextId,
|
||||
Application::ASSOC_TYPE_ISSUE,
|
||||
$this->issue->getId()
|
||||
);
|
||||
|
||||
if (!$this->sender) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mailable = $this->createMailable($context, $this->issue, $recipient, $template, $notification);
|
||||
$mailable->setData($this->locale);
|
||||
Mail::send($mailable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new issue published notification email
|
||||
*/
|
||||
protected function createMailable(
|
||||
Context $context,
|
||||
Issue $issue,
|
||||
User $recipient,
|
||||
EmailTemplate $template,
|
||||
Notification $notification
|
||||
): IssuePublishedNotify {
|
||||
$mailable = new IssuePublishedNotify($context, $issue);
|
||||
$mailable
|
||||
->recipients([$recipient])
|
||||
->sender($this->sender)
|
||||
->body($template->getLocalizedData('body', $this->locale))
|
||||
->subject($template->getLocalizedData('subject', $this->locale))
|
||||
->allowUnsubscribe($notification);
|
||||
|
||||
return $mailable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/notifications/OpenAccessMailUsers.php
|
||||
*
|
||||
* Copyright (c) 2014-2022 Simon Fraser University
|
||||
* Copyright (c) 2000-2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class OpenAccessMailUsers
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Class to send issue open access notification to userIds
|
||||
*/
|
||||
|
||||
namespace APP\jobs\notifications;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\facades\Repo;
|
||||
use APP\journal\Journal;
|
||||
use APP\mail\mailables\OpenAccessNotify;
|
||||
use APP\notification\Notification;
|
||||
use APP\notification\NotificationManager;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class OpenAccessMailUsers extends BaseJob
|
||||
{
|
||||
use Batchable;
|
||||
|
||||
protected Collection $userIds;
|
||||
protected int $contextId;
|
||||
protected int $issueId;
|
||||
|
||||
public function __construct(Collection $userIds, int $contextId, int $issueId)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->userIds = $userIds;
|
||||
$this->contextId = $contextId;
|
||||
$this->issueId = $issueId;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$contextDao = Application::getContextDAO();
|
||||
$context = $contextDao->getById($this->contextId); /** @var Journal $context */
|
||||
$issue = Repo::issue()->get($this->issueId, $this->contextId);
|
||||
|
||||
if (!$context || !$issue) {
|
||||
return;
|
||||
}
|
||||
|
||||
$locale = $context->getPrimaryLocale();
|
||||
$template = Repo::emailTemplate()->getByKey($this->contextId, OpenAccessNotify::getEmailTemplateKey());
|
||||
|
||||
foreach ($this->userIds as $userId) {
|
||||
$user = Repo::user()->get($userId);
|
||||
if (!$user) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notificationManager = new NotificationManager();
|
||||
$notification = $notificationManager->createNotification(
|
||||
null,
|
||||
$userId,
|
||||
Notification::NOTIFICATION_TYPE_OPEN_ACCESS,
|
||||
$this->contextId
|
||||
);
|
||||
|
||||
$mailable = new OpenAccessNotify($context, $issue);
|
||||
$mailable
|
||||
->subject($template->getLocalizedData('subject', $locale))
|
||||
->body($template->getLocalizedData('body', $locale))
|
||||
->from($context->getData('contactEmail'), $context->getData('contactName'))
|
||||
->recipients([$user])
|
||||
->allowUnsubscribe($notification);
|
||||
|
||||
Mail::send($mailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileCounterSubmissionDailyMetrics.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileCounterSubmissionDailyMetrics
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile COUNTER submission daily metrics.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileCounterSubmissionDailyMetrics extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
|
||||
$temporaryTotalsDao->deleteCounterSubmissionDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
$temporaryItemRequestsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileCounterSubmissionInstitutionDailyMetrics.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileCounterSubmissionInstitutionDailyMetrics
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile COUNTER submission institution daily metrics.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileCounterSubmissionInstitutionDailyMetrics extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
|
||||
$temporaryTotalsDao->deleteCounterSubmissionInstitutionDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
$temporaryItemRequestsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileIssueMetrics.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileIssueMetrics
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile issue metrics.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileIssueMetrics extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryTotalsDao->compileIssueMetrics($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileSubmissionGeoDailyMetrics.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileSubmissionGeoDailyMetrics
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile submission Geo daily metrics.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileSubmissionGeoDailyMetrics extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
|
||||
// Geo database only contains total and unique investigations (no extra requests differentiation)
|
||||
$temporaryTotalsDao->deleteSubmissionGeoDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileSubmissionGeoDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileSubmissionGeoDailyMetrics($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileUniqueInvestigations.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileUniqueInvestigations
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Remove unique investigations according to COUNTER guidelines.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileUniqueInvestigations extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemInvestigationsDao->compileUniqueClicks($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileUniqueRequests.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileUniqueRequests
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile unique requests according to COUNTER guidelines.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
|
||||
class CompileUniqueRequests extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
$temporaryItemRequestsDao->compileUniqueClicks($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/CompileUsageStatsFromTemporaryRecords.php
|
||||
*
|
||||
* Copyright (c) 2022 Simon Fraser University
|
||||
* Copyright (c) 2022 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompileUsageStatsFromTemporaryRecords
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile the temporary usage stats and store them in the metrics table.
|
||||
*
|
||||
* @deprecated 3.4.0.5
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\StatisticsHelper;
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\job\exceptions\JobException;
|
||||
use PKP\jobs\BaseJob;
|
||||
use PKP\statistics\TemporaryInstitutionsDAO;
|
||||
use PKP\task\FileLoader;
|
||||
|
||||
class CompileUsageStatsFromTemporaryRecords extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$compileSuccessful = $this->compileMetrics();
|
||||
if (!$compileSuccessful) {
|
||||
// Move the archived file back to staging
|
||||
$filename = $this->loadId;
|
||||
$archivedFilePath = StatisticsHelper::getUsageStatsDirPath() . '/' . FileLoader::FILE_LOADER_PATH_ARCHIVE . '/' . $filename;
|
||||
if (!file_exists($archivedFilePath)) {
|
||||
$filename .= '.gz';
|
||||
$archivedFilePath = StatisticsHelper::getUsageStatsDirPath() . '/' . FileLoader::FILE_LOADER_PATH_ARCHIVE . '/' . $filename;
|
||||
}
|
||||
$stagingPath = StatisticsHelper::getUsageStatsDirPath() . '/' . FileLoader::FILE_LOADER_PATH_STAGING . '/' . $filename;
|
||||
|
||||
if (!rename($archivedFilePath, $stagingPath)) {
|
||||
$message = __('admin.job.compileMetrics.returnToStaging.error', ['file' => $filename,
|
||||
'archivedFilePath' => $archivedFilePath, 'stagingPath' => $stagingPath]);
|
||||
} else {
|
||||
$message = __('admin.job.compileMetrics.error', ['file' => $filename]);
|
||||
}
|
||||
|
||||
throw new JobException($message);
|
||||
}
|
||||
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
$temporaryInstitutionDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /** @var TemporaryInstitutionsDAO $temporaryInstitutionDao */
|
||||
|
||||
$temporaryTotalsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemInvestigationsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemRequestsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryInstitutionDao->deleteByLoadId($this->loadId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the entries inside the temporary database associated with
|
||||
* the passed load id to the metrics tables.
|
||||
*/
|
||||
protected function compileMetrics(): bool
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
|
||||
$temporaryTotalsDao->removeDoubleClicks($this->loadId, StatisticsHelper::COUNTER_DOUBLE_CLICK_TIME_FILTER_SECONDS);
|
||||
$temporaryItemInvestigationsDao->compileUniqueClicks($this->loadId);
|
||||
$temporaryItemRequestsDao->compileUniqueClicks($this->loadId);
|
||||
|
||||
$temporaryTotalsDao->compileContextMetrics($this->loadId);
|
||||
$temporaryTotalsDao->compileIssueMetrics($this->loadId);
|
||||
$temporaryTotalsDao->compileSubmissionMetrics($this->loadId);
|
||||
|
||||
// Geo database only contains total and unique investigations (no extra requests differentiation)
|
||||
$temporaryTotalsDao->deleteSubmissionGeoDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileSubmissionGeoDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileSubmissionGeoDailyMetrics($this->loadId);
|
||||
|
||||
$temporaryTotalsDao->deleteCounterSubmissionDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
$temporaryItemRequestsDao->compileCounterSubmissionDailyMetrics($this->loadId);
|
||||
|
||||
$temporaryTotalsDao->deleteCounterSubmissionInstitutionDailyByLoadId($this->loadId); // always call first, before loading the data
|
||||
$temporaryTotalsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
$temporaryItemInvestigationsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
$temporaryItemRequestsDao->compileCounterSubmissionInstitutionDailyMetrics($this->loadId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/DeleteUsageStatsTemporaryRecords.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class DeleteUsageStatsTemporaryRecords
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile the temporary usage stats and store them in the metrics table.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\BaseJob;
|
||||
use PKP\statistics\TemporaryInstitutionsDAO;
|
||||
|
||||
class DeleteUsageStatsTemporaryRecords extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $loadId Usage stats log file name
|
||||
*/
|
||||
public function __construct(protected string $loadId)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
$temporaryInstitutionDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /** @var TemporaryInstitutionsDAO $temporaryInstitutionDao */
|
||||
|
||||
$temporaryTotalsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemInvestigationsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemRequestsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryInstitutionDao->deleteByLoadId($this->loadId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file jobs/statistics/ProcessUsageStatsLogFile.php
|
||||
*
|
||||
* Copyright (c) 2024 Simon Fraser University
|
||||
* Copyright (c) 2024 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ProcessUsageStatsLogFile
|
||||
*
|
||||
* @ingroup jobs
|
||||
*
|
||||
* @brief Compile context metrics.
|
||||
*/
|
||||
|
||||
namespace APP\jobs\statistics;
|
||||
|
||||
use APP\core\Application;
|
||||
use APP\statistics\TemporaryItemInvestigationsDAO;
|
||||
use APP\statistics\TemporaryItemRequestsDAO;
|
||||
use APP\statistics\TemporaryTotalsDAO;
|
||||
use Exception;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\jobs\statistics\PKPProcessUsageStatsLogFile;
|
||||
use PKP\statistics\TemporaryInstitutionsDAO;
|
||||
|
||||
class ProcessUsageStatsLogFile extends PKPProcessUsageStatsLogFile
|
||||
{
|
||||
protected function deleteByLoadId(): void
|
||||
{
|
||||
$temporaryInstitutionsDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /** @var TemporaryInstitutionsDAO $temporaryInstitutionsDao */
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
|
||||
$temporaryInstitutionsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryTotalsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemInvestigationsDao->deleteByLoadId($this->loadId);
|
||||
$temporaryItemRequestsDao->deleteByLoadId($this->loadId);
|
||||
}
|
||||
|
||||
protected function validateLogEntry(object $entry): void
|
||||
{
|
||||
parent::validateLogEntry($entry);
|
||||
if (!empty($entry->issueId) && !is_int($entry->issueId)) {
|
||||
throw new Exception(__('admin.job.processLogFile.invalidLogEntry.issueId'));
|
||||
}
|
||||
if (!empty($entry->issueGalleyId) && !is_int($entry->issueGalleyId)) {
|
||||
throw new Exception(__('admin.job.processLogFile.invalidLogEntry.issueGalleyId'));
|
||||
}
|
||||
}
|
||||
|
||||
protected function getValidAssocTypes(): array
|
||||
{
|
||||
return [
|
||||
Application::ASSOC_TYPE_SUBMISSION_FILE,
|
||||
Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER,
|
||||
Application::ASSOC_TYPE_SUBMISSION,
|
||||
Application::ASSOC_TYPE_ISSUE_GALLEY,
|
||||
Application::ASSOC_TYPE_ISSUE,
|
||||
Application::ASSOC_TYPE_JOURNAL,
|
||||
];
|
||||
}
|
||||
|
||||
protected function insertTemporaryUsageStatsData(object $entry, int $lineNumber): void
|
||||
{
|
||||
$temporaryInstitutionsDao = DAORegistry::getDAO('TemporaryInstitutionsDAO'); /** @var TemporaryInstitutionsDAO $temporaryInstitutionsDao */
|
||||
$temporaryTotalsDao = DAORegistry::getDAO('TemporaryTotalsDAO'); /** @var TemporaryTotalsDAO $temporaryTotalsDao */
|
||||
$temporaryItemInvestigationsDao = DAORegistry::getDAO('TemporaryItemInvestigationsDAO'); /** @var TemporaryItemInvestigationsDAO $temporaryItemInvestigationsDao */
|
||||
$temporaryItemRequestsDao = DAORegistry::getDAO('TemporaryItemRequestsDAO'); /** @var TemporaryItemRequestsDAO $temporaryItemRequestsDao */
|
||||
|
||||
try {
|
||||
$temporaryTotalsDao->insert($entry, $lineNumber, $this->loadId);
|
||||
$temporaryInstitutionsDao->insert($entry->institutionIds, $lineNumber, $this->loadId);
|
||||
if (!empty($entry->submissionId)) {
|
||||
$temporaryItemInvestigationsDao->insert($entry, $lineNumber, $this->loadId);
|
||||
if ($entry->assocType == Application::ASSOC_TYPE_SUBMISSION_FILE) {
|
||||
$temporaryItemRequestsDao->insert($entry, $lineNumber, $this->loadId);
|
||||
}
|
||||
}
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
$message = __(
|
||||
'admin.job.processLogFile.insertError',
|
||||
['file' => $this->loadId, 'lineNumber' => $lineNumber, 'msg' => $e->getMessage()]
|
||||
);
|
||||
error_log($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user