* - beforeInsert($request,$roo) - before insert - jerr() will stop insert..
*
* AFTER
- * - onUpdate($old, $request,$roo) - after update // return value ignored
- * - onInsert($request,$roo) - after insert
+ * - onUpdate($old, $request,$roo, $event) - after update // return value ignored
+ * - onInsert($request,$roo, $event) - after insert
* - onDelete($req, $roo) - after delete
* - onUpload($roo)
*
var $key; // used by update currenly to store primary key.
- var $transObj = false ; // the transaction BEGIN / ROLLBACK / COMMIT Dataobject.
-
+
var $max_limit = 10000;
var $debugEnabled = true; // disable this for public versions of this code.
return true;
}
/**
- * GET method Roo/TABLENAME.php
+ * GET method Roo/TABLENAME
*
* Generally for SELECT or Single SELECT
*
*/
function get($tab, $opts = Array())
{
-
// $this->jerr("Not authenticated", array('authFailure' => true));
//echo '<PRE>';print_R($_GET);
//DB_DataObject::debuglevel(1);
$this->sessionState(0);
$res = $x->find();
$this->sessionState(1);
-
+
if (false === $res) {
$this->jerr($x->_lastError->toString());
$this->init(); // for pman.
$x = $this->dataObject($tab);
-
+
$this->transObj = clone($x);
$this->transObj->query('BEGIN');
// do we really delete stuff!?!?!?
return $this->delete($x,$_REQUEST);
}
-
+
+
+
$old = false;
// not sure if this is a good idea here...
-
+
if (!empty($_REQUEST['_ids'])) {
$ids = explode(',',$_REQUEST['_ids']);
$x->whereAddIn($this->key, $ids, 'int');
$ar = $x->fetchAll();
foreach($ar as $x) {
- $this->update($x, $_REQUEST);
-
+ $this->update($x, $_REQUEST);
}
// all done..
$this->jok("UPDATED");
}
- if (!empty($_REQUEST[$this->key])) {
+ if (!empty($_REQUEST[$this->key])) {
// it's a create..
if (!$x->get($this->key, $_REQUEST[$this->key])) {
$this->jerr("Invalid request (id does not point to a record.)");
if (empty($_POST)) {
$this->jerr("No data recieved for inserting");
}
-
+
$this->jok($this->insert($x, $_REQUEST));
}
} else if (method_exists($x, 'applyFilters')) {
// always call apply filters even after update/insert...
// however arguments are not passed.
- $x->applyFilters(array(), $this->authUser, $this);
+ $x->applyFilters(array('_is_update_request' => true), $this->authUser, $this);
}
// DB_DataObject::DebugLevel(1);
}
$res = $x->insert();
+
if ($res === false) {
$this->jerr($x->_lastError->toString());
}
+ $ev = $this->addEvent("ADD", $x);
if (method_exists($x, 'onInsert')) {
- $x->onInsert($_REQUEST, $this);
+ $x->onInsert($_REQUEST, $this, $ev);
}
- $ev = $this->addEvent("ADD", $x);
+
if ($ev) {
$ev->audit($x);
}
//print_r($old);
$cols = $x->tableColumns();
- //print_r($cols);
+
if (isset($cols['modified'])) {
$x->modified = date('Y-m-d H:i:s');
}
if ($res === false) {
$this->jerr($x->_lastError->toString());
}
-
+ $ev = $this->addEvent("EDIT", $x);
+
if (method_exists($x, 'onUpdate')) {
- $x->onUpdate($old, $req, $this);
+ $x->onUpdate($old, $req, $this, $ev);
}
- $ev = $this->addEvent("EDIT", $x);
if ($ev) {
$ev->audit($x, $old);
}
*/
function delete($x, $req)
- {
+ {
// do we really delete stuff!?!?!?
if (empty($req['_delete'])) {
$this->jerr("Delete Requested with no value");
}
+
+
// build a list of tables to queriy for dependant data..
$map = $x->links();
// echo '<PRE>';print_r($affects);exit;
// DB_Dataobject::debugLevel(1);
-
+
$bits = array_map(function($v) { return (int)$v; } , explode(',', $req['_delete']));
$match_ar = array();
foreach($affects as $k=> $true) {
$ka = explode('.', $k);
+
$chk = DB_DataObject::factory($ka[0]);
if (!is_a($chk,'DB_DataObject') && !is_a($chk,'PDO_DataObject')) {
$this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
continue;
}
}
-
+
+
$has_beforeDelete = method_exists($xx, 'beforeDelete');
// before delte = allows us to trash dependancies if needed..
$match_total = 0;
- var_dump($match_ar);
+
if ( $has_beforeDelete ) {
if ($xx->beforeDelete($match_ar, $this) === false) {
$errs[] = "Delete failed ({$xx->id})\n".
if (!is_a($chk,'DB_DataObject') && !is_a($chk,'PDO_DataObject')) {
$this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
}
- $chk->{$ka[1]} = $xx->{$this->key};
+ $chk->{$ka[1]} = $xx->{$this->key};
$matches = $chk->count();
$match_total += $matches;
if ($matches) {
}
- //
-
if (!empty($match_ar)) {
$chk = $match_ar[0];
$chk->limit(1);
$q_filtered = array();
$keys = $x->keys();
- // var_dump($keys);exit;
+
foreach($q as $key=>$val) {
if (in_array($key,$keys) && !is_array($val)) {
}
-
+
switch($key) {
}
-
- // our handlers to commit / rollback.
-
- function jok($str)
- {
- // note that commit will only work if an insert/update was done,
- // so some stored proc calls may not have flagged this.
-
- if ($this->transObj ) {
- $this->transObj->query( connection_aborted() ? 'ROLLBACK' : 'COMMIT');
- }
- return parent::jok($str);
- }
-
-
- function jerr($str, $errors=array(), $content_type = false)
- {
- // standard error reporting..
- if ($this->transObj) {
- $this->transObj->query('ROLLBACK');
- }
- return parent::jerr($str,$errors,$content_type);
-
- }
-
-