JTable->store() - updating 'content' article returns 1054

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Norguad
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sat Sep 22, 2007 8:21 am

JTable->store() - updating 'content' article returns 1054

Postby Norguad » Sun Oct 22, 2017 4:27 am

Hi all,

I have an external component which should also be able to add articles into core 'content' table.

My code looks like this:

Code: Select all

       
        $db = JFactory::getDbo();
        if (version_compare(JVERSION, '3.0', 'lt')) {
            JTable::addIncludePath(JPATH_PLATFORM . 'joomla/database/table');
        }
       
        $article = JTable::getInstance('content');
 
        // $updated is a parametr in function call: (integer) id of already existing article
        if ( $updated ) {
            $article->load($updated);
        }
       
        $article->title             = $title;
        $article->alias             = JFilterOutput::stringURLsafe($title);
        $article->introtext         = $content;
        $article->catid             = 104;
        $article->created           = JFactory::getDate()->toSQL();
        $article->created_by        = 167;
        $article->created_by_alias   = 'My Component';
        $article->state             = $published;
        $article->access            = 1;
        $article->language          = 'en-GB';
        $article->attribs           = '';
       
        $article->fulltext = '';
        $article->images = '';
        $article->urls = '';
        $article->metakey = '';
        $article->metadesc = '';
        $article->metadata = '';
        $article->xreference = '';
       
        $article->publish_up = JFactory::getDate()->toSQL();
        $article->publish_down = $db->getNullDate();
        $article->version++;
       
        // Check to make sure our data is valid, raise notice if it's not.
        if (!$article->check()) {
                JError::raiseNotice(500, $article->getError());
                return FALSE;
        }
       
        // Now store the article, raise notice if it doesn't get stored.
        if (!$article->store(TRUE)) {
                JError::raiseNotice(500, $article->getError());
                return FALSE;
        }
 


If I save it without "$updated" called, everything runs perfectly and the article is created, but if $updated = id of an existing article - I get this error: 1054 - Unknown column 'alias' in 'field list'

Even if I remove all the lines setting params or use different order and so on (I really tried tons of stuff) it returns the error above.

In my opinion if I just load the article and save it right away, it is still the same object and there should be no errors, so why do I get the 1054 error?

P.s.: the $article->check runs ok everytime.

Thanks a lot for help!!!

User avatar
lefteriskavadas
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Fri Feb 05, 2016 6:10 pm
Location: Athens, Greece
Contact:

Re: JTable->store() - updating 'content' article returns 1054

Postby lefteriskavadas » Mon Oct 23, 2017 3:31 pm

Hi,

The most easy way to troubleshoot this is to enable the system debugging under Joomla global configuration.

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8746
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: JTable->store() - updating 'content' article returns 1054

Postby toivo » Mon Oct 23, 2017 5:50 pm

The debugging option does not quite deliver in this particular case. I happened to be working on a similar extension and tried the store() method, logged a faulty query but could not pinpoint its origin.

The error is reported when the store() method triggers the update of the #__assets table, which of course does not have a column called alias:
...`lft`='298',`rgt`='299',`alias`=NULL WHERE `id` = '179'
I am guessing that it is some leftover in the query object, not cleaned after the previous query addressed the #_-content table. Not sure if this can be reported as a bug if the script is not part of the Joomla core, which works all right and updates the #__assets table when existing articles are updated.

The following rough try - catch block shows how to report the offending query.

Code: Select all

   try
   {
      $result = $article->store(true);
      $msg   = 'an existing article was stored all right';
      echo $msg . $crlf . $crlf;
   }
   catch (JDatabaseExceptionExecuting $e)
   {   
      $msg   = 'JDatabaseExceptionExecuting - article->store() error details:';
      echo $msg . $crlf;      
      do
      {
         $msg   = ' File: ' . $e->getFile() . ' - line: ' . $e->getLine() .  "\r\n - message: " . $e->getMessage() . "\r\n - code: " . $e->getCode() . "\r\n - class: " . get_class($e) .  "\r\n - from: " . __FILE__ .  "\r\n - line: " . __LINE__;
         echo $msg . $crlf;
         $msg   = ' - query = ' . $e->getQuery();
         echo $msg  . $crlf;
      }
      while ($e = $e->getPrevious());
      exit;
   }
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100

User avatar
lefteriskavadas
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Fri Feb 05, 2016 6:10 pm
Location: Athens, Greece
Contact:

Re: JTable->store() - updating 'content' article returns 1054

Postby lefteriskavadas » Tue Oct 24, 2017 12:42 pm

Probably you are using a wrong table object.

Use:

Code: Select all

var_dump($article); die;


to see that you are actually using the correct table class

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8746
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: JTable->store() - updating 'content' article returns 1054

Postby toivo » Tue Oct 24, 2017 2:56 pm

That is not the case. The same code stores a new article into the content table and also adds a row into the assets table.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100

Norguad
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sat Sep 22, 2007 8:21 am

Re: JTable->store() - updating 'content' article returns 1054

Postby Norguad » Wed Oct 25, 2017 9:16 am

Hello,

so I am considering, that it is more a "Joomla bug" ?

Or do I really do something wrong?

Btw. I solved it already by writing my custom store function using the JDatabase class, but anyway, I would know the real reason for the error as this code (I wrote above) is from a Joomla Advanced book I bought in store.

Thanks to all :-)

User avatar
toivo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8746
Joined: Thu Feb 15, 2007 5:48 am
Location: Nottingham, UK
Contact:

Re: JTable->store() - updating 'content' article returns 1054

Postby toivo » Thu Oct 26, 2017 11:53 am

Norguad wrote:this code (I wrote above) is from a Joomla Advanced book I bought in store
The book was published in 2013. Subsequent updates to the framework may have introduced subtle differences which now cause a bug when an external script uses the store() method to update an existing article.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100

alcatel444
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Aug 25, 2011 1:25 pm

Re: JTable->store() - updating 'content' article returns 1054

Postby alcatel444 » Sat Oct 28, 2017 6:10 pm

toivo wrote:
Norguad wrote:this code (I wrote above) is from a Joomla Advanced book I bought in store
The book was published in 2013. Subsequent updates to the framework may have introduced subtle differences which now cause a bug when an external script uses the store() method to update an existing article.

Do you recommend Any Books to learn joomla Development that are up to date with the latest Joomla Version ?


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 2 guests