Skip to content

Commit

Permalink
SaveRelationship now returns boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
klederson committed May 10, 2012
1 parent c879ae6 commit 46d81e4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/generator/structure/config.php
Expand Up @@ -19,7 +19,7 @@
################################ ################################
# Getting current session if exists # Getting current session if exists
################################ ################################
session_name(PHPBURN_SESSIONNAME); session_name(SYS_SESSION_NAME);
session_start(); session_start();




Expand Down
2 changes: 1 addition & 1 deletion app/generator/structure/sysConfig.php
Expand Up @@ -54,7 +54,7 @@
################################ ################################
# Infos # Infos
################################ ################################
define('PHPBURN_SESSIONNAME', md5(SYS_BASE_PATH), true); define('SYS_SESSION_NAME', md5(SYS_BASE_PATH), true);
define('PHPBURN_VERSION','0.9b',true); define('PHPBURN_VERSION','0.9b',true);
define('PHPBURN_WEBSITE','http://www.phpburn.com/',true); define('PHPBURN_WEBSITE','http://www.phpburn.com/',true);
define('PHPBURN_REPOSITORY_TYPE','git',true); define('PHPBURN_REPOSITORY_TYPE','git',true);
Expand Down
Expand Up @@ -38,7 +38,7 @@
'defaultType' => 'unknown', 'defaultType' => 'unknown',


'authInfo' => array( 'authInfo' => array(
'allowedMethods' => &$_SESSION['phpburn']['userInfo']['allowedMethods'] 'allowedMethods' => &$_SESSIONSYS_SESSION_NAME['userInfo']['allowedMethods']
) )
); );


Expand Down
2 changes: 1 addition & 1 deletion app/libs/Connection/MySQL.php
Expand Up @@ -354,7 +354,7 @@ public function executeSQL($sql)
{ {
$msg = "[!Database error:!] " . $this->getErrorMsg(); $msg = "[!Database error:!] " . $this->getErrorMsg();
PhpBURN_Message::output($msg, PhpBURN_Message::ERROR); PhpBURN_Message::output($msg, PhpBURN_Message::ERROR);
return false; return FALSE;
//$this->dispatchEvent('onExecuteError', $this, $sql, $msg); //$this->dispatchEvent('onExecuteError', $this, $sql, $msg);
} }
//$this->close(); //$this->close();
Expand Down
48 changes: 24 additions & 24 deletions app/libs/Connection/MySQLi.php 100755 → 100644
Expand Up @@ -16,7 +16,7 @@
* @author Klederson Bueno Bezerra da Silva * @author Klederson Bueno Bezerra da Silva
* *
*/ */
class PhpBURN_Connection_MySQL implements IConnection class PhpBURN_Connection_MySQLi implements IConnection
{ {


const CLOSED = 100201; const CLOSED = 100201;
Expand Down Expand Up @@ -52,7 +52,7 @@ static public function getInstance()
{ {
if(self::$instance == null) if(self::$instance == null)
{ {
self::$instance = new PhpBURN_Connection_MySQL(); self::$instance = new PhpBURN_Connection_MySQLi();
} }


return self::$instance; return self::$instance;
Expand All @@ -63,7 +63,7 @@ public function connect()


if($this->conn_id && $this->state == self::OPEN) if($this->conn_id && $this->state == self::OPEN)
{ {
mysql_select_db($this->getDatabase(), $this->conn_id); mysqli_select_db($this->conn_id,$this->getDatabase());
return true; return true;
} }


Expand All @@ -82,9 +82,9 @@ public function connect()


if(isset($this->options['persistent']) && $this->options['persistent'] == true) if(isset($this->options['persistent']) && $this->options['persistent'] == true)
{ {
$this->conn_id = @mysql_pconnect($hostString, $this->getUser(), $this->getPassword(), $flags); $this->conn_id = @mysqli_pconnect($hostString, $this->getUser(), $this->getPassword(), $flags);
} else { } else {
$this->conn_id = @mysql_connect($hostString, $this->getUser(), $this->getPassword(), $flags); $this->conn_id = @mysqli_connect($hostString, $this->getUser(), $this->getPassword(), $flags);
} }


if( !$this->conn_id ) if( !$this->conn_id )
Expand All @@ -97,7 +97,7 @@ public function connect()
} }


//Selecting database //Selecting database
mysql_select_db($this->getDatabase(), $this->conn_id); mysqli_select_db($this->conn_id,$this->getDatabase());
$this->state = self::OPEN; $this->state = self::OPEN;


//TODO onConnectSucess actions should be called from here //TODO onConnectSucess actions should be called from here
Expand All @@ -111,7 +111,7 @@ public function close()
if($this->conn_id && $this->state != self::CLOSED) if($this->conn_id && $this->state != self::CLOSED)
{ {
$this->state = self::CLOSED; $this->state = self::CLOSED;
mysql_close($this->conn_id); mysqli_close($this->conn_id);
} }
//$this->dispatchEvent('posClose', $this); //$this->dispatchEvent('posClose', $this);
} }
Expand Down Expand Up @@ -196,9 +196,9 @@ public function getErrorMsg()
$msg = ''; $msg = '';
if($this->conn_id) if($this->conn_id)
{ {
$msg = mysql_error($this->conn_id); $msg = mysqli_connect_error();
} else { } else {
$msg = mysql_error(); $msg = mysqli_connect_error();
} }
return $msg; return $msg;
} }
Expand All @@ -214,7 +214,7 @@ public function getTables()


$list = array(); $list = array();


while($row = mysql_fetch_row($rs)) while($row = mysqli_fetch_row($rs))
{ {
$list[] = $row[0]; $list[] = $row[0];
} }
Expand All @@ -232,7 +232,7 @@ public function getForeignKeys($tablename)
$fks = array(); $fks = array();
$sql = sprintf("SHOW CREATE TABLE `%s`",$tablename); $sql = sprintf("SHOW CREATE TABLE `%s`",$tablename);
$rs = $this->executeSQL($sql); $rs = $this->executeSQL($sql);
$result = mysql_fetch_row($rs); $result = mysqli_fetch_row($rs);
$result[0] = preg_replace("(\r|\n)",'\n', $result[0]); $result[0] = preg_replace("(\r|\n)",'\n', $result[0]);


$matches = array(); $matches = array();
Expand Down Expand Up @@ -280,17 +280,17 @@ public function getServerInfo($type = null)
switch($type) switch($type)
{ {
case self::CLIENT_VERSION: case self::CLIENT_VERSION:
return mysql_get_client_info(); return mysqli_get_client_info();
break; break;
case self::HOST_INFO: case self::HOST_INFO:
return mysql_get_host_info($this->conn_id); return mysqli_get_host_info($this->conn_id);
break; break;
case self::PROTOCOL_VERSION: case self::PROTOCOL_VERSION:
return mysql_get_proto_info($this->conn_id); return mysqli_get_proto_info($this->conn_id);
break; break;
case self::SERVER_VERSION: case self::SERVER_VERSION:
default: default:
return mysql_get_server_info($this->conn_id); return mysqli_get_server_info($this->conn_id);
break; break;
} }
return ''; return '';
Expand All @@ -305,7 +305,7 @@ public function describe($tablename)
$rs = $this->executeSQL( $sql ); $rs = $this->executeSQL( $sql );


$data = array(); $data = array();
while($row = mysql_fetch_row($rs)) while($row = mysqli_fetch_row($rs))
{ {
$name = $row[0]; $name = $row[0];
$type_native = $row[1]; $type_native = $row[1];
Expand Down Expand Up @@ -345,7 +345,7 @@ public function executeSQL($sql)
{ {
//$this->dispatchEvent('preExecute', $this, $sql); //$this->dispatchEvent('preExecute', $this, $sql);
$this->connect(); $this->connect();
$rs = @mysql_query($sql, $this->conn_id); $rs = @mysqli_query($sql, $this->conn_id);
if( ! $rs ) if( ! $rs )
{ {
$msg = "[!Database error:!] " . $this->getErrorMsg(); $msg = "[!Database error:!] " . $this->getErrorMsg();
Expand All @@ -361,7 +361,7 @@ public function executeSQL($sql)
public function unbuffExecuteSQL($sql) { public function unbuffExecuteSQL($sql) {
//$this->dispatchEvent('preExecute', $this, $sql); //$this->dispatchEvent('preExecute', $this, $sql);
$this->connect(); $this->connect();
$rs = @mysql_unbuffered_query($sql, $this->conn_id); $rs = @mysqli_unbuffered_query($sql, $this->conn_id);
if( ! $rs ) if( ! $rs )
{ {
$msg = "[!Database error:!] " . $this->getErrorMsg(); $msg = "[!Database error:!] " . $this->getErrorMsg();
Expand All @@ -378,9 +378,9 @@ public function escape($str)
{ {
if($this->state == self::OPEN) if($this->state == self::OPEN)
{ {
return mysql_real_escape_string($str, $this->conn_id); return mysqli_real_escape_string($str, $this->conn_id);
} else { } else {
return mysql_escape_string($str); return mysqli_escape_string($str);
} }
} }


Expand All @@ -397,14 +397,14 @@ public function affected_rows()
{ {
if($this->state == self::OPEN) if($this->state == self::OPEN)
{ {
return mysql_affected_rows($this->conn_id); return mysqli_affected_rows($this->conn_id);
} }
//throw new PhpBURN_Exception() TODO CREATE EXCETION CLASS AND INPUT AN EXCEPTION HERE; //throw new PhpBURN_Exception() TODO CREATE EXCETION CLASS AND INPUT AN EXCEPTION HERE;
} }


public function num_rows($rs) public function num_rows($rs)
{ {
return mysql_num_rows($rs); return mysqli_num_rows($rs);
} }


public function random() public function random()
Expand All @@ -418,7 +418,7 @@ public function getEscapeChar()
} }


public function fetch($rs) { public function fetch($rs) {
return mysql_fetch_array($rs, $this->mode); return mysqli_fetch_array($rs, $this->mode);
} }


//Transactions //Transactions
Expand All @@ -437,7 +437,7 @@ public function rollback($transactionID=null)


//Utils //Utils
public function last_id() { public function last_id() {
return mysql_insert_id($this->conn_id); return mysqli_insert_id($this->conn_id);
} }


public function __destruct() { public function __destruct() {
Expand Down
14 changes: 8 additions & 6 deletions app/libs/Dialect/Dialect.php
Expand Up @@ -455,12 +455,12 @@ public function saveRelationships($name = NULL) {
if($name == NULL) { if($name == NULL) {
foreach ($this->getMap()->fields as $fieldCheck => $infos) { foreach ($this->getMap()->fields as $fieldCheck => $infos) {
if ($this->getModel()->getMap()->getRelationShip($fieldCheck) == true && $this->getModel()->$fieldCheck instanceof $infos['isRelationship']['foreignClass']) { if ($this->getModel()->getMap()->getRelationShip($fieldCheck) == true && $this->getModel()->$fieldCheck instanceof $infos['isRelationship']['foreignClass']) {
$this->saveRelationship($infos, $fieldCheck); return $this->saveRelationship($infos, $fieldCheck);
} }
} }
} else { } else {
$infos = $this->getMap()->fields[$name]; $infos = $this->getMap()->fields[$name];
$this->saveRelationship($infos, $name); return $this->saveRelationship($infos, $name);
} }
} }


Expand All @@ -474,16 +474,16 @@ protected function saveRelationship(&$infos, &$fieldCheck) {
case PhpBURN_Core::ONE_TO_ONE: case PhpBURN_Core::ONE_TO_ONE:
$this->getModel()->$fieldCheck->save(); $this->getModel()->$fieldCheck->save();
$this->getModel()->getMap()->setFieldValue($infos['isRelationship']['thisKey'], $relModel->getMap()->getFieldValue($infos['isRelationship']['thisKey'])); $this->getModel()->getMap()->setFieldValue($infos['isRelationship']['thisKey'], $relModel->getMap()->getFieldValue($infos['isRelationship']['thisKey']));
$this->getModel()->save(); $saved = $this->getModel()->save();
break; break;


case PhpBURN_Core::ONE_TO_MANY: case PhpBURN_Core::ONE_TO_MANY:
$relModel->getMap()->setFieldValue($infos['isRelationship']['relKey'], $this->getModel()->getMap()->getFieldValue($infos['isRelationship']['relKey'])); $relModel->getMap()->setFieldValue($infos['isRelationship']['relKey'], $this->getModel()->getMap()->getFieldValue($infos['isRelationship']['relKey']));
$this->getModel()->$fieldCheck->save(); $saved = $this->getModel()->$fieldCheck->save();
break; break;


case PhpBURN_Core::MANY_TO_MANY: case PhpBURN_Core::MANY_TO_MANY:
$this->getModel()->$fieldCheck->save(); $saved = $this->getModel()->$fieldCheck->save();


// SEARCH IF THE RELATIONSHIP ALREADY EXISTS // SEARCH IF THE RELATIONSHIP ALREADY EXISTS
unset($sqlWHERE, $relationshipSQL, $rs); unset($sqlWHERE, $relationshipSQL, $rs);
Expand Down Expand Up @@ -516,13 +516,15 @@ protected function saveRelationship(&$infos, &$fieldCheck) {
$relModel->$relFieldName = $this->getModel()->$_name; $relModel->$relFieldName = $this->getModel()->$_name;
} }


$relModel->save(); $saved = $relModel->save();
} }
} }


// @TODO maybe this is a nice place to put save relationship data to reltable // @TODO maybe this is a nice place to put save relationship data to reltable
break; break;
} }

return $saved;
} }


public function prepareInsert() { public function prepareInsert() {
Expand Down
2 changes: 1 addition & 1 deletion app/libs/Model.php
Expand Up @@ -632,7 +632,7 @@ public function save() {
} }


public function saveRelationship($name) { public function saveRelationship($name) {
$this->getDialect()->saveRelationships($name); return $this->getDialect()->saveRelationships($name);
} }


/** /**
Expand Down

0 comments on commit 46d81e4

Please sign in to comment.