Is it possible to update events in an onAfterEventSave trigger

  • Timothy
  • Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 6 months ago #147075 by Timothy
Hi, I'm trying to make a plugin to automatically assign default language data to an event's translation fields.
But I'm having issues getting any db operations to work.

I have no issues with performing db operations in layout overrides but here it seems nothing works.
So I was wondering if it's even possible to perform an update on the events table in an onAfterEventSave trigger?

For reference here the code for the plugin I'm trying to make, including a couple of the ways I've tried to perform the db operation. 

Thank you in advance!
Code:
<?php /**  * @package            Joomla  * @subpackage         Event Booking  */ defined('_JEXEC') or die; class plgCreateEventTranslations extends JPlugin {     /**      * Application object.      *      * @var    JApplicationCms      */     protected $app;     /**      * Database object.      *      * @var    JDatabaseDriver      */     protected $db;     /**      * Create event translations with default language data      *      * @param   EventbookingTableEvent  $row      * @param   array                   $data      * @param   bool                    $isNew  true if create new plan, false if edit      */     public function onAfterSaveEvent($row, $data, $isNew)     {         $db = $this->db;         $query = $db->getQuery(true);                  // QUERY METHOD ATTEMPT (USING QUERYBUILDER)         //$query->update('#__eb_events')         //    ->set('title = ' . $db->quote('CHANGED'))         //    ->where('id = ' . 468);                  //$query->delete('#__eb_events')         //    ->where('id = ' . (int) 468);                  // QUERY METHOD ATTEMPT (USING RAW QUERY STRING)         $query = 'UPDATE #__eb_events SET short_description = "WORKSSS" WHERE id = 468';                  $db->setQuery($query);         $db->execute();                  // STORE METHOD ATTEMPT (USING ROW)             //$row->description = 'TESTESTEST';         //$row->store();                  // STORE METHOD ATTEMPT (USING EVENT)         //$event   = EventbookingHelperDatabase::getEvent(468);         //$event->title = 'ESTESTEST';         //$event->description = 'ESTESTEST';         //$event->store();     } }

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #147078 by Tuan Pham Ngoc
Use the second method should be the right option:

STORE METHOD ATTEMPT (USING ROW)

$row->description = 'TESTESTEST';
$row->store();

The reason is because if you update db directly using query, other plugins might manipulate $row object before calling $row->store(); and it will overritten your change

So if that method does not work for you, please submit a support ticket so that we can help checking directly on your site

Regards,

Tuan

Please Log in or Create an account to join the conversation.