public function onAfterWrite()
 {
     parent::onAfterWrite();
     //create supported versions for not versioned components
     $supported_components = $this->owner->OpenStackComponents();
     if ($supported_components && count($supported_components) > 0) {
         $non_versioned_components = array();
         foreach ($supported_components as $component) {
             if (!$component->getSupportsVersioning()) {
                 //crete dumb version
                 array_push($non_versioned_components, $component->getIdentifier());
                 $old = $this->owner->SupportedApiVersions(" OpenStackComponentID = {$component->getIdentifier()} AND ApiVersionID = 0 ");
                 if (count($old) == 0) {
                     $new_supported_version = new OpenStackReleaseSupportedApiVersion();
                     $new_supported_version->OpenStackComponentID = $component->getIdentifier();
                     $new_supported_version->ReleaseID = $this->owner->getIdentifier();
                     $new_supported_version->ApiVersionID = 0;
                     $new_supported_version->write();
                 }
             }
         }
         $to_delete = "";
         if (count($non_versioned_components) > 0) {
             $to_delete = implode(',', $non_versioned_components);
             $to_delete = "AND OpenStackComponentID NOT IN ({$to_delete})";
         }
         DB::query("DELETE FROM OpenStackReleaseSupportedApiVersion WHERE ReleaseID = {$this->owner->getIdentifier()} AND ApiVersionID = 0 {$to_delete}");
     }
 }
 /**
  * @param $release_id
  * @param $component_id
  * @return IOpenStackApiVersion[]
  */
 public function getByReleaseAndComponent($release_id, $component_id)
 {
     $ds = OpenStackReleaseSupportedApiVersion::get()->filter(array('OpenStackComponentID' => $component_id, 'ReleaseID' => $release_id));
     $list = array();
     if ($ds) {
         foreach ($ds as $item) {
             array_push($list, $item->ApiVersion());
         }
     }
     return $list;
 }
 /**
  * @param IOpenStackRelease $release
  * @return IOpenStackRelease
  */
 public function cloneRelease(IOpenStackRelease $release)
 {
     return $this->tx_manager->transaction(function () use($release) {
         $clone = OpenStackRelease::create();
         $index = '';
         $idx = 0;
         do {
             $proposed_name = $release->Name . '-CLONE' . $index;
             ++$idx;
             $index = '-' . $idx;
         } while (intval(OpenStackRelease::get()->filter('Name', $proposed_name)->count()) > 0);
         $clone->Name = $proposed_name;
         $clone->Status = 'Future';
         $clone->write();
         //components
         foreach ($release->OpenStackComponents() as $component) {
             $clone->OpenStackComponents()->add($component);
         }
         //supported apis
         foreach ($release->SupportedApiVersions() as $api) {
             $new_api = OpenStackReleaseSupportedApiVersion::create();
             $new_api->OpenStackComponentID = $api->OpenStackComponentID;
             $new_api->ApiVersionID = $api->ApiVersionID;
             $new_api->ReleaseVersion = $api->ReleaseVersion;
             $new_api->ReleaseID = $clone->ID;
             $new_api->write();
         }
         //sample configurations
         foreach ($release->SampleConfigurationTypes() as $config_type) {
             $new_config_type = OpenStackSampleConfigurationType::create();
             $new_config_type->Type = $config_type->Type;
             $new_config_type->Order = $config_type->Order;
             $new_config_type->IsDefault = $config_type->IsDefault;
             $new_config_type->write();
             foreach ($config_type->SampleConfigurations() as $sample) {
                 $new_sample = OpenStackSampleConfig::create();
                 $new_sample->Title = $sample->Title;
                 $new_sample->Summary = $sample->Summary;
                 $new_sample->Description = $sample->Description;
                 $new_sample->IsDefault = $sample->IsDefault;
                 $new_sample->Order = $sample->Order;
                 $new_sample->CuratorID = $sample->CuratorID;
                 $new_sample->ReleaseID = $clone->ID;
                 $new_sample->write();
                 foreach ($sample->RelatedNotes() as $note) {
                     $new_note = OpenStackSampleConfigRelatedNote::create();
                     $new_note->Title = $note->Title;
                     $new_note->Link = $note->Link;
                     $new_note->Order = $note->Order;
                     $new_note->write();
                     $new_sample->RelatedNotes()->add($new_note);
                 }
                 foreach ($sample->OpenStackComponents() as $sample_comp) {
                     $new_sample->OpenStackComponents()->add($sample_comp, array('Order' => $sample_comp->Order));
                 }
                 $new_config_type->SampleConfigurations()->add($new_sample);
             }
             $clone->SampleConfigurationTypes()->add($new_config_type);
         }
         return $clone;
     });
 }
 /**
  * @param IOpenStackRelease    $release
  * @param IOpenStackComponent  $component
  * @param IOpenStackApiVersion $api_version
  * @return IReleaseSupportedApiVersion
  */
 public function buildReleaseSupportedApiVersion(IOpenStackRelease $release, IOpenStackComponent $component, IOpenStackApiVersion $api_version)
 {
     $supported_api = new OpenStackReleaseSupportedApiVersion();
     $supported_api->setRelease($release);
     $supported_api->setOpenStackComponent($component);
     $supported_api->setApiVersion($api_version);
     return $supported_api;
 }