Skip to content

Commit

Permalink
Added return for command classes, #PG-2642
Browse files Browse the repository at this point in the history
  • Loading branch information
AltamashShaikh committed Mar 16, 2023
1 parent f93e0aa commit a0cec26
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Commands/AnonymizeLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ protected function configure()
$this->addOption('pluginname', null, InputOption::VALUE_REQUIRED, 'If defined, the log file will be placed in the specified plugin instead of the VisitorGenerator plugin', 'VisitorGenerator');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $this->getPathToFile($input);
Expand All @@ -60,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$target = $this->buildTargetFileName($plugin, $file);
$this->saveFile($output, $target, $anonymized);

return 0;
return self::SUCCESS;
}

private function getReplace(InputInterface $input)
Expand Down
8 changes: 7 additions & 1 deletion Commands/GenerateAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ protected function configure()
$this->addOption('idsite', null, InputOption::VALUE_REQUIRED, 'Defines the site the goals should be generated for');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$idSite = (int) $input->getOption('idsite');
Expand All @@ -41,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->writeSuccessMessage($output, array('1 Annotation for today generated'));

return 0;
return self::SUCCESS;
}

}
8 changes: 7 additions & 1 deletion Commands/GenerateGoals.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ protected function configure()
$this->addOption('idsite', null, InputOption::VALUE_REQUIRED, 'Defines the site the goals should be generated for');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$idSite = (int) $input->getOption('idsite');
Expand All @@ -43,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
sprintf('idsite=%d, %d goals generated (idgoal from %d to %d)', $idSite, count($goalIds), reset($goalIds), end($goalIds))
));

return 0;
return self::SUCCESS;
}

}
16 changes: 11 additions & 5 deletions Commands/GenerateLiveVisits.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ protected function configure()
. 'command continuously or a cron, this should be used, since the generated token auth will expire after 24 hours.');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$piwikUrl = $input->getOption('custom-matomo-url');
Expand All @@ -69,14 +75,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
list($count, $nextWaitTime) = $generateLiveVisits->tick();
if ($count === null) {
$output->writeln("Found no logs to track for day of month / time of day, exiting.");
return 0;
return self::SUCCESS;
}

$output->writeln(" tracked $count actions.");

if ($nextWaitTime === null) {
$output->writeln("Out of logs, exiting.");
return 0;
return self::SUCCESS;
}

// nextWaitTime can be large if the next visit happens in an hour. no sense in
Expand All @@ -85,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
&& (time() + $nextWaitTime) - $startTime > $stopAfter
) {
$output->writeln("$stopAfter seconds reached, exiting.");
return 0;
return self::SUCCESS;
}

$output->writeln(" sleeping {$nextWaitTime}s.");
Expand All @@ -95,11 +101,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
&& time() - $startTime > $stopAfter
) {
$output->writeln("$stopAfter seconds reached, exiting.");
return 0;
return self::SUCCESS;
}
}

return 0; // should never occur
return self::SUCCESS; // should never occur
}

private function getPostiveIntegerOption(InputInterface $input, $optionName)
Expand Down
8 changes: 7 additions & 1 deletion Commands/GenerateUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ protected function configure()
$this->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Defines how many users should be generated', 10);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$limit = $input->getOption('limit');
Expand All @@ -36,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->writeSuccessMessage($output, array(count($userLogins) . ' Users generated'));

return 0;
return self::SUCCESS;
}

}
8 changes: 7 additions & 1 deletion Commands/GenerateVisits.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ protected function configure()
$this->addOption('non-profilable', null, InputOption::VALUE_NONE, "If supplied, tracks data without visitor IDs so it will be considered 'not profilable'.");
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->timeout = $input->getOption('timeout');
Expand Down Expand Up @@ -97,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
round($nbActionsTotal / $timer->getTime(), 0) . ' requests per second'
));

return 0;
return self::SUCCESS;
}

private function getLimitFakeVisits(InputInterface $input)
Expand Down
8 changes: 7 additions & 1 deletion Commands/GenerateWebsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ protected function configure()
$this->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Defines how many websites should be generated', 10);
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$limit = $input->getOption('limit');
Expand All @@ -38,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
sprintf('%d Websites generated (idsite from %d to %d)', count($siteIds), reset($siteIds), end($siteIds))
));

return 0;
return self::SUCCESS;
}

}
8 changes: 7 additions & 1 deletion Commands/ShortenLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ protected function configure()
$this->addOption('force-keep', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Forces to keep a log line if the given terms is present.');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/

protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $this->getPathToFile($input);
Expand Down Expand Up @@ -68,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

echo $shortened;

return 0;
return self::SUCCESS;
}

private function containsTerm($line, $terms)
Expand Down

0 comments on commit a0cec26

Please sign in to comment.