*

kenoffice

  • **
  • 26 posts
BO mgr - deletion of expired listings need improvements
« on: September 06, 2024, 12:21:31 AM »
Hi All
IN BO Manager plugin I have set-up auto-deletion of expired listings after 14 days. Meaning that when listing expire and user don't renew it, then to be automatically deleted.
Now the fun part comes.
Listings are not deleted from all tables in database, some tables still keep records about the expired listing which normally shall be deleted... :(
I dig into BO managed plugin and found that on index.php, the Item::newInstance()->deleteByPrimaryKey( $item_id ) call the function deleteByPrimaryKey from \oc-includes\osclass\model\item.php
There I found only partial deletes:
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_description', "fk_i_item_id = $id");
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_comment' , "fk_i_item_id = $id");
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_resource', "fk_i_item_id = $id");
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_location', "fk_i_item_id = $id");
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_stats'   , "fk_i_item_id = $id");
    $this->dao->delete(DB_TABLE_PREFIX.'t_item_meta'  , "fk_i_item_id = $id");

But wait ! What happens with records from _item, _item_bo_mgr, _item_THEME_NAME, _item_validation ?
Answer: they are not deleted and mess up the functionality of the script.

I know about existence of cleanup utility of core OSC. But is not ok with this. Because this situation can happend:
The user leave the listing to expire; after x days (14 in my case) will be deleted the correspondent rows from tables mentioned in \model\item.php. But on tables _item, _item_bo_mgr, _item_THEME_NAME, _item_validation the records stil remain. The listing appear on user's account and guess what, he press the Re-Publish button. This change the expiration date and will not be "seen" by clean-up utility.

Finally, we reach to situation when on front office of website some "broken" listings still appear, some without title and picture. Are the ones expired and not completely deleted and which the user renewed them, even if the listing was displayed as empty on his account (category name instead of title, and no picture).

In order to have clear the situation, I guess develeoper must take a look:
1. on \oc-includes\osclass\model\item.php, function deleteByPrimaryKey to include all tables related to listings
2. alternatively, BO manager plugin can do this job (cleaning all tables) by adding ad additional function (to supplement the deleteByPrimaryKey from \model\item.php)
I am on gamma theme and last vers of OSC, meaning 8.2.1

For now I will alter the source code and on core file item.php I will add my own rows, indicated the tables which need to be cleared.
But any thoughts to include this in future update of OSC ?
Did anyone encountered this ?
Cheers
There is no perfect classifieds script. I dream to make it.

*

MB Themes

Re: BO mgr - deletion of expired listings need improvements
« Reply #1 on: September 10, 2024, 02:34:23 PM »
Where you see that?
I see:
Code: [Select]
    Item::newInstance()->deleteByPrimaryKey( $item_id );

But it's wrong, we need to use ItemAction to trigger hooks.

Code: [Select]
  $manager = new ItemActions();
  $item_raw = Item::newInstance()->findByPrimaryKey($item_id);
  $item_secret = isset($item_raw['s_secret']) ? $item_raw['s_secret'] : '';
  $manager->delete($item_secret, $item_id);
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots