Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainer Furtmeier authored and Rainer Furtmeier committed Mar 26, 2016
1 parent 2b7ccec commit 020f933
Show file tree
Hide file tree
Showing 491 changed files with 22,868 additions and 6,771 deletions.
20 changes: 11 additions & 9 deletions classes/backend/Adapter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/

class Adapter {
protected $ID;
protected $DBS = null;
protected $DBSLazy = null;
protected $parsers = array();
protected $file = "";
protected $affectedRowsOnly = false;
Expand Down Expand Up @@ -369,38 +370,39 @@ function parseSearchString(){
*
* @param $typsicher[optional](Boolean) Determines if execution is typesafe
*/
function lCV4($typsicher = false){
function lCV4($lazyload = false){
$this->parseSearchString();
if($this->DBS == null) $this->getConnection();
if($this->DBS == null)
$this->getConnection();

if(count($this->selectStatement->fields) == 0)
$this->selectStatement->fields[0] = "*";

#if(!in_array($this->selectStatement->table[0]."ID",$this->selectStatement->fields) AND !in_array("*",$this->selectStatement->fields))
$this->selectStatement->fields[] = "t1.".$this->selectStatement->table[0]."ID"; //This is REQUIRED or else objects with values from a joined table may not get an id (if same colname appears in more than one table)

$this->DBS->setParser($this->parsers);
if($this->affectedRowsOnly) $this->affectedRowsOnly = false;

#if(!$typsicher)
$return = $this->DBS->loadMultipleV4($this->selectStatement);
#else return $this->DBS->loadMultipleT($this->selectStatement);
$return = $this->DBS->loadMultipleV4($this->selectStatement, $lazyload);
if($return != null AND is_array($return))
foreach($return AS $k => $v)
$v->parsers = $this->hasParsers;

if($return != null AND is_object($return))
$return->parsers = $this->hasParsers;

return $return;
}

/**
* Same as lCV4, but without typesafe capabilities.
*
* @deprecated since version 20160218
* @return Object All objects matching selectStatement
*/
function lCV3(){
$this->parseSearchString();
if($this->DBS == null) $this->getConnection();

if($this->selectStatement->AttributesClassName == "")
$this->selectStatement->AttributesClassName = $this->selectStatement->table[0].(count($this->selectStatement->joinTables) > 0 ? "Join" : "")."Attributes";

Expand Down
7 changes: 5 additions & 2 deletions classes/backend/Attributes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ function newWithValues($fields,$values){
function newWithAssociativeArray($values){
$a = PMReflector::getAttributesArray(get_class($this));

for($i = 0;$i < count($a);$i++)
if(isset($values[$a[$i]])) $this->$a[$i] = $values[$a[$i]];
for($i = 0;$i < count($a);$i++){
$f = $a[$i];
if(isset($values[$a[$i]]))
$this->$f = $values[$a[$i]];
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/backend/BackgroundPluginState.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/
class BackgroundPluginState {

Expand Down
32 changes: 20 additions & 12 deletions classes/backend/Collection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/
abstract class Collection {
protected $A = null;
Expand Down Expand Up @@ -473,8 +473,13 @@ function setGroupV3($by){
*
* @return persistentObject Next entry of Collector
*/
function getNextEntry(){
if($this->collector === null) $this->lCV3();
function getNextEntry($lazyLoad = false){
if($lazyLoad)
return $this->lCV3(-1, false, $lazyLoad);

if(!$lazyLoad AND $this->collector === null)
$this->lCV3(-1, true, $lazyLoad);

if(isset($this->collector[$this->i]))
return $this->collector[$this->i++];

Expand Down Expand Up @@ -549,18 +554,21 @@ function loadAdapter(){
* @param $id[optional](Integer) Only select object with specified ID
* @param $returnCollector[optional](Boolean) If true, result is saved in collector-variable, otherwise the result is returned
*/
public function lCV3($id = -1, $returnCollector = true){

if($this->Adapter == null) $this->loadAdapter();
public function lCV3($id = -1, $returnCollector = true, $lazyload = false){
if($this->Adapter == null)
$this->loadAdapter();

$gT = $this->Adapter->getSelectStatement("table");
if(count($gT) == 0) $this->Adapter->setSelectStatement("table",$this->collectionOf);
if(count($gT) == 0)
$this->Adapter->setSelectStatement("table", $this->collectionOf);

if($id != -1)
$this->setAssocV3((count($gT) == 0 ? $this->collectionOf : $gT[0])."ID","=",$id);

if($returnCollector) $this->collector = $this->Adapter->lCV3();
else return $this->Adapter->lCV3();
if($returnCollector)
$this->collector = $this->Adapter->lCV4();
else
return $this->Adapter->lCV4($lazyload);
}

/**
Expand Down Expand Up @@ -767,8 +775,8 @@ public function getCategoryFieldLabel(array $KIDs){
*
* @return persistentObject Next entry of Collector
*/
function n(){
return $this->getNextEntry();
function n($lazyLoad = false){
return $this->getNextEntry($lazyLoad);
}

public function setTableLock(string $table, boolean $lock){
Expand Down
2 changes: 1 addition & 1 deletion classes/backend/CorporateDesign.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/
class CorporateDesign implements iCorporateDesign {
public function getLabel() {
Expand Down
5 changes: 4 additions & 1 deletion classes/backend/DBPDOStorage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/

class DBPDOStorage {
Expand Down Expand Up @@ -277,8 +277,11 @@ function loadMultipleV4(SelectStatement $statement, $typsicher = false){
#$q = $this->c->query($sql);
$q = $this->c->prepare($sql);
#echo $sql;
#echo "\n";
#var_dump($q);
Timer::now("sql start", __FILE__, __LINE__);
$q->execute();
Timer::now("sql end", __FILE__, __LINE__);
#print_r($this->c->errorInfo());
DBPDOStorage::$queryCounter++;

Expand Down
138 changes: 67 additions & 71 deletions classes/backend/DBStorage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 2007 - 2015, Rainer Furtmeier - [email protected]
* 2007 - 2016, Rainer Furtmeier - [email protected]
*/

class DBStorage {
Expand Down Expand Up @@ -217,11 +217,18 @@ function checkMyTable($CIA){
$changes = 0;
foreach($unterschied2 as $key => $value){
$newSQL = strstr($CIA->MySQL,"`$value`");
$ex = explode(",\n",$newSQL);
#$ex = explode(",", $newSQL);
$ex = preg_split("/,\s/", $newSQL);
#echo "<pre>";
#print_r($ex);
#echo "</pre>";
$newSQL = $ex[0];

$sql = "ALTER TABLE `$regs[1]` ADD $newSQL";
$this->cWrite->query($sql);
self::$lastQuery[] = $sql;
if(count(self::$lastQuery) > 5)
array_shift(self::$lastQuery);

if($this->cWrite->error)
throw new Exception($this->cWrite->error);
Expand Down Expand Up @@ -381,12 +388,13 @@ function saveSingle2($table, $id, $A) {

$fields = PMReflector::getAttributesArray($A);
$sql = "UPDATE $table SET";

for($i = 0;$i < count($fields);$i++)
for($i = 0;$i < count($fields);$i++){
$f = $fields[$i];
#print_r($A->$f);
#if(!is_numeric($A->$fields[$i]))
$sql .= ($i > 0 ? "," : "")." ".$fields[$i]." = '".$this->cWrite->real_escape_string($A->$fields[$i])."'";
$sql .= ($i > 0 ? "," : "")." ".$fields[$i]." = '".$this->cWrite->real_escape_string($A->$f)."'";
#else $sql .= ($i > 0 ? "," : "")." ".$fields[$i]." = ".$A->$fields[$i]."";
}
$sql .= " WHERE ".$table."ID = '$id'";
$_SESSION["messages"]->addMessage("executing MySQL: $sql");
$this->cWrite->query($sql);
Expand All @@ -407,9 +415,10 @@ function getTableColumns($forWhat){
if($this->c->error AND $this->c->errno == 1146) throw new TableDoesNotExistException($forWhat);

$a = new stdClass();
while ($row = $result->fetch_assoc())
$a->$row["Field"] = "";

while ($row = $result->fetch_assoc()){
$f = $row["Field"];
$a->$f = "";
}
return $a;
}

Expand Down Expand Up @@ -444,7 +453,18 @@ public static function findNonUft8($value){
return $value;
}

function loadMultipleV4(SelectStatement $statement, $typsicher = false){
private $lazyRequest = null;
function loadMultipleV4(SelectStatement $statement, $lazyload = false){
if($lazyload AND $this->lazyRequest !== null){
$t = $this->lazyRequest->fetch_object();
if(!$t){
$this->lazyRequest = null;
return null;
}

return $this->process($t, $statement);
}

if(!$this->c)
throw new StorageException();

Expand Down Expand Up @@ -525,7 +545,6 @@ function loadMultipleV4(SelectStatement $statement, $typsicher = false){
$sql = str_replace (" t1.", " ".self::$lockAliases[$statement->table[0]].".", $sql);
}

$collector = array();

if($statement->table[0] != "Userdata") $_SESSION["messages"]->startMessage("executing MySQL: $sql");
#echo nl2br($sql)."<br /><br />";
Expand Down Expand Up @@ -560,7 +579,8 @@ function loadMultipleV4(SelectStatement $statement, $typsicher = false){
syslog(LOG_ERR, "MySQL: ".$this->c->error."(".$this->c->errno.") in $sql");

#echo $sql."<br /><br />";
if($statement->table[0] != "Userdata") $_SESSION["messages"]->endMessage(": ".$this->c->affected_rows." ".$statement->table[0]." geladen");
if($statement->table[0] != "Userdata")
$_SESSION["messages"]->endMessage(": ".$this->c->affected_rows." ".$statement->table[0]." geladen");

if($this->affectedRowsOnly) {
$this->affectedRowsOnly = false;
Expand All @@ -575,72 +595,47 @@ function loadMultipleV4(SelectStatement $statement, $typsicher = false){
return $this->c->affected_rows;
}

/*if($typsicher){
$types = array();
$qc = $this->c->query("SHOW COLUMNS FROM ".$statement->table[0]);
DBStorage::$queryCounter++;
while($tc = $qc->fetch_object())
$types[$tc->Field] = $this->mysql2Object($tc->Type);
foreach($statement->joinTables AS $kc => $vc){
$qc = $this->c->query("SHOW COLUMNS FROM ".$vc);
DBStorage::$queryCounter++;
while($tc = $qc->fetch_object())
$types[$tc->Field] = $this->mysql2Object($tc->Type);
}
foreach($statement->dataTypes AS $kc => $vc)
$types = array_merge($types, $vc);
}*/
if($lazyload){
$this->lazyRequest = $q;
$t = $q->fetch_object();
return $this->process($t, $statement);
}

$fields = null;
$collector = array();
while($t = $q->fetch_object())
$collector[] = $this->process($t, $statement);


return $collector;
}

private function process($t, $statement){
$cName = $statement->table[0];
if($statement->className != "") $cName = $statement->className[0];
if($statement->className != "")
$cName = $statement->className[0];

$A = new Attributes();

#if($fields == null)
# $fields = PMReflector::getAttributesArrayAnyObject($t);

while($t = $q->fetch_object()){
$A = new Attributes();
foreach($t AS $key => $value)
$A->$key = $this->fixUtf8(stripslashes($value));

if($fields == null) $fields = PMReflector::getAttributesArrayAnyObject($t);

foreach($fields AS $key => $value){
$A->$value = $this->fixUtf8(stripslashes($t->$value));

/*if($typsicher){
if(isset($types[$value])) $typObj = $types[$value];
else throw new DataTypeNotDefinedException($value);
$A->$value = new $typObj($A->$value);
#echo "<pre>";
#print_r($A);
#echo "</pre>";
}*/
}

if(count($this->parsers) > 0)
foreach($this->parsers as $key => $value)
if(isset($A->$key))
$A->$key = $this->invokeStaticMethod($value, array($A->$key, "load", $A));
#eval("\$A->\$key = ".$value."(\"".."\",\"load\", \$A);");

$oID = $statement->table[0]."ID";

#$cName = $statement->table[0];
#if(isset($_SESSION["CurrentAppPlugins"]) AND $_SESSION["CurrentAppPlugins"]->isPluginGeneric($cName))
# $cName = "Generic";

$newCOfClass = new $cName($t->$oID);
$newCOfClass->setA($A);
$collector[] = $newCOfClass;
}
if(count($this->parsers) > 0)
foreach($this->parsers as $key => $value)
if(isset($A->$key))
$A->$key = $this->invokeStaticMethod($value, array($A->$key, "load", $A));

$oID = $statement->table[0]."ID";

$newCOfClass = new $cName($t->$oID);
$newCOfClass->setA($A);

return $collector;
return $newCOfClass;
}

/*function loadMultipleT(SelectStatement $statement){
return $this->loadMultipleV4($statement, true);
}*/

function loadMultipleV3(SelectStatement $statement){

$noJoinAs = str_replace("Join","",$statement->AttributesClassName);
Expand Down Expand Up @@ -810,9 +805,10 @@ function makeNewLine2($table, $A) {

#if(is_numeric($A->$fields[$i])) $values .= ", ".$A->$fields[$i]."\n";
#else
$values .= ", '".$this->cWrite->real_escape_string($A->$fields[$i])."'\n";
$cf = $fields[$i];
$values .= ", '".$this->cWrite->real_escape_string($A->$cf)."'\n";

$sets .= ",\n`".$fields[$i]."`";
$sets .= ",\n`".$cf."`";
}
$sql = "INSERT INTO\n $table\n ($sets) VALUES ($values)";
$_SESSION["messages"]->addMessage("executing MySQL: $sql");
Expand Down
Loading

0 comments on commit 020f933

Please sign in to comment.