本文整理汇总了PHP中Host::addPriMAC方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::addPriMAC方法的具体用法?PHP Host::addPriMAC怎么用?PHP Host::addPriMAC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::addPriMAC方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import_post
/** import_post()
Actually imports the post.
*/
public function import_post()
{
try {
// Error checking
if ($_FILES["file"]["error"] > 0) {
throw new Exception(sprintf('Error: ' . (is_array($_FILES["file"]["error"]) ? implode(', ', $_FILES["file"]["error"]) : $_FILES["file"]["error"])));
}
if (!file_exists($_FILES["file"]["tmp_name"])) {
throw new Exception('Could not find tmp filename');
}
$numSuccess = $numFailed = $numAlreadyExist = 0;
$handle = fopen($_FILES["file"]["tmp_name"], "r");
// Get all the service id's so they can be enabled.
$ModuleIDs = $this->getClass('ModuleManager')->find('', '', '', '', '', '', '', 'id');
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// Ignore header data if left in CSV
if (preg_match('#ie#', $data[0])) {
continue;
}
$totalRows++;
if (count($data) < 7 && count($data) >= 2) {
try {
// Error checking
$MACs = $this->parseMacList($data[0]);
$Host = $this->getClass('HostManager')->getHostByMacAddresses($MACs);
if ($Host && $Host->isValid()) {
throw new Exception('A Host with any or one of these MACs already exists');
}
if ($this->getClass('HostManager')->exists($data[1])) {
throw new Exception('A host with this name already exists');
}
$Host = new Host(array('name' => $data[1], 'description' => $data[3] . ' Uploaded by batch import on', 'ip' => $data[2], 'imageID' => $data[4], 'createdTime' => $this->nice_date()->format('Y-m-d H:i:s'), 'createdBy' => $this->FOGUser->get('name')));
$Host->addModule($ModuleIDs);
$Host->addPriMAC($MACs[0]);
array_shift($MACs);
$Host->addAddMAC($MACs);
if ($Host->save()) {
$this->HookManager->processEvent('HOST_IMPORT', array('data' => &$data, 'Host' => &$Host));
$numSuccess++;
} else {
$numFailed++;
}
} catch (Exception $e) {
$numFailed++;
$uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, $e->getMessage());
}
} else {
$numFailed++;
$uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, _('Invalid number of cells'));
}
}
fclose($handle);
} catch (Exception $e) {
$error = $e->getMessage();
}
// Title
$this->title = _('Import Host Results');
unset($this->headerData);
$this->attributes = array(array(), array());
$this->templates = array('${field}', '${input}');
$fields = array(_('Total Rows') => $totalRows, _('Successful Hosts') => $numSuccess, _('Failed Hosts') => $numFailed, _('Errors') => $uploadErrors);
foreach ((array) $fields as $field => $input) {
$this->data[] = array('field' => $field, 'input' => $input);
}
// Hook
$this->HookManager->processEvent('HOST_IMPORT_FIELDS', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
// Output
$this->render();
}
示例2: Exception
throw new Exception(_('Failed to save new Host!'));
}
if ($Image->isValid() && $Host->getImageMemberFromHostID()) {
if ($Host->createImagePackage(1, 'AutoRegTask')) {
print _('Done, with imaging!');
} else {
print _('Done, but unable to create task!');
}
} else {
print _('Done!');
}
} else {
$realhost = $macsimple;
if (!$Host || !$Host->isValid()) {
$Host = new Host(array('name' => $realhost, 'description' => sprintf('%s %s', _('Created by FOG Reg on'), date('F j, Y, g:i a')), 'createdTime' => $FOGCore->formatTime('now', 'Y-m-d H:i:s'), 'createdBy' => 'FOGREG'));
$Host->addPriMAC($PriMAC);
$Host->addAddMAC($MACs);
$Host->addModule($ids);
if (!$Host->save()) {
throw new Exception(_('Failed to save new Host!'));
}
print _('Done');
} else {
print _('Already registered as') . ': ' . $Host->get('name');
}
}
} else {
print _('Already registered as') . ': ' . $Host->get('name');
}
}
} catch (Exception $e) {