@@ -2,12 +2,8 @@ |
||
| 2 | 2 | namespace Mouf\Database\TDBM\Controllers; |
| 3 | 3 | |
| 4 | 4 | use Mouf\Composer\ClassNameMapper; |
| 5 | -use Mouf\MoufUtils; |
|
| 6 | - |
|
| 7 | 5 | use Mouf\Actions\InstallUtils; |
| 8 | - |
|
| 9 | 6 | use Mouf\MoufManager; |
| 10 | - |
|
| 11 | 7 | use Mouf\Html\HtmlElement\HtmlBlock; |
| 12 | 8 | use Mouf\Mvc\Splash\Controllers\Controller; |
| 13 | 9 | |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | $this->beanNamespace = $this->moufManager->getVariable("tdbmDefaultBeanNamespace_tdbmService"); |
| 112 | 112 | |
| 113 | 113 | if ($this->daoNamespace == null && $this->beanNamespace == null) { |
| 114 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
| 114 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
| 115 | 115 | |
| 116 | - $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
| 116 | + $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
|
| 117 | 117 | if ($autoloadNamespaces) { |
| 118 | 118 | $this->autoloadDetected = true; |
| 119 | - $rootNamespace = $autoloadNamespaces[0]; |
|
| 119 | + $rootNamespace = $autoloadNamespaces[0]; |
|
| 120 | 120 | $this->daoNamespace = $rootNamespace."Dao"; |
| 121 | 121 | $this->beanNamespace = $rootNamespace."Dao\\Bean"; |
| 122 | 122 | } else { |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @param string $selfedit |
| 147 | 147 | * @throws \Mouf\MoufException |
| 148 | 148 | */ |
| 149 | - public function generate($daonamespace, $beannamespace, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 1, $selfedit="false") { |
|
| 149 | + public function generate($daonamespace, $beannamespace, $keepSupport = 0, $storeInUtc = 0, $castDatesToDateTime = 1, $selfedit="false") { |
|
| 150 | 150 | $this->selfedit = $selfedit; |
| 151 | 151 | |
| 152 | 152 | if ($selfedit == "true") { |
@@ -133,14 +133,14 @@ |
||
| 133 | 133 | $work_table = explode("'", $work_str); |
| 134 | 134 | |
| 135 | 135 | if (count($work_table) == 0) |
| 136 | - return ''; |
|
| 136 | + return ''; |
|
| 137 | 137 | |
| 138 | 138 | // if we start with a ', let's remove the first text |
| 139 | 139 | if (strstr($work_str,"'") === 0) |
| 140 | - array_shift($work_table); |
|
| 140 | + array_shift($work_table); |
|
| 141 | 141 | |
| 142 | 142 | if (count($work_table) == 0) |
| 143 | - return ''; |
|
| 143 | + return ''; |
|
| 144 | 144 | |
| 145 | 145 | // Now, let's take only the stuff outside the quotes. |
| 146 | 146 | $work_str2 = ''; |
@@ -1,8 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Mouf\Database\TDBM\Filters; |
| 3 | 3 | |
| 4 | -use Mouf\Database\DBConnection\ConnectionInterface; |
|
| 5 | - |
|
| 6 | 4 | /* |
| 7 | 5 | Copyright (C) 2006-2011 David Négrier - THE CODING MACHINE |
| 8 | 6 | |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | private function getAllPossiblePaths() { |
| 48 | - return AmbiguityException::getAllPossiblePathsRec($this->paths); |
|
| 48 | + return AmbiguityException::getAllPossiblePathsRec($this->paths); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function getAllPossiblePathsRec($sub_table_paths) |
@@ -65,9 +65,9 @@ |
||
| 65 | 65 | * @param string $func_name |
| 66 | 66 | * @param $values |
| 67 | 67 | * @return array|void |
| 68 | - * @throws TDBMException |
|
| 68 | + * @throws TDBMException |
|
| 69 | 69 | */ |
| 70 | - public function __call($func_name, $values) { |
|
| 70 | + public function __call($func_name, $values) { |
|
| 71 | 71 | |
| 72 | 72 | if (strpos($func_name,"getarray_") === 0) { |
| 73 | 73 | $column = substr($func_name, 9); |
@@ -28,7 +28,6 @@ |
||
| 28 | 28 | use Mouf\Utils\Cache\CacheInterface; |
| 29 | 29 | use Mouf\Database\TDBM\Filters\FilterInterface; |
| 30 | 30 | use Mouf\Database\DBConnection\ConnectionInterface; |
| 31 | -use Mouf\Database\DBConnection\DBConnectionException; |
|
| 32 | 31 | use Mouf\Database\TDBM\Filters\OrFilter; |
| 33 | 32 | use Mouf\Database\TDBM\Utils\TDBMDaoGenerator; |
| 34 | 33 | |
@@ -545,45 +545,45 @@ discard block |
||
| 545 | 545 | } |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - /** |
|
| 549 | - * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
| 550 | - * by parameter before all. |
|
| 551 | - * |
|
| 552 | - * Notice: if the object has a multiple primary key, the function will not work. |
|
| 553 | - * |
|
| 554 | - * @param TDBMObject $objToDelete |
|
| 555 | - */ |
|
| 556 | - public function deleteCascade(TDBMObject $objToDelete) { |
|
| 557 | - $this->deleteAllConstraintWithThisObject($objToDelete); |
|
| 558 | - $this->deleteObject($objToDelete); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * This function is used only in TDBMService (private function) |
|
| 563 | - * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
| 564 | - * |
|
| 565 | - * @param TDBMObject $obj |
|
| 566 | - * @return TDBMObjectArray |
|
| 567 | - */ |
|
| 568 | - private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
| 569 | - $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
| 570 | - $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
| 571 | - foreach ($constraints as $constraint) { |
|
| 572 | - $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
| 573 | - $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
| 574 | - $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
| 575 | - $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
| 576 | - $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
| 577 | - $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
| 578 | - ." FROM ".$tableFrom |
|
| 579 | - ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
| 580 | - ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
| 581 | - $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
| 582 | - foreach ($result as $tdbmObj) { |
|
| 583 | - $this->deleteCascade($tdbmObj); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - } |
|
| 548 | + /** |
|
| 549 | + * This function removes the given object from the database. It will also remove all objects relied to the one given |
|
| 550 | + * by parameter before all. |
|
| 551 | + * |
|
| 552 | + * Notice: if the object has a multiple primary key, the function will not work. |
|
| 553 | + * |
|
| 554 | + * @param TDBMObject $objToDelete |
|
| 555 | + */ |
|
| 556 | + public function deleteCascade(TDBMObject $objToDelete) { |
|
| 557 | + $this->deleteAllConstraintWithThisObject($objToDelete); |
|
| 558 | + $this->deleteObject($objToDelete); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * This function is used only in TDBMService (private function) |
|
| 563 | + * It will call deleteCascade function foreach object relied with a foreign key to the object given by parameter |
|
| 564 | + * |
|
| 565 | + * @param TDBMObject $obj |
|
| 566 | + * @return TDBMObjectArray |
|
| 567 | + */ |
|
| 568 | + private function deleteAllConstraintWithThisObject(TDBMObject $obj) { |
|
| 569 | + $tableFrom = $this->dbConnection->escapeDBItem($obj->_getDbTableName()); |
|
| 570 | + $constraints = $this->dbConnection->getConstraintsFromTable($tableFrom); |
|
| 571 | + foreach ($constraints as $constraint) { |
|
| 572 | + $tableTo = $this->dbConnection->escapeDBItem($constraint["table1"]); |
|
| 573 | + $colFrom = $this->dbConnection->escapeDBItem($constraint["col2"]); |
|
| 574 | + $colTo = $this->dbConnection->escapeDBItem($constraint["col1"]); |
|
| 575 | + $idVarName = $this->dbConnection->escapeDBItem($obj->getPrimaryKey()[0]); |
|
| 576 | + $idValue = $this->dbConnection->quoteSmart($obj->TDBMObject_id); |
|
| 577 | + $sql = "SELECT DISTINCT ".$tableTo.".*" |
|
| 578 | + ." FROM ".$tableFrom |
|
| 579 | + ." LEFT JOIN ".$tableTo." ON ".$tableFrom.".".$colFrom." = ".$tableTo.".".$colTo |
|
| 580 | + ." WHERE ".$tableFrom.".".$idVarName."=".$idValue; |
|
| 581 | + $result = $this->getObjectsFromSQL($constraint["table1"], $sql); |
|
| 582 | + foreach ($result as $tdbmObj) { |
|
| 583 | + $this->deleteCascade($tdbmObj); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | 588 | /** |
| 589 | 589 | * The getObjectsFromSQL is used to retrieve objects from the database using a full SQL query. |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | $keysStandardCased = array(); |
| 646 | 646 | $firstLine = true; |
| 647 | - $colsArray = null; |
|
| 647 | + $colsArray = null; |
|
| 648 | 648 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
| 649 | 649 | { |
| 650 | 650 | $row = array(); |
@@ -676,17 +676,17 @@ discard block |
||
| 676 | 676 | $id = serialize($ids); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - $obj = $this->objectStorage->get($table_name,$id); |
|
| 679 | + $obj = $this->objectStorage->get($table_name,$id); |
|
| 680 | 680 | if ($obj === null) |
| 681 | 681 | { |
| 682 | 682 | if (!is_a($className, "Mouf\\Database\\TDBM\\TDBMObject", true)) { |
| 683 | 683 | throw new TDBMException("Error while calling TDBM: The class ".$className." should extend TDBMObject."); |
| 684 | 684 | } |
| 685 | 685 | $obj = new $className($this, $table_name, $id); |
| 686 | - $obj->loadFromRow($row, $colsArray); |
|
| 687 | - $this->objectStorage->set($table_name, $id, $obj); |
|
| 686 | + $obj->loadFromRow($row, $colsArray); |
|
| 687 | + $this->objectStorage->set($table_name, $id, $obj); |
|
| 688 | 688 | } elseif ($obj->_getStatus() == "not loaded") { |
| 689 | - $obj->loadFromRow($row, $colsArray); |
|
| 689 | + $obj->loadFromRow($row, $colsArray); |
|
| 690 | 690 | // Check that the object fetched from cache is from the requested class. |
| 691 | 691 | if (!is_a($obj, $className)) { |
| 692 | 692 | throw new TDBMException("Error while calling TDBM: An object fetched from database is already present in TDBM cache and they do not share the same class. You requested the object to be of the class ".$className." but the object available locally is of the class ".get_class($obj)."."); |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | private function getObjectsFromSQLGenerator($result, $table_name, $className, $sql) { |
| 720 | 720 | $keysStandardCased = array(); |
| 721 | 721 | $firstLine = true; |
| 722 | - $colsArray = null; |
|
| 722 | + $colsArray = null; |
|
| 723 | 723 | while ($fullCaseRow = $result->fetch(\PDO::FETCH_ASSOC)) |
| 724 | 724 | { |
| 725 | 725 | $row = array(); |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | } |
| 751 | 751 | $id = serialize($ids); |
| 752 | 752 | } |
| 753 | - $obj = $this->objectStorage->get($table_name, $id); |
|
| 753 | + $obj = $this->objectStorage->get($table_name, $id); |
|
| 754 | 754 | if ($obj === null) |
| 755 | 755 | { |
| 756 | 756 | if ($className == null) { |
@@ -763,10 +763,10 @@ discard block |
||
| 763 | 763 | } else { |
| 764 | 764 | throw new TDBMException("Error while casting TDBMObject to class, the parameter passed is not a string. Value passed: ".$className); |
| 765 | 765 | } |
| 766 | - $obj->loadFromRow($row, $colsArray); |
|
| 767 | - $this->objectStorage->set($table_name, $id, $obj); |
|
| 766 | + $obj->loadFromRow($row, $colsArray); |
|
| 767 | + $this->objectStorage->set($table_name, $id, $obj); |
|
| 768 | 768 | } elseif ($obj->_getStatus() == "not loaded") { |
| 769 | - $obj->loadFromRow($row, $colsArray); |
|
| 769 | + $obj->loadFromRow($row, $colsArray); |
|
| 770 | 770 | // Check that the object fetched from cache is from the requested class. |
| 771 | 771 | if ($className != null) { |
| 772 | 772 | if (!is_subclass_of(get_class($obj), $className) && get_class($obj) != $className) { |
@@ -1665,9 +1665,9 @@ discard block |
||
| 1665 | 1665 | * Throws a TDBMException if one of those table does not exist. |
| 1666 | 1666 | * |
| 1667 | 1667 | * @param array $tables |
| 1668 | - * @throws TDBMException |
|
| 1668 | + * @throws TDBMException |
|
| 1669 | 1669 | */ |
| 1670 | - private function checkTablesExist($tables) { |
|
| 1670 | + private function checkTablesExist($tables) { |
|
| 1671 | 1671 | foreach ($tables as $table) { |
| 1672 | 1672 | $possible_tables = $this->dbConnection->checkTableExist($table); |
| 1673 | 1673 | if ($possible_tables !== true) |
@@ -1740,12 +1740,12 @@ discard block |
||
| 1740 | 1740 | * This function returns the HTML to draw a tree of DisplayNode. |
| 1741 | 1741 | * |
| 1742 | 1742 | * @param DisplayNode $tree |
| 1743 | - * @param int $x |
|
| 1744 | - * @param int $y |
|
| 1745 | - * @param int $ret_width |
|
| 1746 | - * @param int $ret_height |
|
| 1747 | - * |
|
| 1748 | - * @return string |
|
| 1743 | + * @param int $x |
|
| 1744 | + * @param int $y |
|
| 1745 | + * @param int $ret_width |
|
| 1746 | + * @param int $ret_height |
|
| 1747 | + * |
|
| 1748 | + * @return string |
|
| 1749 | 1749 | */ |
| 1750 | 1750 | public function drawTree($tree, $x, $y, &$ret_width=0, &$ret_height=0) { |
| 1751 | 1751 | |
@@ -1859,8 +1859,8 @@ discard block |
||
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | /** |
| 1862 | - * @param array<string, string> $tableToBeanMap |
|
| 1863 | - */ |
|
| 1862 | + * @param array<string, string> $tableToBeanMap |
|
| 1863 | + */ |
|
| 1864 | 1864 | public function setTableToBeanMap(array $tableToBeanMap) { |
| 1865 | 1865 | $this->tableToBeanMap = $tableToBeanMap; |
| 1866 | 1866 | } |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | if ($this->daoNamespace == null && $this->beanNamespace == null) { |
| 68 | - $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
| 68 | + $classNameMapper = ClassNameMapper::createFromComposerFile(__DIR__.'/../../../../../../../../composer.json'); |
|
| 69 | 69 | |
| 70 | 70 | $autoloadNamespaces = $classNameMapper->getManagedNamespaces(); |
| 71 | - if ($autoloadNamespaces) { |
|
| 71 | + if ($autoloadNamespaces) { |
|
| 72 | 72 | $this->autoloadDetected = true; |
| 73 | 73 | $rootNamespace = $autoloadNamespaces[0]; |
| 74 | 74 | $this->daoNamespace = $rootNamespace."Dao"; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | $tdbmService = new InstanceProxy($name); |
| 152 | 152 | /* @var $tdbmService TDBMService */ |
| 153 | - $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime); |
|
| 153 | + $tables = $tdbmService->generateAllDaosAndBeans($daofactoryclassname, $daonamespace, $beannamespace, $keepSupport, $storeInUtc, $castDatesToDateTime); |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | $moufManager->declareComponent($daofactoryinstancename, $daonamespace."\\".$daofactoryclassname, false, MoufManager::DECLARE_ON_EXIST_KEEP_INCOMING_LINKS); |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @param string $tableName |
| 100 | 100 | * @param string $columnName |
| 101 | - * @param string $value1 |
|
| 102 | - * @param string $value2 |
|
| 101 | + * @param string $value1 |
|
| 102 | + * @param string $value2 |
|
| 103 | 103 | */ |
| 104 | 104 | public function __construct($tableName=null, $columnName=null, $value1=null, $value2=null) { |
| 105 | 105 | $this->tableName = $tableName; |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @param ConnectionInterface $dbConnection |
| 115 | 115 | * @return string |
| 116 | - * @throws \Mouf\Database\TDBM\TDBMException |
|
| 116 | + * @throws \Mouf\Database\TDBM\TDBMException |
|
| 117 | 117 | */ |
| 118 | - public function toSql(ConnectionInterface $dbConnection) { |
|
| 118 | + public function toSql(ConnectionInterface $dbConnection) { |
|
| 119 | 119 | if ($this->enableCondition != null && !$this->enableCondition->isOk()) { |
| 120 | 120 | return ""; |
| 121 | 121 | } |
@@ -9,14 +9,14 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class FilterUtils |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param string|null|DateTimeInterface $value |
|
| 14 | - */ |
|
| 15 | - public static function valueToSql($value, ConnectionInterface $dbConnection) { |
|
| 16 | - if ($value instanceof DateTimeInterface) { |
|
| 17 | - return "'".$value->format('Y-m-d H:i:s')."'"; |
|
| 18 | - } else { |
|
| 19 | - return $dbConnection->quoteSmart($value); |
|
| 20 | - } |
|
| 21 | - } |
|
| 12 | + /** |
|
| 13 | + * @param string|null|DateTimeInterface $value |
|
| 14 | + */ |
|
| 15 | + public static function valueToSql($value, ConnectionInterface $dbConnection) { |
|
| 16 | + if ($value instanceof DateTimeInterface) { |
|
| 17 | + return "'".$value->format('Y-m-d H:i:s')."'"; |
|
| 18 | + } else { |
|
| 19 | + return $dbConnection->quoteSmart($value); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @param ConnectionInterface $dbConnection |
| 70 | 70 | * @return string |
| 71 | - * @throws TDBMException |
|
| 71 | + * @throws TDBMException |
|
| 72 | 72 | */ |
| 73 | - public function toSql(ConnectionInterface $dbConnection) { |
|
| 73 | + public function toSql(ConnectionInterface $dbConnection) { |
|
| 74 | 74 | if ($this->enableCondition != null && !$this->enableCondition->isOk()) { |
| 75 | 75 | return ""; |
| 76 | 76 | } |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return array<string> |
| 104 | 104 | */ |
| 105 | - public function getUsedTables() { |
|
| 106 | - if ($this->enableCondition != null && !$this->enableCondition->isOk()) { |
|
| 107 | - return array(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $tables = array(); |
|
| 111 | - foreach ($this->filters as $filter) { |
|
| 112 | - |
|
| 113 | - if (!$filter instanceof FilterInterface) { |
|
| 114 | - throw new TDBMException("Error in OrFilter: One of the parameters is not a filter."); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $tables = array_merge($tables,$filter->getUsedTables()); |
|
| 118 | - } |
|
| 119 | - // Remove tables in double. |
|
| 120 | - $tables = array_flip(array_flip($tables)); |
|
| 121 | - return $tables; |
|
| 122 | - } |
|
| 105 | + public function getUsedTables() { |
|
| 106 | + if ($this->enableCondition != null && !$this->enableCondition->isOk()) { |
|
| 107 | + return array(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $tables = array(); |
|
| 111 | + foreach ($this->filters as $filter) { |
|
| 112 | + |
|
| 113 | + if (!$filter instanceof FilterInterface) { |
|
| 114 | + throw new TDBMException("Error in OrFilter: One of the parameters is not a filter."); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $tables = array_merge($tables,$filter->getUsedTables()); |
|
| 118 | + } |
|
| 119 | + // Remove tables in double. |
|
| 120 | + $tables = array_flip(array_flip($tables)); |
|
| 121 | + return $tables; |
|
| 122 | + } |
|
| 123 | 123 | } |