update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -24,6 +24,7 @@ class Process
|
|||
private $pidFile = '';
|
||||
private $timeCreation = null;
|
||||
private $isSupported = null;
|
||||
private $pid = null;
|
||||
|
||||
public function __construct($pid)
|
||||
{
|
||||
|
|
@ -32,15 +33,21 @@ class Process
|
|||
}
|
||||
|
||||
$pidDir = CliMulti::getTmpPath();
|
||||
Filesystem::mkdir($pidDir, true);
|
||||
Filesystem::mkdir($pidDir);
|
||||
|
||||
$this->isSupported = self::isSupported();
|
||||
$this->pidFile = $pidDir . '/' . $pid . '.pid';
|
||||
$this->timeCreation = time();
|
||||
$this->pid = $pid;
|
||||
|
||||
$this->markAsNotStarted();
|
||||
}
|
||||
|
||||
public function getPid()
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
private function markAsNotStarted()
|
||||
{
|
||||
$content = $this->getPidFileContent();
|
||||
|
|
@ -97,6 +104,11 @@ class Process
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!$this->pidFileSizeIsNormal()) {
|
||||
$this->finishProcess();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isProcessStillRunning($content)) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -108,6 +120,13 @@ class Process
|
|||
return false;
|
||||
}
|
||||
|
||||
private function pidFileSizeIsNormal()
|
||||
{
|
||||
$size = Filesystem::getFileSize($this->pidFile);
|
||||
|
||||
return $size !== null && $size < 500;
|
||||
}
|
||||
|
||||
public function finishProcess()
|
||||
{
|
||||
Filesystem::deleteFileIfExists($this->pidFile);
|
||||
|
|
@ -125,7 +144,7 @@ class Process
|
|||
}
|
||||
|
||||
$lockedPID = trim($content);
|
||||
$runningPIDs = explode("\n", trim( `ps -e | awk '{print $1}'` ));
|
||||
$runningPIDs = self::getRunningProcesses();
|
||||
|
||||
return !empty($lockedPID) && in_array($lockedPID, $runningPIDs);
|
||||
}
|
||||
|
|
@ -154,17 +173,30 @@ class Process
|
|||
return false;
|
||||
}
|
||||
|
||||
if (static::commandExists('ps') && self::returnsSuccessCode('ps') && self::commandExists('awk')) {
|
||||
if (!self::commandExists('ps') || !self::returnsSuccessCode('ps') || !self::commandExists('awk')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count(self::getRunningProcesses()) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (!self::isProcFSMounted()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function isSystemNotSupported()
|
||||
{
|
||||
$uname = shell_exec('uname -a');
|
||||
if(strpos($uname, 'synology') !== false) {
|
||||
$uname = @shell_exec('uname -a 2> /dev/null');
|
||||
|
||||
if (empty($uname)) {
|
||||
$uname = php_uname();
|
||||
}
|
||||
|
||||
if (strpos($uname, 'synology') !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -175,12 +207,12 @@ class Process
|
|||
$command = 'shell_exec';
|
||||
$disabled = explode(',', ini_get('disable_functions'));
|
||||
$disabled = array_map('trim', $disabled);
|
||||
return in_array($command, $disabled);
|
||||
return in_array($command, $disabled) || !function_exists($command);
|
||||
}
|
||||
|
||||
private static function returnsSuccessCode($command)
|
||||
{
|
||||
$exec = $command . ' > /dev/null 2>&1 & echo $?';
|
||||
$exec = $command . ' > /dev/null 2>&1; echo $?';
|
||||
$returnCode = shell_exec($exec);
|
||||
$returnCode = trim($returnCode);
|
||||
return 0 == (int) $returnCode;
|
||||
|
|
@ -188,8 +220,38 @@ class Process
|
|||
|
||||
private static function commandExists($command)
|
||||
{
|
||||
$result = shell_exec('which ' . escapeshellarg($command));
|
||||
$result = @shell_exec('which ' . escapeshellarg($command) . ' 2> /dev/null');
|
||||
|
||||
return !empty($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ps -e requires /proc
|
||||
* @return bool
|
||||
*/
|
||||
private static function isProcFSMounted()
|
||||
{
|
||||
if (is_resource(@fopen('/proc', 'r'))) {
|
||||
return true;
|
||||
}
|
||||
// Testing if /proc is a resource with @fopen fails on systems with open_basedir set.
|
||||
// by using stat we not only test the existance of /proc but also confirm it's a 'proc' filesystem
|
||||
$type = @shell_exec('stat -f -c "%T" /proc 2>/dev/null');
|
||||
return strpos($type, 'proc') === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[] The ids of the currently running processes
|
||||
*/
|
||||
public static function getRunningProcesses()
|
||||
{
|
||||
$ids = explode("\n", trim(`ps ex 2>/dev/null | awk '{print $1}' 2>/dev/null`));
|
||||
|
||||
$ids = array_map('intval', $ids);
|
||||
$ids = array_filter($ids, function ($id) {
|
||||
return $id > 0;
|
||||
});
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue