当前位置: 首页>>代码示例>>PHP>>正文


PHP Host::addModule方法代码示例

本文整理汇总了PHP中Host::addModule方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::addModule方法的具体用法?PHP Host::addModule怎么用?PHP Host::addModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Host的用法示例。


在下文中一共展示了Host::addModule方法的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();
 }
开发者ID:bramverstraten,项目名称:fogproject,代码行数:72,代码来源:HostManagementPage.class.php

示例2: 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) {
     print $e->getMessage();
 }
开发者ID:bramverstraten,项目名称:fogproject,代码行数:31,代码来源:auto.register.php


注:本文中的Host::addModule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。