Skip to content

Commit

Permalink
refs #4903 better solution for not working web archiving
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur committed Mar 26, 2014
1 parent 213b5c7 commit 7a2bf71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 61 deletions.
54 changes: 19 additions & 35 deletions misc/cron/archive.php
Expand Up @@ -17,52 +17,36 @@
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
}

if (empty($_SERVER['argv'])) {

if (!class_exists('Piwik\Console', false)) {
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);

define('PIWIK_ENABLE_SESSION_START', PIWIK_INCLUDE_PATH);
require_once PIWIK_INCLUDE_PATH . "/index.php";

$archiving = new Piwik\CronArchive();
try {
$archiving->init();
$archiving->run();
$archiving->runScheduledTasks();
$archiving->end();
} catch (Exception $e) {
$archiving->logFatalError($e->getMessage());
}

return;
}

$callee = array_shift($_SERVER['argv']);

$args = array($callee);
$args[] = 'core:archive';
foreach ($_SERVER['argv'] as $arg) {
if (0 === strpos($arg, '--')) {
$args[] = $arg;
} elseif (0 === strpos($arg, '-')) {
$args[] = '-' . $arg;
} else {
$args[] = '--' . $arg;
}
if (!empty($_SERVER['argv'][0])) {
$callee = $_SERVER['argv'][0];
} else {
$callee = '';
}

$_SERVER['argv'] = $args;

$piwikHome = PIWIK_INCLUDE_PATH;

if (false !== strpos($callee, 'archive.php')) {
echo "
$piwikHome = PIWIK_INCLUDE_PATH;
echo "
-------------------------------------------------------
Using this 'archive.php' script is no longer recommended.
Please use '/path/to/php $piwikHome/console core:archive " . implode(' ', array_slice($args, 2)) . "' instead.
Please use '/path/to/php $piwikHome/console core:archive " . implode(' ', array_slice($_SERVER['argv'], 1)) . "' instead.
To get help use '/path/to/php $piwikHome/console core:archive --help'
-------------------------------------------------------
\n\n";
}

include $piwikHome . '/console';
$archiving = new Piwik\CronArchive();
try {
$archiving->init();
$archiving->run();
$archiving->runScheduledTasks();
$archiving->end();
} catch (Exception $e) {
$archiving->logFatalError($e->getMessage());
}
27 changes: 1 addition & 26 deletions plugins/CoreConsole/Commands/CoreArchiver.php
Expand Up @@ -44,31 +44,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$_SERVER['argv'][] = '--url=' . $input->getOption('piwik-domain');
}

$this->initEnv();

$archiving = new CronArchive();
try {
$archiving->init();
$archiving->run();
$archiving->runScheduledTasks();
$archiving->end();
} catch (\Exception $e) {
$archiving->logFatalError($e->getMessage());
}
}

private function initEnv()
{
if (!defined('PIWIK_ENABLE_ERROR_HANDLER')) {
define('PIWIK_ENABLE_ERROR_HANDLER', false);
}

if (!defined('PIWIK_ENABLE_SESSION_START')) {
define('PIWIK_ENABLE_SESSION_START', false);
}

if (!defined('PIWIK_ENABLE_DISPATCH')) {
define('PIWIK_ENABLE_DISPATCH', false);
}
include PIWIK_INCLUDE_PATH . '/misc/cron/archive.php';
}
}

0 comments on commit 7a2bf71

Please sign in to comment.