コード例 #1
0
 public function deleteContextScript($contextscript)
 {
     $script = ContextScript::getContextScript($contextscript);
     if ($script === null || intval($script->id) <= 0) {
         return true;
     }
     //Check ownership
     if ($this->ownsScript($script) === false) {
         throw new Exception("Cannot remove contextualization script of a different software appliance");
     }
     //Remove contextscript association with context
     $assoc = $this->getScriptAssociation($script->id);
     if ($assoc !== null) {
         $assoc->getMapper()->delete($assoc);
     }
     //Remove vmi intances association with context script
     $images = new Default_Model_VMIinstanceContextScripts();
     $images->filter->contextscriptid->numequals($script->id);
     if (count($images->items) > 0) {
         foreach ($images->items as $item) {
             $images->remove($item);
         }
     }
     //Remove contextscript
     $scripts = new Default_Model_ContextScripts();
     $scripts->filter->id->equals($script->id);
     if (count($scripts->items) > 0) {
         ContextualizationStorage::remove($script, $this->entry, $this->user->id);
         $scripts->remove($scripts->items[0]);
     }
     $this->handleEntityRelations();
     $this->save();
     return true;
 }
コード例 #2
0
ファイル: globals.php プロジェクト: IASA-GR/appdb-core
 private static function removeRelatedScript($id, $script, $userid, $usetransaction = true)
 {
     try {
         $vmiinstanceid = 0;
         if ($usetransaction) {
             db()->beginTransaction();
         }
         $vmis = new Default_Model_VMIinstanceContextScripts();
         $vmis->filter->id->numequals($id);
         if (count($vmis->items) > 0) {
             $vmi = $vmis->items[0];
             if ($vmi->contextscriptid === $script->id) {
                 $vmiinstanceid = $vmi->vmiinstanceid;
                 $vmis->remove($vmi);
             }
         }
         $vmis = new Default_Model_VMIinstanceContextScripts();
         $vmis->filter->contextscriptid->numequals($script->id);
         if (count($vmis->items) === 0) {
             //The script is not longer used. Remove it.
             $scripts = new Default_Model_ContextScripts();
             $scripts->filter->id->numequals($script->id);
             if (count($scripts->items) > 0) {
                 VapplianceStorage::remove($scripts->items[0], $vmiinstanceid, $userid);
                 $scripts->remove($scripts->items[0]);
             }
         }
         if ($usetransaction) {
             db()->commit();
         }
     } catch (Exception $ex) {
         if ($usetransaction) {
             db()->rollback();
             return $ex->getMessage();
         } else {
             throw $ex;
         }
     }
     return true;
 }
コード例 #3
0
ファイル: vmcaster.php プロジェクト: IASA-GR/appdb-core
 private static function deleteContextScripts($vmiinstanceid)
 {
     $scriptids = array();
     $vmiscripts = new Default_Model_VMIinstanceContextScripts();
     $vmiscripts->filter->vmiinstanceid->numequals($vmiinstanceid);
     if (count($vmiscripts->items) > 0) {
         foreach ($vmiscripts->items as $item) {
             $scriptids[] = $item->contextscriptid;
             $vmiscripts->remove($item);
         }
     }
     $scriptids = array_unique($scriptids);
     //check if the referenced scripts have relations
     //if no relation found remove them from db.
     foreach ($scriptids as $id) {
         $vmiscripts = new Default_Model_VMIinstanceContextScripts();
         $vmiscripts->filter->contextscriptid->numequals($id);
         if (count($vmiscripts->items) === 0) {
             $scripts = new Default_Model_ContextScripts();
             $scripts->filter->id->numequals($id);
             if (count($scripts->items) > 0) {
                 $scripts->remove($scripts->items[0]);
             }
         }
     }
 }