Skip to content

Commit

Permalink
Fix inconsistent code in JTable
Browse files Browse the repository at this point in the history
  • Loading branch information
joomdonation committed Jan 28, 2016
1 parent e45cd71 commit 2d413a3
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions libraries/joomla/table/table.php
Expand Up @@ -1037,8 +1037,11 @@ public function delete($pk = null)
*/
public function checkOut($userId, $pk = null)
{
$checkedOutField = $this->getColumnAlias('checked_out');
$checkedOutTimeField = $this->getColumnAlias('checked_out_time');

// If there is no checked_out or checked_out_time field, just return true.
if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
if (!property_exists($this, $checkedOutField) || !property_exists($this, $checkedOutTimeField))
{
return true;
}
Expand Down Expand Up @@ -1073,15 +1076,15 @@ public function checkOut($userId, $pk = null)
// Check the row out by primary key.
$query = $this->_db->getQuery(true)
->update($this->_tbl)
->set($this->_db->quoteName($this->getColumnAlias('checked_out')) . ' = ' . (int) $userId)
->set($this->_db->quoteName($this->getColumnAlias('checked_out_time')) . ' = ' . $this->_db->quote($time));
->set($this->_db->quoteName($checkedOutField) . ' = ' . (int) $userId)
->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($time));
$this->appendPrimaryKeys($query, $pk);
$this->_db->setQuery($query);
$this->_db->execute();

// Set table values in the object.
$this->checked_out = (int) $userId;
$this->checked_out_time = $time;
$this->$checkedOutField = (int) $userId;
$this->$checkedOutTimeField = $time;

return true;
}
Expand All @@ -1100,8 +1103,11 @@ public function checkOut($userId, $pk = null)
*/
public function checkIn($pk = null)
{
$checkedOutField = $this->getColumnAlias('checked_out');
$checkedOutTimeField = $this->getColumnAlias('checked_out_time');

// If there is no checked_out or checked_out_time field, just return true.
if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
if (!property_exists($this, $checkedOutField) || !property_exists($this, $checkedOutTimeField))
{
return true;
}
Expand Down Expand Up @@ -1133,17 +1139,17 @@ public function checkIn($pk = null)
// Check the row in by primary key.
$query = $this->_db->getQuery(true)
->update($this->_tbl)
->set($this->_db->quoteName($this->getColumnAlias('checked_out')) . ' = 0')
->set($this->_db->quoteName($this->getColumnAlias('checked_out_time')) . ' = ' . $this->_db->quote($this->_db->getNullDate()));
->set($this->_db->quoteName($checkedOutField) . ' = 0')
->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($this->_db->getNullDate()));
$this->appendPrimaryKeys($query, $pk);
$this->_db->setQuery($query);

// Check for a database error.
$this->_db->execute();

// Set table values in the object.
$this->checked_out = 0;
$this->checked_out_time = '';
$this->$checkedOutField = 0;
$this->$checkedOutTimeField = '';

return true;
}
Expand Down Expand Up @@ -1202,8 +1208,10 @@ public function hasPrimaryKey()
*/
public function hit($pk = null)
{
$hitsField = $this->getColumnAlias('hits');

// If there is no hits field, just return true.
if (!property_exists($this, 'hits'))
if (!property_exists($this, $hitsField))
{
return true;
}
Expand Down Expand Up @@ -1235,7 +1243,7 @@ public function hit($pk = null)
// Check the row in by primary key.
$query = $this->_db->getQuery(true)
->update($this->_tbl)
->set($this->_db->quoteName($this->getColumnAlias('hits')) . ' = (' . $this->_db->quoteName($this->getColumnAlias('hits')) . ' + 1)');
->set($this->_db->quoteName($hitsField) . ' = (' . $this->_db->quoteName($hitsField) . ' + 1)');
$this->appendPrimaryKeys($query, $pk);
$this->_db->setQuery($query);
$this->_db->execute();
Expand Down Expand Up @@ -1266,7 +1274,8 @@ public function isCheckedOut($with = 0, $against = null)
// Handle the non-static case.
if (isset($this) && ($this instanceof JTable) && is_null($against))
{
$against = $this->get('checked_out');
$checkedOutField = $this->getColumnAlias('checked_out');
$against = $this->get($checkedOutField);
}

// The item is not checked out or is checked out by the same user.
Expand Down Expand Up @@ -1565,17 +1574,20 @@ public function publish($pks = null, $state = 1, $userId = 0)
$pks = array($pk);
}

$publishedField = $this->getColumnAlias('published');
$checkedOutField = $this->getColumnAlias('checked_out');

foreach ($pks as $pk)
{
// Update the publishing state for rows with the given primary keys.
$query = $this->_db->getQuery(true)
->update($this->_tbl)
->set($this->_db->quoteName($this->getColumnAlias('published')) . ' = ' . (int) $state);
->set($this->_db->quoteName($publishedField) . ' = ' . (int) $state);

// Determine if there is checkin support for the table.
if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time'))
{
$query->where('(' . $this->getColumnAlias('checked_out') . ' = 0 OR ' . $this->getColumnAlias('checked_out') . ' = ' . (int) $userId . ')');
$query->where('(' . $this->_db->quoteName($checkedOutField) . ' = 0 OR ' . $this->_db->quoteName($checkedOutField) . ' = ' . (int) $userId . ')');
$checkin = true;
}
else
Expand Down Expand Up @@ -1618,7 +1630,6 @@ public function publish($pks = null, $state = 1, $userId = 0)

if ($ours)
{
$publishedField = $this->getColumnAlias('published');
$this->$publishedField = $state;
}
}
Expand Down

0 comments on commit 2d413a3

Please sign in to comment.