$Task = $Host->get('task'); if (!$Task->isValid()) { throw new Exception(sprintf('%s: %s (%s)', _('No Active Task found for Host'), $Host->get('name'), $Host->get('mac'))); } // Set the task to state 4 if (!in_array($Task->get('typeID'), array(12, 13))) { $Task->set('stateID', '4')->set('pct', '100')->set('percent', '100'); } // Log it $ImagingLogs = $FOGCore->getClass('ImagingLogManager')->find(array('hostID' => $Host->get('id'))); foreach ($ImagingLogs as $ImagingLog) { $id[] = $ImagingLog->get('id'); } // Update Last deploy $Host->set('deployed', date('Y-m-d H:i:s'))->save(); $il = new ImagingLog(max($id)); $il->set('finish', date('Y-m-d H:i:s'))->save(); // Task Logging. $TaskLog = new TaskLog($Task); $TaskLog->set('taskID', $Task->get('id'))->set('taskStateID', $Task->get('stateID'))->set('createdTime', $Task->get('createdTime'))->set('createdBy', $Task->get('createdBy'))->save(); if (!$Task->save()) { $EventManager->notify('HOST_IMAGE_Fail', array(HostName => $Host->get('name'))); throw new Exception('Failed to update task.'); } $EventManager->notify('HOST_IMAGE_COMPLETE', array(HostName => $Host->get('name'))); ////============================== Email Notification Start ============================== if ($FOGCore->getSetting('FOG_EMAIL_ACTION')) { $Inventory = current($FOGCore->getClass('InventoryManager')->find(array('hostID' => $Host->get('id')))); //Get inventory Data if ($Inventory && $Inventory->isValid()) { $SnapinJob = $Host->get('snapinjob');
// If client count is equal, place session task in-progress as it will likely start soon. if ($MSAs == $MultiSess->get('clients') || $MultiSess->get('sessclients') > 0 && $MultiSess->get('clients') > 0) { $MultiSess->set('stateID', 3); } else { $MultiSess->set('stateID', 1); } } // Save the info. if ($Task->save() && ($Task->get('typeID') == 8 ? $MultiSess->save() : true)) { if ($MultiSess && $MultiSess->isValid()) { $Host->set('imageID', $MultiSess->get('image')); } // Log it $ImagingLogs = $FOGCore->getClass('ImagingLogManager')->find(array('hostID' => $Host->get('id'), 'type' => $_REQUEST['type'], 'complete' => '0000-00-00 00:00:00')); foreach ($ImagingLogs as $ImagingLog) { $id[] = $ImagingLog->get('id'); } if (!$id) { $il = new ImagingLog(array('hostID' => $Host->get('id'), 'start' => $FOGCore->nice_date()->format('Y-m-d H:i:s'), 'image' => $Task->getImage()->get('name'), 'type' => $_REQUEST['type'])); } else { $il = new ImagingLog(max($id)); $il->set('start', $FOGCore->nice_set()->format('Y-m-d H:i:s')); } $il->save(); $TaskLog = new TaskLog(array('taskID' => $Task->get('id'), 'taskStateID' => $Task->get('stateID'), 'createdTime' => $Task->get('createdTime'), 'createdBy' => $Task->get('createdBy'))); $TaskLog->save(); print '##@GO'; } } catch (Exception $e) { print $e->getMessage(); }