*

mwindey

  • *****
  • 506 posts
dt_expiration is set to never expires osclass v8.3
« on: April 19, 2025, 01:05:32 PM »
I don't know if it's because of the update to osclass 8.3 but since then every new listing with expiration date is recorded as never expiring. Despite the settings in categories always being set to 60 days.

*

Ajit Sahane

  • ****
  • 204 posts
  • https://bestclassifiedsusa.com
Re: dt_expiration is set to never expires osclass v8.3
« Reply #1 on: April 19, 2025, 02:03:28 PM »
Yes, i am facing this issue. When check db recent few days ads expiry date not recorded as per category expiry days set, like 365 days etc.

Manual ads expiry date change using sql then its shown correct calculated expiry date. but again new ads issue continue.

want to fix from core osclass, theme level no issue found.

*

mwindey

  • *****
  • 506 posts
Re: dt_expiration is set to never expires osclass v8.3
« Reply #2 on: April 19, 2025, 03:38:45 PM »
Found issue in oc-includes/osclass/ItemActions.php: replaced this part and the issue with the expiration date is fixed.

Code: [Select]
    // Manage expiration date
    if($is_add || $this->is_admin) {
      $dt_expiration = Params::getParam('dt_expiration');
     
      if($dt_expiration == -1 || $dt_expiration == '') {
        $aItem['dt_expiration'] = '';
       
      } elseif (
        $dt_expiration != ''
        && (
          ctype_digit($dt_expiration)
          || preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$|', $dt_expiration, $match)
          || preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration, $match)
        )
      ) {
        $aItem['dt_expiration'] = $dt_expiration;
        $_category = osc_get_category_row($aItem['catId']);
       
        if (ctype_digit($dt_expiration)) {
          if (!$this->is_admin && $dt_expiration > $_category['i_expiration_days']) {
            $aItem['dt_expiration'] = $_category['i_expiration_days'];
          }
        } else {
          if(preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration, $match)) {
            $aItem['dt_expiration'] .= ' 23:59:59';
          }
         
          if(!$this->is_admin && strtotime($dt_expiration) > (time() + $_category['i_expiration_days'] * 24 * 3600)) {
            $aItem['dt_expiration'] = $_category['i_expiration_days'];
          }
        }
      } else {
        $_category = osc_get_category_row($aItem['catId']);
        $aItem['dt_expiration'] = (isset($_category['i_expiration_days']) ? $_category['i_expiration_days'] : null);
      }
     
      unset($dt_expiration);
     
    } else {
      $aItem['dt_expiration'] = '';
    }

Replace with:

Code: [Select]
// Manage expiration date
if($is_add || $this->is_admin) {
  $dt_expiration = Params::getParam('dt_expiration');
  $_category = Category::newInstance()->findByPrimaryKey($aItem['catId']);
  $cat_days = isset($_category['i_expiration_days']) ? (int)$_category['i_expiration_days'] : 0;

  if ($dt_expiration == -1) {
    // Never expires
    $aItem['dt_expiration'] = '';

  } elseif ($dt_expiration != '' && (
    ctype_digit($dt_expiration) ||
    preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration) ||
    preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$|', $dt_expiration)
  )) {

    if (ctype_digit($dt_expiration)) {
      // It's a number of days
      $days = (int)$dt_expiration;

      if (!$this->is_admin && $days > $cat_days) {
        $days = $cat_days;
      }

      $aItem['dt_expiration'] = date('Y-m-d H:i:s', time() + ($days * 86400));

    } else {
      // It's a date or datetime string
      if (preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration)) {
        // Gebruik huidige tijd i.p.v. 23:59:59
        $dt_expiration .= ' ' . date('H:i:s');
      }

      // Restrict if date is too far in the future for regular users
      if (!$this->is_admin && strtotime($dt_expiration) > (time() + $cat_days * 86400)) {
        $aItem['dt_expiration'] = date('Y-m-d H:i:s', time() + ($cat_days * 86400));
      } else {
        $aItem['dt_expiration'] = $dt_expiration;
      }
    }

  } else {
    // No valid date or days given, fallback to category limit
    $aItem['dt_expiration'] = date('Y-m-d H:i:s', time() + ($cat_days * 86400));
  }

  unset($dt_expiration);
} else {
  $aItem['dt_expiration'] = '';
}

When a number of days was submitted (e.g. 30), the code simply assigned it directly like this: $aItem['dt_expiration'] = $_category['i_expiration_days'];
When a full date or datetime string was passed, the code tried to add 23:59:59, but sometimes this got overwritten.
For numeric input (number of days), the code did not convert it into a proper datetime.
The category limit (i_expiration_days) was mixed in without clear structure.
« Last Edit: April 19, 2025, 03:44:21 PM by mwindey »

*

Ajit Sahane

  • ****
  • 204 posts
  • https://bestclassifiedsusa.com
Re: dt_expiration is set to never expires osclass v8.3
« Reply #3 on: April 19, 2025, 04:14:25 PM »
🔄 However, one thing I want to reconfirm –
If we change the expiry days for a category later, will the expiry date of already posted ads also update automatically?

Or is it that only new ads will follow the updated expiry setting, and existing ads will retain their originally calculated dt_expiration?

Just want to be 100% sure – so we can recommend this code fix confidently to all users of the Osclass Beta version (v8.3.0) as a must-have improvement.

Thanks!

« Last Edit: April 19, 2025, 04:17:54 PM by Ajit Sahane »

*

mwindey

  • *****
  • 506 posts
Re: dt_expiration is set to never expires osclass v8.3
« Reply #4 on: April 19, 2025, 05:01:39 PM »
No, the expiration date of already posted ads will not update automatically.
Only new ads (or updated ones) will have their dt_expiration recalculated using the current category expiration setting.

When an ad is posted, the expiration date is calculated once based on:

The value submitted in the form (e.g., a number of days or a specific date)
The i_expiration_days setting of the selected category
Whether the user is an admin or not
This value is then stored directly in the database as dt_expiration.
After that, changing the category's expiration setting does not retroactively affect existing ads — there's no built-in mechanism that loops over and updates previous entries.
« Last Edit: April 19, 2025, 05:03:15 PM by mwindey »

*

Ajit Sahane

  • ****
  • 204 posts
  • https://bestclassifiedsusa.com
Re: dt_expiration is set to never expires osclass v8.3
« Reply #5 on: April 23, 2025, 08:14:01 PM »
Waiting from MB team final check in this issue and updates.

*

MB Themes

Re: dt_expiration is set to never expires osclass v8.3
« Reply #6 on: April 24, 2025, 03:08:50 PM »
Try this one, it should limit user just in case you are above expiration days from category and category expiration is defined.
If you specify sooner expiration, or expiration on non-expiring category it still should be "acceptable".

Code: [Select]
    // Manage expiration date
    if($is_add || $this->is_admin) {
      $category = osc_get_category_row($aItem['catId']);
      $category_expiration_days = (isset($category['i_expiration_days']) && $category['i_expiration_days'] > 0) ? $category['i_expiration_days'] : null;
      $dt_expiration = osc_esc_html(Params::getParam('dt_expiration'));

      // Non-expiring listing
      if($dt_expiration == -1 && $this->is_admin) {
        $aItem['dt_expiration'] = '';
       
      // Expiration set as number of days
      } else if (
        $dt_expiration != ''
        && (
          ctype_digit($dt_expiration)
          || preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$|', $dt_expiration, $match)
          || preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration, $match)
        )
      ) {
        $aItem['dt_expiration'] = $dt_expiration;

        if(ctype_digit($dt_expiration)) {
          // Expiration defined by user is beyond category expiration days
          if(!$this->is_admin && $dt_expiration > $category_expiration_days && $category_expiration_days > 0) {
            $aItem['dt_expiration'] = $category_expiration_days;
          }
         
        } else {
          if(preg_match('|^([0-9]{4})-([0-9]{2})-([0-9]{2})$|', $dt_expiration, $match)) {
            $aItem['dt_expiration'] .= ' 23:59:59';
          }
         
          // Expiration defined by user is beyond category expiration date
          if(!$this->is_admin && strtotime($dt_expiration) > (time() + $category_expiration_days * 24 * 3600) && $category_expiration_days > 0) {
            $aItem['dt_expiration'] = $category_expiration_days;
          }
        }
       
      } else {
        $aItem['dt_expiration'] = ($category_expiration_days > 0 ? $category_expiration_days : '');
       
      }
     
      unset($dt_expiration);
     
    } else {
      $aItem['dt_expiration'] = '';
    }
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 506 posts
Re: dt_expiration is set to never expires osclass v8.3
« Reply #7 on: April 24, 2025, 03:58:20 PM »
So Ajit Sahane, the code I gave is identical to the solution from MB Themes.... Seems safe to use so  8) I've been doing it for days  :D

*

Ajit Sahane

  • ****
  • 204 posts
  • https://bestclassifiedsusa.com
Re: dt_expiration is set to never expires osclass v8.3
« Reply #8 on: April 25, 2025, 06:40:38 AM »
Yes, thanks. I am used this -

 
Code: [Select]
UPDATE oc_t_item
SET dt_expiration = DATE_ADD(dt_pub_date, INTERVAL 365 DAY)
WHERE dt_expiration = '9999-12-31 23:59:59';


to manual update all items expiry date from backend phpmyadmin change your table name and category expiry days ( my case 365 days, your case 3 month - 6 month etc check this )


Check once, and give me corrected sql query to update expiry date as per this new code
« Last Edit: April 25, 2025, 06:44:50 AM by Ajit Sahane »

*

mwindey

  • *****
  • 506 posts
Re: dt_expiration is set to never expires osclass v8.3
« Reply #9 on: April 25, 2025, 09:38:36 AM »
@Ajit

Yes, your original query works perfectly if you want to hardcode 365 days as the expiration for all items that currently have '9999-12-31 23:59:59' as their expiration date:
Code: [Select]
UPDATE oc_t_item
SET dt_expiration = DATE_ADD(dt_pub_date, INTERVAL 365 DAY)
WHERE dt_expiration = '9999-12-31 23:59:59';

Or maybe you want the code I gave to be modified specifically for you and have it count 365 days for all existing ones? Currently the code I gave uses the days that were set per category in your admin categories
« Last Edit: April 25, 2025, 09:42:18 AM by mwindey »

*

MB Themes

Re: dt_expiration is set to never expires osclass v8.3
« Reply #10 on: April 25, 2025, 09:44:12 AM »
So Ajit Sahane, the code I gave is identical to the solution from MB Themes.... Seems safe to use so  8) I've been doing it for days  :D

30 mins  ;D
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 506 posts
Re: dt_expiration is set to never expires osclass v8.3
« Reply #11 on: April 25, 2025, 09:52:12 AM »
@MB Themes

Ah, so the admin is doing a '30-minute magic test,'  :) and I've been here debugging for days, haha! Let's hope your quick test works as well as my days-long code marathon ;D
But seriously, I do appreciate all the rest of the work you're doing!  :-*
« Last Edit: April 25, 2025, 09:56:24 AM by mwindey »

*

Ajit Sahane

  • ****
  • 204 posts
  • https://bestclassifiedsusa.com
Re: dt_expiration is set to never expires osclass v8.3
« Reply #12 on: April 26, 2025, 06:06:23 AM »
Guy's this sql query was just for once update where never expire shown. I hope recent new expiry code work well and newer item set properly category expiry days or other days which admin setup. So recent few items only needed sql query to update this date.