Blame view

php/classes/UserDeleteObsolete.php 4.85 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
<?php
/**
 * @class UserDeleteObsolete
 * @version $Id: UserDeleteObsolete.php 1808 2013-09-24 13:09:42Z elena $
 *
 */

08a89462   Elena.Budnik   convert old user ws
8
class UserDeleteObsolete {  
16035364   Benjamin Renard   First commit
9

08a89462   Elena.Budnik   convert old user ws
10
11
	private $dataset, $vi, $Mgr;
	private $ws_deleted;
16035364   Benjamin Renard   First commit
12
   
08a89462   Elena.Budnik   convert old user ws
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	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);
	}
16035364   Benjamin Renard   First commit
52
 
08a89462   Elena.Budnik   convert old user ws
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	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;
16035364   Benjamin Renard   First commit
105
                   
08a89462   Elena.Budnik   convert old user ws
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
			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);
	}
16035364   Benjamin Renard   First commit
173
174
}
?>