Recently I developped some PHP code which delete an article. Here I post the code:
Code: Select all
$p = dirname(dirname(__FILE__));
define('JOOMLA_MINIMUM_PHP', '5.3.10');
if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<'))
{
die('Your host needs to use PHP ' . JOOMLA_MINIMUM_PHP . ' or higher to run this version of Joomla!');
}
$startTime = microtime(1);
$startMem = memory_get_usage();
define('_JEXEC', 1);
if (file_exists($p . '/defines.php'))
{
include_once $p . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', $p);
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
$idArticle=23;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$conditions = array(
$db->quoteName('id') . " = $idArticle",
);
$query->delete($db->quoteName('#__content'));
$query->where($conditions);
$db->setQuery($query);
$result = $db->execute();
Error displaying the error page: Table 's' was not locked with LOCK TABLES SQL=SELECT template, s.params FROM #__template_styles as s LEFT JOIN #__extensions as e ON e.type='template' AND e.element=s.template AND e.client_id=s.client_id WHERE s.client_id = 1 AND home = '1' ORDER BY home: Unknown column 'alias' in 'field list' SQL=UPDATE `#__assets` SET `name`='com_content.article.6',`title`='test article',`rules`='{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":{\"3\":1},\"core.delete\":[],\"core.edit\":{\"4\":1},\"core.edit.state\":{\"5\":1},\"core.edit.own\":[]}',`parent_id`='27',`level`='3',`lft`='23',`rgt`='24',`alias`=NULL WHERE `id`='68'
On your own, does this code goes well and above all, what can I change to resolve this error?
In my opinion, since the db is nested, when I remove the article from "content" table, I forget to delete/update some other tables...but I don't know which!
Thanks