From 97ed36996eacccb63939d41e85184e2b576ea362 Mon Sep 17 00:00:00 2001 From: Fabrizio Branca Date: Thu, 7 Aug 2014 23:28:12 -0700 Subject: [PATCH 001/153] Introduced job table --- .../community/Aoe/Scheduler/Model/Job.php | 25 +++++ .../Aoe/Scheduler/Model/Resource/Job.php | 19 ++++ .../Model/Resource/Job/Collection.php | 19 ++++ .../Aoe/Scheduler/Test/Model/Job.php | 92 +++++++++++++++++++ .../community/Aoe/Scheduler/etc/config.xml | 15 ++- .../mysql4-upgrade-0.4.3-0.5.0.php | 45 +++++++++ 6 files changed, 214 insertions(+), 1 deletion(-) create mode 100755 app/code/community/Aoe/Scheduler/Model/Job.php create mode 100755 app/code/community/Aoe/Scheduler/Model/Resource/Job.php create mode 100755 app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php create mode 100755 app/code/community/Aoe/Scheduler/Test/Model/Job.php create mode 100755 app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.4.3-0.5.0.php diff --git a/app/code/community/Aoe/Scheduler/Model/Job.php b/app/code/community/Aoe/Scheduler/Model/Job.php new file mode 100755 index 0000000..9b44910 --- /dev/null +++ b/app/code/community/Aoe/Scheduler/Model/Job.php @@ -0,0 +1,25 @@ +_init('aoe_scheduler/job'); + } + +} \ No newline at end of file diff --git a/app/code/community/Aoe/Scheduler/Model/Resource/Job.php b/app/code/community/Aoe/Scheduler/Model/Resource/Job.php new file mode 100755 index 0000000..8d482a1 --- /dev/null +++ b/app/code/community/Aoe/Scheduler/Model/Resource/Job.php @@ -0,0 +1,19 @@ +_init('aoe_scheduler/job', 'id'); + } + +} diff --git a/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php b/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php new file mode 100755 index 0000000..3fb35b3 --- /dev/null +++ b/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php @@ -0,0 +1,19 @@ +_init('aoe_scheduler/job'); + } + +} diff --git a/app/code/community/Aoe/Scheduler/Test/Model/Job.php b/app/code/community/Aoe/Scheduler/Test/Model/Job.php new file mode 100755 index 0000000..e1f6563 --- /dev/null +++ b/app/code/community/Aoe/Scheduler/Test/Model/Job.php @@ -0,0 +1,92 @@ +assertInstanceOf('Aoe_Scheduler_Model_Job', $job); + return $job; + } + + /** + * @test + */ + public function checkResourceModelClass() { + $jobResource = Mage::getModel('aoe_scheduler/job')->getResource(); /* @var $jobResource Aoe_Scheduler_Model_Resource_Job */ + $this->assertInstanceOf('Aoe_Scheduler_Model_Resource_Job', $jobResource); + + $jobResource = Mage::getResourceModel('aoe_scheduler/job'); + $this->assertInstanceOf('Aoe_Scheduler_Model_Resource_Job', $jobResource); + + return $jobResource; + } + + /** + * @test + */ + public function checkResourceCollectionModelClass() { + $jobCollection = Mage::getModel('aoe_scheduler/job')->getCollection(); /* @var $jobCollection Aoe_Scheduler_Model_Resource_Job_Collection */ + $this->assertInstanceOf('Aoe_Scheduler_Model_Resource_Job_Collection', $jobCollection); + } + + /** + * @test + * @depends checkResourceModelClass + */ + public function checkTableName(Aoe_Scheduler_Model_Resource_Job $jobResource) { + $this->assertEquals('cron_job', $jobResource->getMainTable()); + } + + /** + * @test + */ + public function checkPersistence() { + + foreach (Mage::getModel('aoe_scheduler/job')->getCollection() as $job) { /* @var $job Aoe_Scheduler_Model_Job */ + $job->delete(); + } + + $job = Mage::getModel('aoe_scheduler/job'); /* @var $job Aoe_Scheduler_Model_Job */ + $job->setJobCode('testCode'); + $job->save(); + + $reloadedJob = Mage::getModel('aoe_scheduler/job')->load($job->getId()); /* @var $reloadedJob Aoe_Scheduler_Model_Job */ + $this->assertEquals('testCode', $reloadedJob->getJobCode()); + + $reloadedJob = Mage::getModel('aoe_scheduler/job')->load('testCode', 'job_code'); /* @var $reloadedJob Aoe_Scheduler_Model_Job */ + $this->assertEquals($job->getId(), $reloadedJob->getId()); + + $reloadedJob->delete(); + + $loadAgain = Mage::getModel('aoe_scheduler/job')->load('testCode'); /* @var $loadAgain Aoe_Scheduler_Model_Job */ + $this->assertNull($loadAgain->getJobCode()); + } + + /** + * @test + */ + public function checkUniqueKey() { + + foreach (Mage::getModel('aoe_scheduler/job')->getCollection() as $job) { /* @var $job Aoe_Scheduler_Model_Job */ + $job->delete(); + } + + $job = Mage::getModel('aoe_scheduler/job'); /* @var $job Aoe_Scheduler_Model_Job */ + $job->setJobCode('testCode'); + $job->save(); + + $this->setExpectedException('Zend_Db_Statement_Exception'); + + $duplicateJob = Mage::getModel('aoe_scheduler/job'); /* @var $job Aoe_Scheduler_Model_Job */ + $duplicateJob->setJobCode('testCode'); + $duplicateJob->save(); + } + +} + diff --git a/app/code/community/Aoe/Scheduler/etc/config.xml b/app/code/community/Aoe/Scheduler/etc/config.xml index ba5fd06..3679a5a 100755 --- a/app/code/community/Aoe/Scheduler/etc/config.xml +++ b/app/code/community/Aoe/Scheduler/etc/config.xml @@ -2,7 +2,7 @@ - 0.4.3 + 0.5.0 @@ -22,16 +22,29 @@ Aoe_Scheduler_Model + aoe_scheduler_resource + + Aoe_Scheduler_Model_Resource + + + cron_job
+
+
+
+ Aoe_Scheduler_Model_Observer Aoe_Scheduler_Model_Schedule +
+ +