wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.LogOutputStrategy.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.LogOutputStrategy.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/util/class.Log.php");
20 require_once(BASE."wcmf/lib/output/class.OutputStrategy.php");
21 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
22 require_once(BASE."wcmf/lib/security/class.RightsManager.php");
23 /**
24  * @class LogOutputStrategy
25  * @ingroup Output
26  * @brief This OutputStrategy outputs an object's content to the logger category
27  * LogOutputStrategy, loglevel info
28  * Used classes must implement the toString() method.
29  *
30  * @author ingo herwig <ingo@wemove.com>
31  */
33 {
34  /**
35  * Write the document header.
36  */
37  function writeHeader()
38  {
39  // do nothing
40  }
41  /**
42  * Write the document footer.
43  */
44  function writeFooter()
45  {
46  // do nothing
47  }
48  /**
49  * Write the objects content.
50  * @param obj The object to write.
51  */
52  function writeObject(&$obj)
53  {
54  $persistenceFacade = &PersistenceFacade::getInstance();
55  $rightsManager = &RightsManager::getInstance();
56  $user = &$rightsManager->getAuthUser();
57  switch ($state = $obj->getState())
58  {
59  // log insert action
60  case STATE_NEW:
61  Log::info('INSERT '.$obj->getOID().': '.str_replace("\n", " ", $obj->toString()).' USER: '.$user->getLogin(), __CLASS__);
62  break;
63  // log update action
64  case STATE_DIRTY:
65  // get old object from storage
66  $oldObj = &$persistenceFacade->load($obj->getOID(), BUILDDEPTH_SINGLE);
67  // collect differences
68  $values = array();
69  $valueNames = $obj->getValueNames();
70  foreach($valueNames as $name)
71  {
72  $values[$name]['name'] = $name;
73  $values[$name]['new'] = $obj->getValue($name);
74  $values[$name]['old'] = $oldObj->getValue($name);
75  }
76  // make diff string
77  $diff = '';
78  foreach ($values as $value)
79  if ($value['old'] != $value['new'])
80  $diff .= $value['name'].':'.$value['old'].'->'.$value['new'].' ';
81  Log::info('SAVE '.$obj->getOID().': '.$diff.' USER: '.$user->getLogin(), __CLASS__);
82  break;
83  // log delete action
84  case STATE_DELETE:
85  // get old object from storage
86  Log::info('DELETE '.$obj->getOID().': '.str_replace("\n", " ", $obj->toString()).' USER: '.$user->getLogin(), __CLASS__);
87  break;
88  }
89  }
90 }
91 ?>
const STATE_DIRTY
OutputStrategy is used to write an object's content to a destination (called 'document') using a spec...
info($message, $category)
Definition: class.Log.php:49
const STATE_NEW
This OutputStrategy outputs an object's content to the logger category LogOutputStrategy, loglevel info Used classes must implement the toString() method.
const BUILDDEPTH_SINGLE