Skip to content

Commit

Permalink
pkp#9911 changes ofter the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Aug 13, 2024
1 parent 56414c0 commit cabf266
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
22 changes: 12 additions & 10 deletions classes/cliTool/traits/ConvertLogFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ public function convert(string $fileName): void
$context = $this->contextsByPath[$foundContextPath];
$newEntry['contextId'] = $context->getId();

$this->setAssoc($assocType, $page, $op, $args, $newEntry);
// temporarily set the canonicalUrlPage that is needed in the child class
$newEntry['canonicalUrlPage'] = $page;
$this->setAssoc($assocType, $args, $newEntry);
if (!array_key_exists('assocType', $newEntry)) {
if (!$this->isApacheAccessLogFile()) {
fwrite(STDERR, "The URL {$entryData['url']} in the line number {$lineNumber} was not considered." . PHP_EOL);
Expand All @@ -200,10 +202,10 @@ public function convert(string $fileName): void
$canonicalUrl = $entryData['url']; // if this is not the apache log file i.e. it is the internal log file, the URLs are already canonical
if ($this->isApacheAccessLogFile()) {
$canonicalUrl = $this->getCanonicalUrl($foundContextPath, $newEntry['canonicalUrlPage'], $newEntry['canonicalUrlOp'], $newEntry['canonicalUrlArgs'] ?? null);
// unset elements that are temporarily used and should not be logged
unset($newEntry['canonicalUrlPage'], $newEntry['canonicalUrlOp'], $newEntry['canonicalUrlArgs']);
}
$newEntry['canonicalUrl'] = $canonicalUrl;
// unset elements that are temporarily used and should not be logged
unset($newEntry['canonicalUrlPage'], $newEntry['canonicalUrlOp'], $newEntry['canonicalUrlArgs']);
} else {
continue;
}
Expand Down Expand Up @@ -609,19 +611,19 @@ protected function getCanonicalUrl(string $contextPath, string $canonicalUrlPage
/**
* Set assoc type and IDs from the passed page, operation and arguments.
*/
protected function setAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setAssoc(int $assocType, array $args, array &$newEntry): void
{
$application = Application::get();
$applicationName = $application->getName();
switch ($applicationName) {
case 'ojs2':
$this->setOJSAssoc($assocType, $page, $op, $args, $newEntry);
$this->setOJSAssoc($assocType, $args, $newEntry);
break;
case 'omp':
$this->setOMPAssoc($assocType, $page, $op, $args, $newEntry);
$this->setOMPAssoc($assocType, $args, $newEntry);
break;
case 'ops':
$this->setOPSAssoc($assocType, $page, $op, $args, $newEntry);
$this->setOPSAssoc($assocType, $args, $newEntry);
break;
default:
throw new Exception('Unrecognized application name!');
Expand All @@ -632,7 +634,7 @@ protected function setAssoc(int $assocType, string $page, string $op, array $arg
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OJS.
*/
protected function setOJSAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOJSAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
Expand Down Expand Up @@ -875,7 +877,7 @@ protected function setOJSAssoc(int $assocType, string $page, string $op, array $
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OMP.
*/
protected function setOMPAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOMPAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
Expand Down Expand Up @@ -1028,7 +1030,7 @@ protected function setOMPAssoc(int $assocType, string $page, string $op, array $
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OPS.
*/
protected function setOPSAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOPSAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
Expand Down
39 changes: 8 additions & 31 deletions tools/convertApacheAccessLogFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function splitFileByDay(string $filePath): array

// Get all days between the first and the last date, including the last date
$firstDate->setTime(0, 0, 0);
$firstDate->setTime(0, 0, 1);
$lastDate->setTime(0, 0, 1);
$period = new DatePeriod(
$firstDate,
new DateInterval('P1D'),
Expand Down Expand Up @@ -410,33 +410,11 @@ protected function getExpectedPageAndOp(): array
return $pageAndOp;
}

/**
* Set assoc type and IDs from the passed page, operation and arguments.
*/
protected function setAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
{
$application = Application::get();
$applicationName = $application->getName();
switch ($applicationName) {
case 'ojs2':
$this->setOJSAssoc($assocType, $page, $op, $args, $newEntry);
break;
case 'omp':
$this->setOMPAssoc($assocType, $page, $op, $args, $newEntry);
break;
case 'ops':
$this->setOPSAssoc($assocType, $page, $op, $args, $newEntry);
break;
default:
throw new Exception('Unrecognized application name!');
}
}

/**
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OJS.
*/
protected function setOJSAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOJSAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
Expand Down Expand Up @@ -657,7 +635,7 @@ protected function setOJSAssoc(int $assocType, string $page, string $op, array $
}

// is this a full text or supp file
$genreDao = DAORegistry::getDAO('GenreDAO');
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$genre = $genreDao->getById($submissionFile->getData('genreId'));
if ($genre->getCategory() != Genre::GENRE_CATEGORY_DOCUMENT || $genre->getSupplementary() || $genre->getDependent()) {
$newEntry['assocType'] = Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER;
Expand Down Expand Up @@ -797,14 +775,13 @@ protected function setOJSAssoc(int $assocType, string $page, string $op, array $
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OMP.
*/
protected function setOMPAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOMPAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
// $newEntry['contextId'] has already been set
$newEntry['assocType'] = $assocType;
$newEntry['canonicalUrlPage'] = $page;
$newEntry['canonicalUrlOp'] = $page == 'catalog' ? 'index' : '';
$newEntry['canonicalUrlOp'] = $newEntry['canonicalUrlPage'] == 'catalog' ? 'index' : '';
break;

case Application::ASSOC_TYPE_SUBMISSION:
Expand Down Expand Up @@ -979,7 +956,7 @@ protected function setOMPAssoc(int $assocType, string $page, string $op, array $
}

// is this a full text or supp file
$genreDao = DAORegistry::getDAO('GenreDAO');
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$genre = $genreDao->getById($submissionFile->getData('genreId'));
if ($genre->getCategory() != Genre::GENRE_CATEGORY_DOCUMENT || $genre->getSupplementary() || $genre->getDependent()) {
$newEntry['assocType'] = Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER;
Expand Down Expand Up @@ -1022,7 +999,7 @@ protected function setOMPAssoc(int $assocType, string $page, string $op, array $
* Set assoc type and IDs from the passed page, operation and
* arguments specific to OPS.
*/
protected function setOPSAssoc(int $assocType, string $page, string $op, array $args, array &$newEntry): void
protected function setOPSAssoc(int $assocType, array $args, array &$newEntry): void
{
switch ($assocType) {
case Application::getContextAssocType():
Expand Down Expand Up @@ -1170,7 +1147,7 @@ protected function setOPSAssoc(int $assocType, string $page, string $op, array $
}

// is this a full text or supp file
$genreDao = DAORegistry::getDAO('GenreDAO');
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDao $genreDao */
$genre = $genreDao->getById($submissionFile->getData('genreId'));
if ($genre->getCategory() != Genre::GENRE_CATEGORY_DOCUMENT || $genre->getSupplementary() || $genre->getDependent()) {
$newEntry['assocType'] = Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER;
Expand Down

0 comments on commit cabf266

Please sign in to comment.