Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_reset_hit_count.inc
1 <?php
16 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 
31 {
32 
33 
53  public static function execute($settings, &$state)
54  {
55  if (empty($state['asset'])) {
56  // grab the asset if assetid is given, but not the asset.
57  if (empty($state['assetid'])) {
58  return FALSE;
59  } else {
60  $state['asset'] = &$GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
61  }
62  }
63  if (is_null($state['asset'])) return FALSE;
64 
65  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
66  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
67 
68  // we need to check if there is already an entry in the DB
69  try {
70  $bind_vars = Array('assetid' => (string) $state['assetid']);
71  $asset_hit_count = MatrixDAL::executeAll('data_package', 'getHitCount', $bind_vars);
72  } catch (Exception $e) {
73  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
74  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
75  throw new Exception('Unable to reset hit count due to database error: '.$e->getMessage());
76  }
77 
78  // if there is already a entry in the DB we will remove it from the table
79  if (!empty($asset_hit_count)) {
80  try {
81  $bind_vars = Array('assetid' => (string) $state['assetid']);
82  $result = MatrixDAL::executeQuery('data_package', 'deleteHitCount', $bind_vars);
83  } catch (Exception $e) {
84  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
85  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
86  throw new Exception('Unable to decrement hit count due to database error: '.$e->getMessage());
87  }
88  }
89 
90  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
91  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
92 
93  }//end execute()
94 
95 
106  public static function getInterface($settings, $prefix, $write_access=FALSE)
107  {
108  // This trigger does not require any customisation from the details screen.
109  return FALSE;
110 
111  }//end getInterface()
112 
113 
125  public static function processInterface(&$settings, $request_data)
126  {
127  // This trigger does not use any settings, so we do not need to save.
128  return FALSE;
129 
130  }//end processInterface()
131 
132 
142  public static function getLocks($settings, &$state)
143  {
144  return Array($state['assetid'] => Array('lookups'));
145 
146  }//end getLocks()
147 
148 
149 }//end class
150 
151 ?>