コード例 #1
0
ファイル: IEHost.php プロジェクト: stpq/icinga_configurator
 /**
  * Smaže záznam
  */
 public function delete($id = null)
 {
     if (!is_null($id)) {
         $this->loadFromMySQL($id);
     }
     $hostGroup = new IEHostgroup();
     $hostGroup->deleteHost($this->getName());
     $delAll = true;
     $service = new IEService();
     $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . 'host_name' . ' LIKE \'%"' . $this->getName() . '"%\'', $service->myKeyColumn);
     foreach ($servicesAssigned as $ServiceID => $ServiceInfo) {
         $service->loadFromMySQL($ServiceID);
         $service->delHostName($this->getId(), $this->getName());
         if (!$service->saveToMySQL()) {
             $this->addStatusMessage(sprintf(_('Nepodařilo se odregistrovat %s ze služby %s'), $this->getName(), $service->getName()), 'Error');
             $delAll = false;
         }
     }
     $childsOfMe = $this->myDbLink->queryToArray('SELECT ' . $this->myKeyColumn . ',' . $this->nameColumn . ' FROM ' . $this->myTable . ' WHERE parents ' . ' LIKE \'%' . $this->getName() . '%\'', $this->myKeyColumn);
     foreach ($childsOfMe as $chid_id => $child_info) {
         $child = new IEHost($chid_id);
         if ($child->delMember('parents', $this->getId(), $this->getName()) && $child->saveToMySQL()) {
             $this->addStatusMessage(sprintf(_('%s již není rodičem %s'), $this->getName(), $child->getName()), 'success');
         } else {
             $this->addStatusMessage(sprintf(_('%s je stále rodičem %s'), $this->getName(), $child->getName()), 'warning');
         }
     }
     if ($delAll) {
         return parent::delete();
     }
     return false;
 }