From d31fd7ee8989d50e4f97d60f55b93b1195e6113f Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Tue, 24 Jul 2012 09:14:11 -0600 Subject: [PATCH 1/2] Deprecate xPDO->getMicroTime() Was implemented to support PHP 4 emulation of the microtime() call with the PHP 5-only get_as_float parameter set to true. No longer needed. --- xpdo/changelog.txt | 1 + xpdo/xpdo.class.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/xpdo/changelog.txt b/xpdo/changelog.txt index 032c79a2f74..2235bfef7bf 100644 --- a/xpdo/changelog.txt +++ b/xpdo/changelog.txt @@ -1,5 +1,6 @@ This file shows the changes in this release of xPDO. +- Deprecate xPDO->getMicroTime() - [#8176] xPDO->updateCollection() fails to set NULL values xPDO 2.2.5-pl (June 1, 2012) diff --git a/xpdo/xpdo.class.php b/xpdo/xpdo.class.php index d9c73908bc7..2b925c8bd03 100644 --- a/xpdo/xpdo.class.php +++ b/xpdo/xpdo.class.php @@ -2506,11 +2506,11 @@ public function setAttribute($attribute, $value) { /** * Convert current microtime() result into seconds. * + * @deprecated Use microtime(true) directly; this was to emulate PHP 5 behavior in PHP 4. * @return float */ public function getMicroTime() { - list($usec, $sec) = explode(' ', microtime()); - return ((float)$usec + (float)$sec); + return microtime(true); } /** From bc33aae06b5a4d2c3b3077037b47496558947c49 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Tue, 24 Jul 2012 11:15:16 -0600 Subject: [PATCH 2/2] [#8320] Preserve order of $columns in xPDOObject::getSelectColumns() When $exclude==false and $columns are specified, xPDOObject::getSelectColumns() will now preserve the order specified in $columns rather than reordering the returned values according to the order of the columns in the field map. --- test/xPDO/xPDO/xPDO.php | 2 +- xpdo/changelog.txt | 1 + xpdo/om/xpdoobject.class.php | 38 ++++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/test/xPDO/xPDO/xPDO.php b/test/xPDO/xPDO/xPDO.php index b6af8e696c5..e404e00a201 100644 --- a/test/xPDO/xPDO/xPDO.php +++ b/test/xPDO/xPDO/xPDO.php @@ -238,7 +238,7 @@ public function testGetSelectColumns() { $columns = $this->xpdo->getSelectColumns('Person','Person','test_'); $this->assertEquals($columns,$correct); - $includeColumns = array('id','last_name','dob'); + $includeColumns = array('dob','last_name','id'); $correct = implode(', ', array_map(array($this->xpdo, 'escape'), $includeColumns)); $columns = $this->xpdo->getSelectColumns('Person','','',$includeColumns); $this->assertEquals($columns,$correct); diff --git a/xpdo/changelog.txt b/xpdo/changelog.txt index 2235bfef7bf..df067b8e2fc 100644 --- a/xpdo/changelog.txt +++ b/xpdo/changelog.txt @@ -1,5 +1,6 @@ This file shows the changes in this release of xPDO. +- [#8320] Preserve order of $columns in xPDOObject::getSelectColumns() - Deprecate xPDO->getMicroTime() - [#8176] xPDO->updateCollection() fails to set NULL values diff --git a/xpdo/om/xpdoobject.class.php b/xpdo/om/xpdoobject.class.php index 9d9966b5ada..77bdcd8a7f4 100644 --- a/xpdo/om/xpdoobject.class.php +++ b/xpdo/om/xpdoobject.class.php @@ -563,20 +563,32 @@ public static function getSelectColumns(xPDO & $xpdo, $className, $tableAlias= ' $tableAlias= $xpdo->escape($tableAlias); $tableAlias.= '.'; } - foreach (array_keys($aColumns) as $k) { - if ($exclude && in_array($k, $columns)) { - continue; - } - elseif (empty ($columns)) { - $columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k); - } - elseif ($exclude || in_array($k, $columns)) { - $columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k); - } else { - continue; + if (!$exclude && !empty($columns)) { + foreach ($columns as $column) { + if (!in_array($column, array_keys($aColumns))) { + continue; + } + $columnarray[$column]= "{$tableAlias}" . $xpdo->escape($column); + if (!empty ($columnPrefix)) { + $columnarray[$column]= $columnarray[$column] . " AS " . $xpdo->escape("{$columnPrefix}{$column}"); + } } - if (!empty ($columnPrefix)) { - $columnarray[$k]= $columnarray[$k] . " AS " . $xpdo->escape("{$columnPrefix}{$k}"); + } else { + foreach (array_keys($aColumns) as $k) { + if ($exclude && in_array($k, $columns)) { + continue; + } + elseif (empty ($columns)) { + $columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k); + } + elseif ($exclude || in_array($k, $columns)) { + $columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k); + } else { + continue; + } + if (!empty ($columnPrefix)) { + $columnarray[$k]= $columnarray[$k] . " AS " . $xpdo->escape("{$columnPrefix}{$k}"); + } } } }