Skip to content

Commit

Permalink
Merge pull request #9500 from piwik/9258_2
Browse files Browse the repository at this point in the history
Forward php cli options to the archiver commands
  • Loading branch information
tsteur committed Jan 19, 2016
2 parents e797355 + fc12e85 commit 45669b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

This is a changelog for Piwik platform developers. All changes for our HTTP API's, Plugins, Themes, etc will be listed here.

## Piwik 2.15.1
## Piwik 2.16.0

### New features
* New segment `actionType` lets you segment all actions of a given type, eg. `actionType==events` or `actionType==downloads`. Action types values are: `pageviews`, `contents`, `sitesearches`, `events`, `outlinks`, `downloads`
* The JavaScript Tracker method `PiwikTracker.setDomains()` can now handle paths. This means when setting eg `_paq.push(['setDomains, '*.piwik.org/website1'])` all link that goes to the same domain `piwik.org` but to any other path than `website1/*` will be treated as outlink.
* It is now possible to pass an option `php-cli-options` to the `core:archive` command. The given cli options will be forwarded to the actual PHP command. This allows to for example specifiy a different memory limit for the archiving process like this: `./console core:archive --php-cli-options="-d memory_limit=8G"`

### Internal change
* When generating a new plugin skeleton via `generate:plugin` command, plugin name must now contain only letters and numbers.
Expand Down
15 changes: 13 additions & 2 deletions core/CliMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class CliMulti
*/
private $urlToPiwik = null;

private $phpCliOptions = '';

public function __construct()
{
$this->supportsAsync = $this->supportsAsync();
Expand Down Expand Up @@ -89,6 +91,15 @@ public function request(array $piwikUrls)
return $results;
}

/**
* Forwards the given configuration options to the PHP cli command.
* @param string $phpCliOptions eg "-d memory_limit=8G -c=path/to/php.ini"
*/
public function setPhpCliConfigurationOptions($phpCliOptions)
{
$this->phpCliOptions = (string) $phpCliOptions;
}

/**
* Ok, this sounds weird. Why should we care about ssl certificates when we are in CLI mode? It is needed for
* our simple fallback mode for Windows where we initiate HTTP requests instead of CLI.
Expand Down Expand Up @@ -142,8 +153,8 @@ private function buildCommand($hostname, $query, $outputFile)
$bin = $this->findPhpBinary();
$superuserCommand = $this->runAsSuperUser ? "--superuser" : "";

return sprintf('%s %s/console climulti:request -q --piwik-domain=%s %s %s > %s 2>&1 &',
$bin, PIWIK_INCLUDE_PATH, escapeshellarg($hostname), $superuserCommand, escapeshellarg($query), $outputFile);
return sprintf('%s %s %s/console climulti:request -q --piwik-domain=%s %s %s > %s 2>&1 &',
$bin, $this->phpCliOptions, PIWIK_INCLUDE_PATH, escapeshellarg($hostname), $superuserCommand, escapeshellarg($query), $outputFile);
}

private function getResponse()
Expand Down
13 changes: 9 additions & 4 deletions core/CronArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ class CronArchive
*/
public $shouldStartProfiler = false;

/**
* Given options will be forwarded to the PHP command if the archiver is executed via CLI.
* @var string
*/
public $phpCliConfigurationOptions = '';

/**
* If HTTP requests are used to initiate archiving, this controls whether invalid SSL certificates should
* be accepted or not by each request.
Expand Down Expand Up @@ -896,9 +902,7 @@ private function archiveReportsFor($idSite, $period, $date, $archiveSegments, Ti
$this->requests += count($urls);

$cliMulti = $this->makeCliMulti();
$cliMulti->setAcceptInvalidSSLCertificate($this->acceptInvalidSSLCertificate);
$cliMulti->setConcurrentProcessesLimit($this->getConcurrentRequestsPerWebsite());
$cliMulti->runAsSuperUser();
$response = $cliMulti->request($urls);

foreach ($urls as $index => $url) {
Expand Down Expand Up @@ -971,8 +975,6 @@ private function request($url)

try {
$cliMulti = $this->makeCliMulti();
$cliMulti->setAcceptInvalidSSLCertificate($this->acceptInvalidSSLCertificate);
$cliMulti->runAsSuperUser();
$responses = $cliMulti->request(array($url));

$response = !empty($responses) ? array_shift($responses) : null;
Expand Down Expand Up @@ -1714,6 +1716,9 @@ private function makeCliMulti()
{
$cliMulti = StaticContainer::get('Piwik\CliMulti');
$cliMulti->setUrlToPiwik($this->urlToPiwik);
$cliMulti->setPhpCliConfigurationOptions($this->phpCliConfigurationOptions);
$cliMulti->setAcceptInvalidSSLCertificate($this->acceptInvalidSSLCertificate);
$cliMulti->runAsSuperUser();
return $cliMulti;
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/CoreConsole/Commands/CoreArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function makeArchiver($url, InputInterface $input)
$archiver->forceTimeoutPeriod = $input->getOption("force-timeout-for-periods");
$archiver->shouldArchiveAllPeriodsSince = $input->getOption("force-all-periods");
$archiver->restrictToDateRange = $input->getOption("force-date-range");
$archiver->phpCliConfigurationOptions = $input->getOption("php-cli-options");

$restrictToPeriods = $input->getOption("force-periods");
$restrictToPeriods = explode(',', $restrictToPeriods);
Expand Down Expand Up @@ -116,5 +117,6 @@ public static function configureArchiveCommand(ConsoleCommand $command)
$command->addOption('accept-invalid-ssl-certificate', null, InputOption::VALUE_NONE,
"It is _NOT_ recommended to use this argument. Instead, you should use a valid SSL certificate!\nIt can be "
. "useful if you specified --url=https://... or if you are using Piwik with force_ssl=1");
$command->addOption('php-cli-options', null, InputOption::VALUE_OPTIONAL, 'Forwards the PHP configuration options to the PHP CLI command. For example "-d memory_limit=8G". Note: These options are only applied if the archiver actually uses CLI and not HTTP.', $default = '');
}
}
1 change: 0 additions & 1 deletion tests/PHPUnit/Integration/CronArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Piwik\Tests\Integration;

use Piwik\Archiver\Request;
use Piwik\CliMulti;
use Piwik\Container\StaticContainer;
use Piwik\CronArchive;
Expand Down

0 comments on commit 45669b2

Please sign in to comment.