/**
  * creates a new object log controller
  * @return ObjectLogController	ObjectLogController instance
  */
 public static function create()
 {
     //check, if an ObjectLogController instance already exists
     if (ObjectLogController::$objectLogController == null) {
         ObjectLogController::$objectLogController = new ObjectLogController();
     }
     return ObjectLogController::$objectLogController;
 }
 public function getResource()
 {
     $objectController = ObjectController::create();
     $objectLogController = ObjectLogController::create();
     //try to get object log
     try {
         $objectId = $this->uri[1];
         $object = $objectController->getObject($objectId, $this->user);
         $objectLogEntries = $objectLogController->getLogEntries($object, 0, 0, $this->user);
         //generate output
         $output = array();
         $output['objectId'] = $objectId;
         $output['logEntries'] = array();
         foreach ($objectLogEntries as $logEntry) {
             $output['logEntries'][] = array('date' => $logEntry->getTimestamp(), 'action' => $logEntry->getAction(), 'description' => $logEntry->getDescription(), 'user' => $logEntry->getUser());
         }
     } catch (Exception $e) {
         return new RestResponse(404);
     }
     return new RestResponse(200, json_encode($output));
 }
Beispiel #3
0
use yourCMDB\security\AuthorisationProviderLocal;
use yourCMDB\taskscheduler\EventProcessor;
use yourCMDB\info\InfoController;
//define base directories
$webScriptBaseDir = dirname(__FILE__);
$coreBaseDir = realpath("{$webScriptBaseDir}/../../core");
//include yourCMDB bootstrap
include "{$coreBaseDir}/bootstrap.php";
//include function definitions
include "functions.inc.php";
//define variables
$config = CmdbConfig::create();
$accessGroupController = AccessGroupController::create();
$objectController = ObjectController::create();
$objectLinkController = ObjectLinkController::create();
$objectLogController = ObjectLogController::create();
$authorisationProvider = new AuthorisationProviderLocal();
$eventProcessor = new EventProcessor();
$infoController = new InfoController();
//set default values of some variables
$authUser = "";
//get configuration
$installTitle = $config->getViewConfig()->getInstallTitle();
//setup i18n with gettext
$i18nLocale = $config->getViewConfig()->getLocale();
$i18nDomain = "web";
$i18nCodeset = "utf-8";
$i18nBaseDir = realpath("{$webScriptBaseDir}/../../i18n");
setlocale(LC_ALL, $i18nLocale);
bindtextdomain($i18nDomain, $i18nBaseDir);
bind_textdomain_codeset($i18nDomain, $i18nCodeset);
 /**
  * Deletes all CmdbObjectLinks for a given CmdbObject
  * @param CmdbObject $object	the CmdbObject
  * @param string $user		name of the user
  * @throws CmdbObjectLinkNotFoundException
  */
 public function deleteObjectLinks($object, $user)
 {
     //get ObjectLogController
     $objectLogController = ObjectLogController::create();
     //find the links
     $links = $this->getObjectLinks($object, $user);
     foreach ($links as $link) {
         //remove the link
         $this->entityManager->remove($link);
         //create log entry
         $objectA = $link->getObjectA();
         $objectB = $link->getObjectB();
         $logString = $objectA->getId() . " <-> " . $objectB->getId();
         $objectLogController->addLogEntry($objectA, "delete link", $logString, $user);
         $objectLogController->addLogEntry($objectB, "delete link", $logString, $user);
     }
     //flush output
     $this->entityManager->flush();
 }
Beispiel #5
0
 /**
  * Deletes the CmdbObject with the given ID
  * @param int $id	ID of the CmdbObject
  * @param string	$user		name of user that wishes the change
  * @throws CmdbObjectNotFoundException
  */
 public function deleteObject($id, $user)
 {
     //get object and references
     $object = $this->getObject($id, $user);
     $references = $this->getObjectReferences($id, $user);
     //remove object links
     $objectLinkController = ObjectLinkController::create();
     $objectLinkController->deleteObjectLinks($object, $user);
     //remove log entries
     $objectLogController = ObjectLogController::create();
     $objectLogController->deleteLogEntries($object, $user);
     //process event
     $eventProcessor = new EventProcessor();
     $eventProcessor->generateEvent("objectDeleted", $object->getId(), $object->getType());
     //remove the object
     $this->entityManager->remove($object);
     //flush
     $this->entityManager->flush();
     //delete references to object
     foreach ($references as $reference) {
         $this->updateObject($reference->getId(), $reference->getStatus(), array(), $user);
     }
 }