public function testFindOneById()
 {
     // First persist the template
     $this->template->save();
     // Now check if we can find it by its Id
     $template = $this->templateMapper->findOneById($this->template->getId());
     $this->assertNotNull($template);
     $this->assertInstanceOf('\\Application\\Model\\TemplateModel', $template);
     $this->assertEquals($this->template->exportData(), $template->exportData());
 }
Exemplo n.º 2
0
 /**
  *
  * @param  \Application\Model\TemplateModel           $template
  * @throws App_MigrationTool_TemplatesTo23_Exception
  * @return \Application\Model\LifeCycleModel
  */
 public static function upgradeLifeCycle($template)
 {
     $oldData = $template->exportData();
     $lifeCycle = new LifeCycleModel();
     $lifeCycle->importData($oldData);
     $validatorAuto = new App_MigrationTool_TemplatesTo24_LifeCycleAutomatic();
     $validatorAutoTest = new App_MigrationTool_TemplatesTo24_LifeCycleAutomaticWithTest();
     if (!($validatorAuto->isValid($lifeCycle) || $validatorAutoTest->isValid($lifeCycle))) {
         throw new App_MigrationTool_TemplatesTo24_Exception("LifeCycle template {$template->id} does not need upgrade.");
     }
     $status = $lifeCycle->getStatusByOriginStatus(LifeCycleModel::STATUS_ACTIVATION_READY);
     $transition = $status->getTransitionByDestinationStatus(LifeCycleModel::STATUS_ACTIVE);
     if ($transition->manual) {
         throw new App_MigrationTool_TemplatesTo24_Exception("LifeCycle template {$template->id} already upgraded.");
     }
     $transition->manual = true;
     return $lifeCycle;
 }
 /**
  *
  * @param  \Application\Model\TemplateModel           $template
  * @param  \Application\Model\ZonePlanModel           $zonePlan
  * @param  array                                      $relation
  * @throws App_MigrationTool_TemplatesTo20_Exception
  * @return \Application\Model\TariffPlanServicesModel
  */
 public static function upgradeTariffPlan($template, $zonePlan, $relation)
 {
     $oldData = $template->exportData();
     $tariffPlan = new TariffPlanServicesModel();
     $tariffPlan->importData($oldData);
     if ($tariffPlan->zonePlan) {
         throw new App_MigrationTool_TemplatesTo20_Exception("Tariff plan template " . $template->id . " already upgraded.");
     }
     $tariffPlan->setZonePlan($zonePlan);
     //Single tariff fields
     $tariffTypes = array('defaultData', 'defaultOrigVoice', 'defaultTermVoice', 'defaultSms');
     foreach ($tariffTypes as $type) {
         if (!isset($oldData[$type]['zoneId']) || $oldData[$type]['zoneId'] == -1) {
             continue;
         }
         if (!isset($relation[$oldData[$type]['zoneId']])) {
             throw new App_MigrationTool_TemplatesTo20_Exception("Unknown zone " . $oldData[$type]['zoneId'] . ". Impossible to upgrade.");
         }
         $tariff = new ServiceTariffModel($oldData[$type]);
         $tariff->zoneGroupId = $relation[$oldData[$type]['zoneId']];
         $tariffPlan->{$type} = $tariff;
     }
     //Array of tariff fields
     $tariffTypes = array('data', 'origVoice', 'termVoice', 'sms');
     foreach ($tariffTypes as $type) {
         $tariffs = array();
         foreach ($oldData[$type] as $oldTariff) {
             if (!isset($oldTariff['zoneId']) || $oldTariff['zoneId'] == -1) {
                 $tariff = new ServiceTariffModel($oldTariff);
                 $tariff->zoneGroupId = -1;
                 $tariffs[] = $tariff;
                 continue;
             }
             if (!isset($relation[$oldTariff['zoneId']])) {
                 throw new App_MigrationTool_TemplatesTo20_Exception("Unknown zone " . $oldTariff['zoneId'] . ". Impossible to upgrade.");
             }
             $tariff = new ServiceTariffModel($oldTariff);
             $tariff->zoneGroupId = $relation[$oldTariff['zoneId']];
             $tariffs[] = $tariff;
         }
         $tariffPlan->{$type} = $tariffs;
     }
     return $tariffPlan;
 }