From: <gem...@li...> - 2011-11-30 10:33:56
|
Revision: 316 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=316&view=rev Author: matijsdejong Date: 2011-11-30 10:33:50 +0000 (Wed, 30 Nov 2011) Log Message: ----------- Updated version numbers Really solved problem with staff deletion. Database models are more stable now. Modified Paths: -------------- branches/1.5.0-pulse/library/classes/Gems/Model.php branches/1.5.0-pulse/library/classes/Gems/Versions.php branches/1.5.0-pulse/library/classes/MUtil/Model/DatabaseModelAbstract.php branches/1.5.0-pulse/library/classes/MUtil/Model/JoinModel.php branches/1.5.0-pulse/library/classes/MUtil/Version.php Modified: branches/1.5.0-pulse/library/classes/Gems/Model.php =================================================================== --- branches/1.5.0-pulse/library/classes/Gems/Model.php 2011-11-29 16:26:57 UTC (rev 315) +++ branches/1.5.0-pulse/library/classes/Gems/Model.php 2011-11-30 10:33:50 UTC (rev 316) @@ -105,6 +105,7 @@ protected function addUserLogin(Gems_Model_JoinModel $model, $loginField, $organizationField) { $model->addTable('gems__user_logins', array($loginField => 'gul_login', $organizationField => 'gul_id_organization'), 'gul'); + $model->setTableKeysToJoin('gems__user_logins'); } /** Modified: branches/1.5.0-pulse/library/classes/Gems/Versions.php =================================================================== --- branches/1.5.0-pulse/library/classes/Gems/Versions.php 2011-11-29 16:26:57 UTC (rev 315) +++ branches/1.5.0-pulse/library/classes/Gems/Versions.php 2011-11-30 10:33:50 UTC (rev 316) @@ -43,7 +43,7 @@ { public final function getBuild() { - return 42; + return 43; } public final function getGemsVersion() Modified: branches/1.5.0-pulse/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- branches/1.5.0-pulse/library/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-29 16:26:57 UTC (rev 315) +++ branches/1.5.0-pulse/library/classes/MUtil/Model/DatabaseModelAbstract.php 2011-11-30 10:33:50 UTC (rev 316) @@ -244,6 +244,11 @@ return $this->_filterDataForSave($tableData, $isNew); } + /** + * + * @param string $table_name Does not test for existence + * @return array Numeric array containing the key field names. + */ protected function _getKeysFor($table_name) { $keys = array(); @@ -277,7 +282,7 @@ { $table_name = $this->_getTableName($table); - // MUtil_Echo::r($table->info('metadata')); + // MUtil_Echo::track($table->info('metadata')); foreach ($table->info('metadata') as $field) { $name = $field['COLUMN_NAME']; $finfo = array('table' => $table_name); @@ -406,12 +411,15 @@ if ($update) { // MUtil_Echo::r($filter, 'Filter'); + $adapter = $this->getAdapter(); + $wheres = array(); + foreach ($filter as $text => $value) { + $wheres[] = $adapter->quoteInto($text, $value); + } // Retrieve the record from the database - $oldValueSet = call_user_func_array(array($table, 'find'), $filter); + $oldValues = $table->fetchRow('(' . implode(' ) AND (', $wheres) . ')')->toArray(); - if ($oldValueSet->count()) { - $oldValues = $oldValueSet->current()->toArray(); - } else { + if (! $oldValues) { // MUtil_Echo::r('INSERT!!', 'Old not found'); // Apparently the record does not exist in the database $update = false; @@ -441,14 +449,19 @@ // Update the row if ($changed = $table->update($returnValues, $filter)) { $this->addChanged($changed); - return $this->_updateCopyKeys($primaryKeys, $returnValues); + // Make sure the copy keys (if any) have the new values as well + $returnValues = $this->_updateCopyKeys($primaryKeys, $returnValues); + + // Add the old values as we have them and they may be of use later on. + $returnValues = $returnValues + $oldValues; + + return $returnValues; } } } } - // No changes were made, return empty array. - // The non-abstract child class should take care - // of returning the original values. + // Add the old values as we have them and they may be of use later on. + return $returnValues + $oldValues; } else { // Perform insert @@ -782,6 +795,12 @@ // abstract public function save(array $newValues); + /** + * Function to turn database insertion on or off for this model. + * + * @param boolean $value + * @return MUtil_Model_DatabaseModelAbstract (continuation pattern) + */ public function setCreate($value = true) { $this->canCreate = (bool) $value; @@ -795,7 +814,7 @@ * @param mxied $value1 * @param string $field2 * @param mixed $key2 - * @return MUtil_Model_TableModel + * @return MUtil_Model_DatabaseModelAbstract (continuation pattern) */ public function setDeleteValues($arrayOrField1 = null, $value1 = null, $field2 = null, $key2 = null) { @@ -804,6 +823,15 @@ return $this; } + /** + * When passed an array this method set the keys of this database object + * to those keys. + * When passed a string it is assumed to be a table name and the keys of + * this object are set to those of that table. + * + * @param mixed $keysOrTableName array or string + * @return MUtil_Model_DatabaseModelAbstract (continuation pattern) + */ public function setKeysToTable($keysOrTableName) { if (is_string($keysOrTableName)) { @@ -812,8 +840,17 @@ $keys = $keysOrTableName; } $this->setKeys($keys); + + return $this; } + /** + * Changes the key copy string that is used to create a new identifier + * for keys. + * + * @param string $value A sting of at least 3 characters containing %s. + * @return MUtil_Model_DatabaseModelAbstract (continuation pattern) + */ public function setKeyCopier($value = self::KEY_COPIER) { $this->keyCopier = $value; Modified: branches/1.5.0-pulse/library/classes/MUtil/Model/JoinModel.php =================================================================== --- branches/1.5.0-pulse/library/classes/MUtil/Model/JoinModel.php 2011-11-29 16:26:57 UTC (rev 315) +++ branches/1.5.0-pulse/library/classes/MUtil/Model/JoinModel.php 2011-11-30 10:33:50 UTC (rev 316) @@ -292,9 +292,40 @@ /** * * @param string $table_name Does not test for existence - * @param bool $saveable Will changes to this table be saved - * @return MUtil_Model_JoinModel + * @return MUtil_Model_JoinModel (continuation pattern) */ + public function setTableKeysToJoin($table_name) + { + $origKeys = $this->_getKeysFor($table_name); + + // First remove old keys + foreach ($origKeys as $key) { + $this->del($key, 'key'); + } + + foreach ($this->_joinFields as $left => $right) { + if (is_string($left) && $this->is($left, 'table', $table_name)) { + $this->set($left, 'key', true); + } + if (is_string($right) && $this->is($right, 'table', $table_name)) { + $this->set($right, 'key', true); + } + } + + return $this; + } + + /** + * Add the table to the default save tables. + * + * Only tables marked as save tables are saved during a save() or delete(), + * unless this is overuled by the extra parameter for those functions in + * this object. + * + * @param string $table_name Does not test for existence + * @param boolean $saveable Will changes to this table be saved + * @return MUtil_Model_JoinModel (continuation pattern) + */ public function setTableSaveable($table_name, $saveable = true) { // MUtil_Echo::r(func_get_args(), __CLASS__ . '->' . __FUNCTION__); Modified: branches/1.5.0-pulse/library/classes/MUtil/Version.php =================================================================== --- branches/1.5.0-pulse/library/classes/MUtil/Version.php 2011-11-29 16:26:57 UTC (rev 315) +++ branches/1.5.0-pulse/library/classes/MUtil/Version.php 2011-11-30 10:33:50 UTC (rev 316) @@ -1,40 +1,40 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** * @package MUtil */ class MUtil_Version { const MAJOR = 1; const MINOR = 0; - const BUILD = 28; + const BUILD = 30; public static function get() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |