Last active
March 22, 2022 10:29
-
-
Save joomdonation/94dd692cfd2d890259c9762ad1a2d45f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function delete_attachments() | |
{ | |
$db = Factory::getDbo(); | |
$query = $db->getQuery(true); | |
$query->select('attachments') | |
->from('#__helpdeskpro_tickets') | |
->where('attachments != ""') | |
->where('YEAR(created_date) <= 2019'); | |
$db->setQuery($query); | |
$messages = $db->loadObjectList(); | |
$path = JPATH_ROOT . '/media/com_helpdeskpro/attachments/'; | |
$count = 0; | |
foreach ($messages as $message) | |
{ | |
if ($message->attachments) | |
{ | |
$files = explode('|', $message->attachments); | |
foreach ($files as $file) | |
{ | |
if (empty($file)) | |
{ | |
continue; | |
} | |
$filePath = $path . $file; | |
if (file_exists($filePath)) | |
{ | |
$count++; | |
//File::delete($filePath); | |
} | |
} | |
} | |
} | |
// Query messages | |
$query->clear() | |
->select('attachments') | |
->from('#__helpdeskpro_messages') | |
->where('attachments != ""') | |
->where('YEAR(date_added) <= 2019'); | |
$db->setQuery($query); | |
$messages = $db->loadObjectList(); | |
foreach ($messages as $message) | |
{ | |
if ($message->attachments) | |
{ | |
$files = explode('|', $message->attachments); | |
foreach ($files as $file) | |
{ | |
if (empty($file)) | |
{ | |
continue; | |
} | |
$filePath = $path . $file; | |
if (file_exists($filePath)) | |
{ | |
$count++; | |
//File::delete($filePath); | |
} | |
} | |
} | |
} | |
echo $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment