diff --git a/administrator/components/com_menus/models/items.php b/administrator/components/com_menus/models/items.php index 7e8b439a75e76..de7daf43fd476 100644 --- a/administrator/components/com_menus/models/items.php +++ b/administrator/components/com_menus/models/items.php @@ -168,7 +168,7 @@ protected function getListQuery() $app = JFactory::getApplication(); // Select all fields from the table. - $query->select($this->getState('list.select', 'a.id, a.menutype, a.title, a.alias, a.note, a.path, a.link, a.type, a.parent_id, a.level, a.published as apublished, a.component_id, a.ordering, a.checked_out, a.checked_out_time, a.browserNav, a.access, a.img, a.template_style_id, a.params, a.lft, a.rgt, a.home, a.language, a.client_id')); + $query->select($this->getState('list.select', 'a.id, a.menutype, a.title, a.alias, a.note, a.path, a.link, a.type, a.parent_id, a.level, a.published as apublished, a.component_id, a.ordering, a.checked_out, a.checked_out_time, a."browserNav", a.access, a.img, a.template_style_id, a.params, a.lft, a.rgt, a.home, a.language, a.client_id')); $query->select('CASE a.type' . ' WHEN ' . $db->quote('component') . ' THEN a.published+2*(e.enabled-1) ' . ' WHEN ' . $db->quote('url') . ' THEN a.published+2 ' . diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index d15949cdedddc..cd8c4fb1bff95 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1703,7 +1703,7 @@ CREATE TABLE "#__menu" ( "img" character varying(255) DEFAULT '' NOT NULL, "template_style_id" integer DEFAULT 0 NOT NULL, -- JSON encoded data for the menu item. - "params" text NOT NULL, + "params" text DEFAULT '' NOT NULL, -- Nested set lft. "lft" bigint DEFAULT 0 NOT NULL, -- Nested set rgt. @@ -2385,4 +2385,4 @@ BEGIN RETURN soundex; END; -$$; \ No newline at end of file +$$; diff --git a/libraries/joomla/database/database.php b/libraries/joomla/database/database.php index a4678f4f3a8d8..5950dcf37be45 100644 --- a/libraries/joomla/database/database.php +++ b/libraries/joomla/database/database.php @@ -838,7 +838,8 @@ public function insertObject($table, &$object, $key = null) $values = array(); // Create the base insert statement. - $statement = 'INSERT INTO ' . $this->quoteName($table) . ' (%s) VALUES (%s)'; + $query = $this->getQuery(true); + $query->insert($this->quoteName($table)); // Iterate over the object variables to build the query fields and values. foreach (get_object_vars($object) as $k => $v) @@ -857,11 +858,14 @@ public function insertObject($table, &$object, $key = null) // Prepare and sanitize the fields and values for the database query. $fields[] = $this->quoteName($k); - $values[] = $this->quote($v); + $values[] = is_numeric($v) ? $v : $this->quote($v); } + $query->columns($fields); + $query->values(implode(',', $values)); + // Set the query and execute the insert. - $this->setQuery(sprintf($statement, implode(',', $fields), implode(',', $values))); + $this->setQuery($query); if (!$this->query()) { return false; @@ -1618,7 +1622,7 @@ public function updateObject($table, &$object, $key, $nulls = false) // Set the primary key to the WHERE clause instead of a field to update. if ($k == $key) { - $where = $this->quoteName($k) . '=' . $this->quote($v); + $where = $this->quoteName($k) . '=' . (is_numeric($v) ? $v : $this->quote($v)); continue; } @@ -1639,7 +1643,7 @@ public function updateObject($table, &$object, $key, $nulls = false) // The field is not null so we prep it for update. else { - $val = $this->quote($v); + $val = (is_numeric($v) ? $v : $this->quote($v)); } // Add the field to be updated. diff --git a/libraries/joomla/database/database/postgresql.php b/libraries/joomla/database/database/postgresql.php index 9bcdcdd13d54a..4bad397baaae9 100644 --- a/libraries/joomla/database/database/postgresql.php +++ b/libraries/joomla/database/database/postgresql.php @@ -233,7 +233,7 @@ public function getCollation() */ public function getNumRows( $cur = null ) { - return pg_num_rows($cur ? $cur : $this->cursor); + return pg_num_rows((int)$cur ? $cur : $this->cursor); } /** @@ -450,10 +450,6 @@ public function insertObject($table, &$object, $key = null) $fields = array(); $values = array(); - // Create the base insert statement. - $query = $this->getQuery(true); - $query->insert($this->quoteName($table)); - // Iterate over the object variables to build the query fields and values. foreach (get_object_vars($object) as $k => $v) { @@ -474,24 +470,35 @@ public function insertObject($table, &$object, $key = null) $values[] = is_numeric($v) ? $v : $this->quote($v); } - $query->columns($fields); - $query->values(implode(',', $values)); + // Create the base insert statement. + $query = $this->getQuery(true); + + $query->insert($this->quoteName($table)) + ->columns($fields) + ->values(implode(',', $values)); + if ($key) + { + $query->returning($key); + } + // Set the query and execute the insert. $this->setQuery($query); - if (!$this->query()) + + if ($key) { + $id = $this->loadResult(); + if ($id) + { + $object->$key = $id; + return true; + } return false; - } - - // Update the primary key if it exists. - $id = $this->insertid(); - if ($key && $id) + } + else { - $object->$key = $id; + return $this->query(); } - - return true; } /** diff --git a/libraries/joomla/database/table/user.php b/libraries/joomla/database/table/user.php index 51b3cab1a1953..0d906a04f0df1 100644 --- a/libraries/joomla/database/table/user.php +++ b/libraries/joomla/database/table/user.php @@ -181,6 +181,12 @@ public function bind($array, $ignore = '') */ public function check() { + // Set user id to null istead of 0, if needed + if ($this->id === 0) + { + $this->id = null; + } + // Validate user information if (trim($this->name) == '') { @@ -207,11 +213,16 @@ public function check() } // Set the registration timestamp - if ($this->registerDate == null || $this->registerDate == $this->_db->getNullDate()) + if (empty($this->registerDate) || $this->registerDate == $this->_db->getNullDate()) { $this->registerDate = JFactory::getDate()->toSql(); } - + // Set the lastvisitDate timestamp + if (empty($this->lastvisitDate)) + { + $this->lastvisitDate = $this->_db->getNullDate(); + } + // check for existing username $query = $this->_db->getQuery(true); $query->select($this->_db->quoteName('id')); diff --git a/libraries/joomla/installer/adapters/component.php b/libraries/joomla/installer/adapters/component.php index f1428a6e870eb..7d9f17121d010 100644 --- a/libraries/joomla/installer/adapters/component.php +++ b/libraries/joomla/installer/adapters/component.php @@ -541,11 +541,11 @@ public function install() return false; } - $eid = $db->insertid(); + $eid = $row->extension_id; // Clobber any possible pending updates $update = JTable::getInstance('update'); - $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); + $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); if ($uid) { @@ -1021,7 +1021,7 @@ public function update() // Clobber any possible pending updates $update = JTable::getInstance('update'); - $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); + $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); if ($uid) { @@ -1323,7 +1323,7 @@ public function uninstall($id) // Clobber any possible pending updates $update = JTable::getInstance('update'); - $uid = $update->find(array('element' => $row->element, 'type' => 'component', 'client_id' => '', 'folder' => '')); + $uid = $update->find(array('element' => $row->element, 'type' => 'component', 'client_id' => 1, 'folder' => '')); if ($uid) { @@ -1950,7 +1950,7 @@ public function discover_install() // Clobber any possible pending updates $update = JTable::getInstance('update'); - $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => '', 'folder' => '')); + $uid = $update->find(array('element' => $this->get('element'), 'type' => 'component', 'client_id' => 1, 'folder' => '')); if ($uid) { diff --git a/libraries/joomla/installer/adapters/file.php b/libraries/joomla/installer/adapters/file.php index 57ce2b6c1779e..c79772b02963d 100644 --- a/libraries/joomla/installer/adapters/file.php +++ b/libraries/joomla/installer/adapters/file.php @@ -254,9 +254,6 @@ public function install() return false; } - // Set the insert id - $row->set('extension_id', $db->insertid()); - // Since we have created a module item, we add it to the installation step stack // so that if we have to rollback the changes we can undo it. $this->parent->pushStep(array('type' => 'extension', 'extension_id' => $row->extension_id)); diff --git a/libraries/joomla/installer/adapters/module.php b/libraries/joomla/installer/adapters/module.php index 43b49726fc573..7c96f0a2f1254 100644 --- a/libraries/joomla/installer/adapters/module.php +++ b/libraries/joomla/installer/adapters/module.php @@ -427,9 +427,6 @@ public function install() return false; } - // Set the insert id - $row->extension_id = $db->insertid(); - // Since we have created a module item, we add it to the installation step stack // so that if we have to rollback the changes we can undo it. $this->parent->pushStep(array('type' => 'extension', 'extension_id' => $row->extension_id)); diff --git a/libraries/joomla/installer/adapters/template.php b/libraries/joomla/installer/adapters/template.php index 7220797b62a93..0d9347b79d9e4 100644 --- a/libraries/joomla/installer/adapters/template.php +++ b/libraries/joomla/installer/adapters/template.php @@ -284,17 +284,24 @@ public function install() if ($this->route == 'install') { - //insert record in #__template_styles - $query = $db->getQuery(true); - $query->insert('#__template_styles'); - $query->set('template=' . $db->Quote($row->element)); - $query->set('client_id=' . $db->Quote($clientId)); - $query->set('home=0'); $debug = $lang->setDebug(false); - $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name'))))); + + $columns = array('template', 'client_id', 'home', 'title', 'params'); + $values = array( + $db->Quote($row->element), $clientId, $db->Quote(0), + $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name')))), + $db->Quote($row->params) ); + $lang->setDebug($debug); - $query->set('params=' . $db->Quote($row->params)); + + //insert record in #__template_styles + $query = $db->getQuery(true); + $query->insert($db->quoteName('#__template_styles')) + ->columns($columns) + ->values(implode(',', $values)); + $db->setQuery($query); + // There is a chance this could fail but we don't care... $db->query(); } @@ -359,7 +366,7 @@ public function uninstall($id) // Deny remove default template $db = $this->parent->getDbo(); - $query = 'SELECT COUNT(*) FROM #__template_styles' . ' WHERE home = 1 AND template = ' . $db->Quote($name); + $query = "SELECT COUNT(*) FROM #__template_styles WHERE home = '1' AND template = " . $db->Quote($name); $db->setQuery($query); if ($db->loadResult() != 0) @@ -412,13 +419,17 @@ public function uninstall($id) } // Set menu that assigned to the template back to default template - $query = 'UPDATE #__menu INNER JOIN #__template_styles' . ' ON #__template_styles.id = #__menu.template_style_id' - . ' SET #__menu.template_style_id = 0' . ' WHERE #__template_styles.template = ' . $db->Quote(strtolower($name)) - . ' AND #__template_styles.client_id = ' . $db->Quote($clientId); + + $query = 'UPDATE #__menu' + . ' SET template_style_id = 0' + . ' WHERE template_style_id in (' + . ' SELECT s.id FROM #__template_styles s' + . ' WHERE s.template = '. $db->Quote(strtolower($name)) .' AND s.client_id = '. $clientId .')'; + $db->setQuery($query); $db->Query(); - $query = 'DELETE FROM #__template_styles' . ' WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $db->Quote($clientId); + $query = 'DELETE FROM #__template_styles WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $clientId; $db->setQuery($query); $db->Query();