fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

taskingelement.class.php
Go to the documentation of this file.
1 <?php
22 abstract class TaskingElement extends FOGBase
23 {
29  protected $Task;
35  protected $Image;
41  protected $StorageGroup;
47  protected $StorageNode;
53  protected $StorageNodes;
59  protected $imagingTask;
65  public function __construct()
66  {
67  parent::__construct();
68  try {
69  self::getHostItem(false);
70  $this->Task = self::$Host
71  ->get('task');
73  $this->Task,
74  self::$Host->get('name'),
75  self::$Host->get('mac')
76  );
77  $this->imagingTask = $this
78  ->Task
79  ->isImagingTask();
80  $this->StorageGroup = $this->StorageNode = null;
81  self::$HookManager->processEvent(
82  'HOST_NEW_SETTINGS',
83  array(
84  'Host' => &self::$Host,
85  'StorageNode' => &$this->StorageNode,
86  'StorageGroup' => &$this->StorageGroup
87  )
88  );
89  if (!$this->StorageGroup
90  || !$this->StorageGroup->isValid()
91  ) {
92  $this->StorageGroup = $this
93  ->Task
94  ->getStorageGroup();
95  }
96  if ($this->imagingTask) {
97  if (!$this->StorageNode
98  || !$this->StorageNode->isValid()
99  ) {
100  if ($this->Task->isCapture()
101  || $this->Task->isMulticast()
102  ) {
103  $this->StorageNode = $this
104  ->StorageGroup
105  ->getMasterStorageNode();
106  } else {
107  $this->StorageNode = $this
108  ->StorageGroup
109  ->getOptimalStorageNode();
110  }
111  }
113  $this->StorageGroup
114  );
116  $this->StorageGroup
117  );
118  $this->Image = $this
119  ->Task
120  ->getImage();
121  $getter = 'enablednodes';
122  if (count($this->StorageGroup->get($getter)) < 1) {
123  $getter = 'allnodes';
124  }
125  $this->StorageNodes = self::getClass('StorageNodeManager')
126  ->find(
127  array('id' => $this->StorageGroup->get($getter))
128  );
129  if ($this->Task->isCapture()
130  || $this->Task->isMulticast()
131  ) {
132  $this->StorageNode = $this
133  ->StorageGroup
134  ->getMasterStorageNode();
135  }
136  }
137  } catch (Exception $e) {
138  echo $e->getMessage();
139  exit;
140  }
141  }
153  protected static function checkTasking(
154  &$Task,
155  $name,
156  $mac
157  ) {
158  if (!$Task->isValid()) {
159  throw new Exception(
160  sprintf(
161  '%s: %s (%s)',
162  _('No Active Task found for Host'),
163  $name,
164  $mac
165  )
166  );
167  }
168  }
178  protected static function checkStorageGroup(&$StorageGroup)
179  {
180  if (!$StorageGroup->isValid()) {
181  throw new Exception(
182  _('Invalid Storage Group')
183  );
184  }
185  }
195  protected static function checkStorageNodes(&$StorageGroup)
196  {
197  $getter = 'enablednodes';
198  if (count($StorageGroup->get($getter)) < 1) {
199  $getter = 'allnodes';
200  }
201  if (count($StorageGroup->get($getter)) < 1) {
202  throw new Exception(
203  sprintf(
204  '%s, %s?',
205  _('Could not find a Storage Node in this group'),
206  _('is there one enabled')
207  )
208  );
209  }
210  }
219  protected static function nodeFail(
220  $StorageNode,
221  $Host
222  ) {
223  if ($StorageNode->getNodeFailure($Host)) {
224  $StorageNode = new StorageNode();
225  printf(
226  '%s %s (%s) %s.',
227  _('Storage Node'),
228  $StorageNode->get('name'),
229  $StorageNode->get('ip'),
230  sprintf(
231  '%s, %s',
232  _('is open'),
233  _('but has recently failed for this host')
234  )
235  );
236  }
237  return $StorageNode;
238  }
244  protected function taskLog()
245  {
246  return self::getClass('TaskLog', $this->Task)
247  ->set('taskID', $this->Task->get('id'))
248  ->set('taskStateID', $this->Task->get('stateID'))
249  ->set('createdTime', $this->Task->get('createdTime'))
250  ->set('createdBy', $this->Task->get('createdBy'))
251  ->save();
252  }
260  protected function imageLog($checkin = false)
261  {
262  if ($checkin === true) {
263  self::getClass('ImagingLogManager')
264  ->destroy(
265  array(
266  'hostID' => self::$Host->get('id'),
267  'finish' => '0000-00-00 00:00:00'
268  )
269  );
270  return self::getClass('ImagingLog')
271  ->set('hostID', self::$Host->get('id'))
272  ->set('start', self::formatTime('', 'Y-m-d H:i:s'))
273  ->set('image', $this->Image->get('name'))
274  ->set('type', $_REQUEST['type'])
275  ->set('createdBy', $this->Task->get('createdBy'))
276  ->save();
277  }
278  $ilID = self::getSubObjectIDs(
279  'ImagingLog',
280  array(
281  'hostID' => self::$Host->get('id'),
282  'finish' => '0000-00-00 00:00:00',
283  'image' => $this->Image->get('name'),
284  )
285  );
286  $ilID = @max($ilID);
287  return self::getClass('ImagingLog', $ilID)
288  ->set('finish', self::formatTime('', 'Y-m-d H:i:s'))
289  ->save();
290  }
291 }
TaskingElement\checkStorageNodes
static checkStorageNodes(&$StorageGroup)
Definition: taskingelement.class.php:195
exit
exit
Definition: download.php:102
TaskingElement\$StorageNode
$StorageNode
Definition: taskingelement.class.php:47
TaskType\isCapture
isCapture($nums=false)
Definition: tasktype.class.php:150
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
TaskingElement\nodeFail
static nodeFail( $StorageNode, $Host)
Definition: taskingelement.class.php:219
TaskingElement\$Image
$Image
Definition: taskingelement.class.php:35
TaskingElement
Definition: taskingelement.class.php:23
TaskingElement\$StorageNodes
$StorageNodes
Definition: taskingelement.class.php:53
Image
Definition: image.class.php:23
TaskingElement\$imagingTask
$imagingTask
Definition: taskingelement.class.php:59
FOGController\get
get($key='')
Definition: fogcontroller.class.php:207
TaskingElement\__construct
__construct()
Definition: taskingelement.class.php:65
$mac
$mac
Definition: hostinfo.php:151
TaskingElement\$StorageGroup
$StorageGroup
Definition: taskingelement.class.php:41
StorageNode
Definition: storagenode.class.php:23
Task
Definition: task.class.php:23
$Host
$Host
Definition: hostnameloop.php:30
FOGBase
Definition: fogbase.class.php:25
TaskingElement\taskLog
taskLog()
Definition: taskingelement.class.php:244
TaskingElement\checkTasking
static checkTasking(&$Task, $name, $mac)
Definition: taskingelement.class.php:153
TaskingElement\checkStorageGroup
static checkStorageGroup(&$StorageGroup)
Definition: taskingelement.class.php:178
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
FOGBase\getHostItem
static getHostItem( $service=true, $encoded=false, $hostnotrequired=false, $returnmacs=false, $override=false, $mac=false)
Definition: fogbase.class.php:503
StorageGroup
Definition: storagegroup.class.php:23
FOGBase\$Host
static $Host
Definition: fogbase.class.php:312
TaskingElement\imageLog
imageLog($checkin=false)
Definition: taskingelement.class.php:260
FOGController\isValid
isValid()
Definition: fogcontroller.class.php:865
TaskingElement\$Task
$Task
Definition: taskingelement.class.php:29