Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1614 from alexispeter/clockwork-servicemanager-un…
Browse files Browse the repository at this point in the history
…aware

make only servicemanager-dependent storage-systems ServiceManagerAware
  • Loading branch information
alexispeter committed Feb 2, 2015
2 parents ec5cd76 + 6542112 commit 7101119
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 30 deletions.
3 changes: 1 addition & 2 deletions library/CM/Clockwork/Manager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class CM_Clockwork_Manager extends CM_Service_ManagerAware {
class CM_Clockwork_Manager {

/** @var CM_Clockwork_Event[] */
private $_events;
Expand Down Expand Up @@ -62,7 +62,6 @@ public function runEvents() {
*/
public function setStorage(CM_Clockwork_Storage_Abstract $storage) {
$this->_storage = $storage;
$this->_storage->setServiceManager($this->getServiceManager());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/CM/Clockwork/Storage/Abstract.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

abstract class CM_Clockwork_Storage_Abstract extends CM_Service_ManagerAware {
abstract class CM_Clockwork_Storage_Abstract {

/** @var string */
protected $_context;
Expand Down
4 changes: 3 additions & 1 deletion library/CM/Clockwork/Storage/FileSystem.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class CM_Clockwork_Storage_FileSystem extends CM_Clockwork_Storage_Abstract {
class CM_Clockwork_Storage_FileSystem extends CM_Clockwork_Storage_Abstract implements CM_Service_ManagerAwareInterface {

use CM_Service_ManagerAwareTrait;

protected function _load() {
$data = [];
Expand Down
5 changes: 3 additions & 2 deletions library/CM/Elasticsearch/Index/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public function optimize() {

public function startMaintenance() {
$clockwork = new CM_Clockwork_Manager();
$clockwork->setServiceManager(CM_Service_Manager::getInstance());
$clockwork->setStorage(new CM_Clockwork_Storage_FileSystem('search-maintenance'));
$storage = new CM_Clockwork_Storage_FileSystem('search-maintenance');
$storage->setServiceManager(CM_Service_Manager::getInstance());
$clockwork->setStorage($storage);
$clockwork->registerCallback('search-index-update', '1 minute', array($this, 'update'));
$clockwork->registerCallback('search-index-optimize', '1 hour', array($this, 'optimize'));
$clockwork->start();
Expand Down
10 changes: 6 additions & 4 deletions library/CM/Maintenance/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ class CM_Maintenance_Cli extends CM_Cli_Runnable_Abstract {
*/
public function start() {
$this->_clockworkManager = new CM_Clockwork_Manager();
$this->_clockworkManager->setServiceManager(CM_Service_Manager::getInstance());
$this->_clockworkManager->setStorage(new CM_Clockwork_Storage_FileSystem('app-maintenance'));
$storage = new CM_Clockwork_Storage_FileSystem('app-maintenance');
$storage->setServiceManager(CM_Service_Manager::getInstance());
$this->_clockworkManager->setStorage($storage);
$this->_registerCallbacks();
$this->_clockworkManager->start();
}

public function startLocal() {
$this->_clockworkManager = new CM_Clockwork_Manager();
$this->_clockworkManager->setServiceManager(CM_Service_Manager::getInstance());
$this->_clockworkManager->setStorage(new CM_Clockwork_Storage_FileSystem('app-maintenance-local'));
$storage = new CM_Clockwork_Storage_FileSystem('app-maintenance-local');
$storage->setServiceManager(CM_Service_Manager::getInstance());
$this->_clockworkManager->setStorage($storage);
$this->_registerCallbacksLocal();
$this->_clockworkManager->start();
}
Expand Down
20 changes: 0 additions & 20 deletions tests/library/CM/Clockwork/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

class CM_Clockwork_ManagerTest extends CMTest_TestCase {

public function testSetStorage() {
$manager = new CM_Clockwork_Manager();
$serviceManager = $this->mockObject('CM_Service_Manager');
/** @var CM_Service_Manager $serviceManager */
$manager->setServiceManager($serviceManager);
$storage = $this->mockObject('CM_Clockwork_Storage_Abstract', ['foo']);
/** @var CM_Clockwork_Storage_Abstract $storage */
$manager->setStorage($storage);
$this->assertSame($serviceManager, $storage->getServiceManager());
}

public function testRunNonBlocking() {
$process = $this->mockClass('CM_Process')->newInstanceWithoutConstructor();
$forkMock = $process->mockMethod('fork');
Expand Down Expand Up @@ -82,7 +71,6 @@ public function testShouldRunFixedTimeMode() {
$currently = new DateTime('13:59:59', $timeZone);
/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
/** @var CM_Clockwork_Event $event */
$event = new CM_Clockwork_Event('event1', '14:00');
Expand All @@ -105,7 +93,6 @@ public function testShouldRunFixedTimeMode() {
$lastRuntime = null;
$currently = new DateTime('last day of', $timeZone);
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$event = new CM_Clockwork_Event('event2', 'first day of 09:00');
Expand All @@ -122,7 +109,6 @@ public function testShouldRunFixedTimeMode() {
$currently = new DateTime('23:59', $timeZone);

$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$event = new CM_Clockwork_Event('event3', '23:59');
Expand Down Expand Up @@ -156,7 +142,6 @@ public function testShouldRunIntervalMode() {
$storage = $storageClass->newInstance();
/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');

Expand Down Expand Up @@ -211,7 +196,6 @@ public function testShouldRun_fixedTimeMode_backwardDaylightSavingTimeSwitch() {

/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');
Expand Down Expand Up @@ -256,7 +240,6 @@ public function testShouldRun_fixedTimeMode_forwardDaylightSavingTimeSwitch() {

/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');
Expand Down Expand Up @@ -295,7 +278,6 @@ public function testShouldRun_fixedTimeMode_backwardDaylightSavingTimeSwitch_Neg
$storage = $storageClass->newInstance();
/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');
Expand Down Expand Up @@ -334,7 +316,6 @@ public function testShouldRun_fixedTimeMode_forwardDaylightSavingTimeSwitch_Nega

/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');
Expand Down Expand Up @@ -380,7 +361,6 @@ private function _testIntervalModeDST(DateTime $start, DateTimeZone $timeZone) {
$storage = $storageClass->newInstance();
/** @var CM_Clockwork_Manager $manager */
$manager = $managerMock->newInstance();
$manager->setServiceManager(CM_Service_Manager::getInstance());
$manager->setStorage($storage);
$manager->setTimeZone($timeZone);
$_shouldRun = CMTest_TH::getProtectedMethod('CM_Clockwork_Manager', '_shouldRun');
Expand Down

0 comments on commit 7101119

Please sign in to comment.