Skip to content
Extraits de code Groupes Projets
Valider f06a7a1d rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

refs #4610 Pid => Process

parent 113e403a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
*/ */
namespace Piwik; namespace Piwik;
use Piwik\CliMulti\Pid; use Piwik\CliMulti\Process;
use Piwik\CliMulti\Output; use Piwik\CliMulti\Output;
class CliMulti { class CliMulti {
/** /**
* @var \Piwik\CliMulti\Pid[] * @var \Piwik\CliMulti\Process[]
*/ */
private $pids = array(); private $pids = array();
...@@ -49,7 +49,7 @@ class CliMulti { ...@@ -49,7 +49,7 @@ class CliMulti {
shell_exec($command . $appendix); shell_exec($command . $appendix);
$this->pids[] = new Pid($pid); $this->pids[] = new Process($pid);
$this->outputs[] = new Output($output); $this->outputs[] = new Output($output);
} }
} }
...@@ -106,6 +106,10 @@ class CliMulti { ...@@ -106,6 +106,10 @@ class CliMulti {
return md5($command . microtime(true) . rand(0, 99999)); return md5($command . microtime(true) . rand(0, 99999));
} }
/**
* What is missing under windows? Detection whether a process is still running in Process::isProcessStillRunning
* and how to send a process into background in start()
*/
private function supportsAsync() private function supportsAsync()
{ {
return !SettingsServer::isWindows(); return !SettingsServer::isWindows();
......
...@@ -11,16 +11,16 @@ namespace Piwik\CliMulti; ...@@ -11,16 +11,16 @@ namespace Piwik\CliMulti;
use Piwik\Filesystem; use Piwik\Filesystem;
use Piwik\SettingsServer; use Piwik\SettingsServer;
class Pid class Process
{ {
private $pidFile = ''; private $pidFile = '';
public function __construct($name) public function __construct($pid)
{ {
$pidDir = PIWIK_INCLUDE_PATH . '/tmp/pids'; $pidDir = PIWIK_INCLUDE_PATH . '/tmp/pids';
Filesystem::mkdir($pidDir, true); Filesystem::mkdir($pidDir, true);
$this->pidFile = $pidDir . '/' . $name . '.pid'; $this->pidFile = $pidDir . '/' . $pid . '.pid';
$this->markAsNotStarted(); $this->markAsNotStarted();
} }
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/ */
if (!defined('PIWIK_INCLUDE_PATH')) { define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
}
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH); define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
require_once PIWIK_INCLUDE_PATH . '/core/Common.php'; require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
...@@ -20,7 +18,7 @@ if (!Piwik\Common::isPhpCliMode()) { ...@@ -20,7 +18,7 @@ if (!Piwik\Common::isPhpCliMode()) {
include PIWIK_INCLUDE_PATH . '/core/Singleton.php'; include PIWIK_INCLUDE_PATH . '/core/Singleton.php';
include PIWIK_INCLUDE_PATH . '/core/FrontController.php'; include PIWIK_INCLUDE_PATH . '/core/FrontController.php';
include PIWIK_INCLUDE_PATH . '/core/Filesystem.php'; include PIWIK_INCLUDE_PATH . '/core/Filesystem.php';
include PIWIK_INCLUDE_PATH . '/core/CliMulti/Pid.php'; include PIWIK_INCLUDE_PATH . '/core/CliMulti/Process.php';
include PIWIK_INCLUDE_PATH . '/core/SettingsServer.php'; include PIWIK_INCLUDE_PATH . '/core/SettingsServer.php';
include PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; include PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
include PIWIK_INCLUDE_PATH . '/core/Url.php'; include PIWIK_INCLUDE_PATH . '/core/Url.php';
...@@ -32,7 +30,7 @@ if (!empty($_GET['testmode'])) { ...@@ -32,7 +30,7 @@ if (!empty($_GET['testmode'])) {
} }
if (!empty($_GET['pid']) && \Piwik\Filesystem::isValidFilename($_GET['pid'])) { if (!empty($_GET['pid']) && \Piwik\Filesystem::isValidFilename($_GET['pid'])) {
$pid = new \Piwik\CliMulti\Pid($_GET['pid']); $pid = new \Piwik\CliMulti\Process($_GET['pid']);
$pid->startProcess(); $pid->startProcess();
} }
......
...@@ -5,67 +5,67 @@ ...@@ -5,67 +5,67 @@
* @link http://piwik.org * @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/ */
use Piwik\CliMulti\Pid; use Piwik\CliMulti\Process;
/** /**
* Class PidTest * Class ProcessTest
* @group Core * @group Core
*/ */
class PidTest extends PHPUnit_Framework_TestCase class ProcessTest extends PHPUnit_Framework_TestCase
{ {
/** /**
* @var Pid * @var Process
*/ */
private $pid; private $process;
public function setUp() public function setUp()
{ {
$this->pid = new Pid('test'); $this->process = new Process('testPid');
} }
public function tearDown() public function tearDown()
{ {
$this->pid->finishProcess(); $this->process->finishProcess();
} }
public function test_construct_shouldBeNotStarted_IfPidJustCreated() public function test_construct_shouldBeNotStarted_IfPidJustCreated()
{ {
$this->assertFalse($this->pid->hasStarted()); $this->assertFalse($this->process->hasStarted());
} }
public function test_construct_shouldBeNotRunning_IfPidJustCreated() public function test_construct_shouldBeNotRunning_IfPidJustCreated()
{ {
$this->assertFalse($this->pid->isRunning()); $this->assertFalse($this->process->isRunning());
} }
public function test_startProcess_finishProcess_ShouldMarkProcessAsStarted() public function test_startProcess_finishProcess_ShouldMarkProcessAsStarted()
{ {
$this->assertFalse($this->pid->isRunning()); $this->assertFalse($this->process->isRunning());
$this->assertFalse($this->pid->hasStarted()); $this->assertFalse($this->process->hasStarted());
$this->pid->startProcess(); $this->process->startProcess();
$this->assertTrue($this->pid->isRunning()); $this->assertTrue($this->process->isRunning());
$this->assertTrue($this->pid->hasStarted()); $this->assertTrue($this->process->hasStarted());
$this->assertTrue($this->pid->isRunning()); $this->assertTrue($this->process->isRunning());
$this->assertTrue($this->pid->hasStarted()); $this->assertTrue($this->process->hasStarted());
$this->pid->startProcess(); $this->process->startProcess();
$this->assertTrue($this->pid->isRunning()); $this->assertTrue($this->process->isRunning());
$this->assertTrue($this->pid->hasStarted()); $this->assertTrue($this->process->hasStarted());
$this->pid->finishProcess(); $this->process->finishProcess();
$this->assertFalse($this->pid->isRunning()); $this->assertFalse($this->process->isRunning());
$this->assertTrue($this->pid->hasStarted()); $this->assertTrue($this->process->hasStarted());
} }
public function test_finishProcess_ShouldNotThrowError_IfNotStartedBefore() public function test_finishProcess_ShouldNotThrowError_IfNotStartedBefore()
{ {
$this->pid->finishProcess(); $this->process->finishProcess();
$this->assertFalse($this->pid->isRunning()); $this->assertFalse($this->process->isRunning());
$this->assertTrue($this->pid->hasStarted()); $this->assertTrue($this->process->hasStarted());
} }
} }
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter