UserDeleteObsolete.php 6.13 KB
<?php
/**
 * @class UserDeleteObsolete
 * @version $Id: UserDeleteObsolete.php 1808 2013-09-24 13:09:42Z elena $
 *
 */

 class UserDeleteObsolete {  

  private $dataset, $vi, $Mgr;
  private $ws_deleted;
   
  function __construct() {  
         
        $this->ws_deleted = array();
   }

    public function setVI($vi) {
        $this->vi = $vi;
        $this->dataset = strtolower($vi);   
    }


  public function deleteDerived() {

        $msg = '<b>WS (Derived) Params:</b><br/>';
    // derived parameters                
        $this->Mgr = new DerivedParamMgr('derivedParam');           
    // get params  
        $wsParams = $this->Mgr->contentDom->getElementsByTagName('param');
 
        if ($wsParams->length == 0) {
               return array('success' => true, 'msg' => 'No parameters');
        }
       
        foreach ($wsParams as $param) {        
            $id = $param->getAttribute('xml:id');
            $name = $param->getAttribute('name');
            $expression = $param->getAttribute('buildchain');
                 
            if (strpos(strtolower($expression), $this->dataset)) {
                    $msg .= 'deleted  name:<b>'.$name.'</b>; expression: '.$expression.'<br/>';
                    $obj = new stdClass();
                    $obj->leaf = true;
                    $obj->id = $id;
                    $this->Mgr->deleteObject($obj);
                 //   error_log( 'For INFO : DELETED '.$expression,1,email);
                    $this->ws_deleted[] = $name;                  
            }                      
        }
        $msg .= ' ok<br/>';
        return array('success' => true, 'msg' => $msg);
  }

   
 
  public function deleteConditions() {
     
    $msg = '<b>Conditions:</b><br/>';
    // conditons                
        $this->Mgr = new RequestMgr('condition');
        
        $conditions = $this->Mgr->contentDom->getElementsByTagName('condition');
 
        if ($conditions->length == 0) {
               return array('success' => true, 'msg' => 'No conditions');
        }
               
        foreach ($conditions as $item) {
            $id = $item->getAttribute('xml:id');
            $name = $item->getAttribute('name');

            $expression = strtolower($this->Mgr->getObject($id)->expression);
           
            if (strpos($expression, $this->dataset)) {
                    $obj = new stdClass();
                    $obj->leaf = true;
                    $obj->id = $id;
                    $this->Mgr->deleteObject($obj);
                    $msg .= 'deleted name:<b>'.$obj->name.'</b>; expression:'.$expression.'<br/>'; 
                   
            }        
        }

        $msg .= ' ok<br/>';

       return array('success' => true, 'msg' => $msg);
  }

    public function deleteRequests() {

       $msg = '<b>Requests:</b><br/>';
    // requests                
        $this->Mgr = new RequestMgr('request');      
        $requests = $this->Mgr->contentDom->getElementsByTagName('request');

        if (count($requests) == 0) {
            return array('success' => true, 'msg' => 'No requests');
        }

        foreach ($requests as $item) { 

            $id = $item->getAttribute('xml:id');
            $name = $item->getAttribute('name');

            $objplot = $this->Mgr->getObject($id); 
            $obj = new stdClass();
            $obj->leaf = true;
            $obj->id = $id;
                   
            foreach ($objplot->children as $panel) { 
                foreach ($panel->children as $param) {

                        $parID = strtolower($param->name);

                         if ($this->ws_deleted && substr($parId,0,3) == "ws_") {
                            if (array_search($this->ws_deleted, $parId)) {                               
                                    
                                    $this->Mgr->deleteObject($obj);
                                    $msg .=    'request deleted  '.$name.'<br/>';
                                    continue 3;                                
                            }
                        }
                        
                        if (strpos($parID, $this->dataset)) {
                            $this->Mgr->deleteObject($obj);
                            $msg .=    'request deleted  '.$name.'<br/>'; 
                            continue 3;
                        }   
                    }
                }                          
         }                    
        $msg .= ' ok<br/>';

  return array('success' => true, 'msg' => $msg);
  }

  public function deleteAliases() {
    
     $msg = '<b>Aliases:</b><br/>';
     $this->Mgr = new AliasMgr();  
     $aliases = $this->Mgr->contentDom->getElementsByTagName('alias');
      
      foreach ($aliases as $alias) {
            $id = $alias->getAttribute('xml:id'); 
            $name = $alias->getAttribute('name'); 
            if (strpos(strtolower($id), $this->dataset)) {
                $obj = new stdClass();
                $obj->leaf = true;
                $obj->id = $id;
                $this->Mgr->deleteObject($obj);
                $msg .= 'alias deleted  '.$name.'<br/>'; 
            }
       }
     return array('success' => true, 'msg' => $msg);
  }


  public function deleteInTree() {
          
        $msg = '<b>Dataset in RemoteParams:</b><br/>';

        $this->Mgr = new ParamMgr();        
        $xp = new domxpath($this->Mgr->xmlDom);
 
        $nodeToDelete = $xp->query("//dataset[@name='".$this->vi."']");
        if ($nodeToDelete->length > 0) {
            $instrNode = $nodeToDelete->item(0)->parentNode;
            $instrNode->removeChild($nodeToDelete->item(0));
            if (!$instrNode->hasChildNodes()) {
                $missionNode = $instrNode->parentNode;
                $missionNode->removeChild($instrNode);
                if (!$missionNode->hasChildNodes()) {
                   $datacenterNode = $missionNode->parentNode;
                   $datacenterNode->removeChild($missionNode); 
                }
            }
            
            $this->Mgr->xmlDom->save($this->Mgr->xmlName);
            $msg .= 'dataset deleted  '.$this->vi.'<br/>'; 
        }
         return array('success' => true, 'msg' => $msg);
  }
}
?>