public static function upgradeTariffPlanLifeCycle($template)
 {
     $oldData = $template->exportData();
     $tariff = new TariffPlanLifeCycleModel();
     $tariff->importData($oldData);
     $newStatuses = array(LifeCycleModel::STATUS_ACTIVATION_READY, LifeCycleModel::STATUS_ACTIVATION_PENDANT);
     $changed = false;
     foreach ($newStatuses as $statusConst) {
         $status = $tariff->findStatus($statusConst);
         if (!$status) {
             $status = new StatusCostModel(array('status' => $statusConst, 'cost' => 0));
             $tariff->addStatus($status);
             $changed = true;
         }
     }
     if (!$changed) {
         throw new App_MigrationTool_TemplatesTo24_Exception("LifeCycle tariff plan template {$template->id} already upgraded.");
     }
     $validator = new TariffPlanLifeCycleValidate();
     if (!$validator->isValid($tariff)) {
         throw new App_MigrationTool_TemplatesTo24_Exception("Invalid LifeCycle tariff plan template {$template->id}. " . var_export($validator->getMessages(), true));
     }
     return $tariff;
 }
 public function testBulkUpgradeTariffPlanLifeCycle()
 {
     $this->_template->importData(Zend_Json::decode(self::LIFE_CYCLE_TARIFF));
     $this->_template->id = null;
     $this->_mapper->insert($this->_template);
     App_MigrationTool_TemplatesTo24_LifeCycleTariffUtils::performUpgrade();
     $template = $this->_mapper->findOneById($this->_template->id);
     $this->assertInstanceOf('Application\\Model\\TemplateModel', $template);
     $tariff = new TariffPlanLifeCycleModel($template->exportData());
     $this->assertInstanceOf('Application\\Model\\TariffPlanLifeCycleModel', $tariff);
     $status = $tariff->findStatus(LifeCycleModel::STATUS_ACTIVATION_READY);
     $this->assertInstanceOf('Application\\Model\\TariffPlan\\StatusCostModel', $status);
     $this->assertEquals(0, $status->cost);
     $status = $tariff->findStatus(LifeCycleModel::STATUS_ACTIVATION_PENDANT);
     $this->assertInstanceOf('Application\\Model\\TariffPlan\\StatusCostModel', $status);
     $this->assertEquals(0, $status->cost);
     $validator = new TariffPlanLifeCycleValidate();
     $this->assertTrue($validator->isValid($tariff), var_export($validator->getMessages(), 1));
 }