3
* Copyright (c) 2008 Zivios, LLC.
5
* This file is part of Zivios.
7
* Zivios is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* Zivios is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Zivios. If not, see <http://www.gnu.org/licenses/>.
20
* @package Transaction
21
* @copyright Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
22
* @license http://www.zivios.org/legal/license
23
* @version $Id: Item.php 943 2008-08-26 10:50:52Z fkhan $
26
class Ecl_Transaction_Item
29
private $rollbackarray, $objarray, $description, $status;
31
const STATUS_FAILED=1;
32
const STATUS_COMPLETE=2;
35
public function __construct($description='')
37
$this->codearray = array();
38
$this->objarray = array();
39
$this->description=$description;
40
$this->status = self::STATUS_READY;
43
public function getDescription()
45
return $this->description;
48
public function getObject($name)
50
return $this->objarray[$name];
53
public function addObject($id,$object)
56
if (array_key_exists($id,$this->objarray))
57
throw new Ecl_Exception("Object key " . $id . " exists, will not override");
59
$this->objarray[$id] = 1;
64
public function getCodeArray()
66
return $this->codearray;
69
public function addCommitLine($line)
71
$bt = debug_backtrace();
72
$class = $bt[2]['class'];
75
Ecl_Log::debug($class . " (" . $ln .") :::: code ::: " . $line);
77
$this->codearray[] = $line;
80
public function addRollbackLine($line)
82
$this->rollbackarray[] = $line;
85
public function commit()
88
* Setup objects first, their id's being variable names
91
foreach ($this->codearray as $code) {
92
Ecl_Log::debug('evaluating : ' . $code);
94
$retval = eval($code);
95
Ecl_Log::debug("eval returned " . $retval);
97
if ($retval === FALSE) {
98
Ecl_Log::debug("Returning FALSE as eval outpt");
99
$this->status = self::STATUS_FAILED;
102
$this->status = self::STATUS_COMPLETE;
105
* Hardcoded check to return unless there is an exception
110
public function markFailed()
112
$this->status = self::STATUS_FAILED;
115
public function getStatus()
117
return $this->status;
120
public function rollback()
122
if ($this->status == self::STATUS_COMPLETE) {
123
foreach ($this->rollbackarray as $code) {
124
Ecl_Log::debug('ROLLBACK* evaluating : ' . $code);
125
if (eval($code) === FALSE)
131
Ecl_Log::info("Item did not succeed, skipping rollback");