I also created entire script in the script folder and continues to execute correctly only if executed via run button and not query string. It still executes what was done before the require command (so it truncates the table but does not repopulate it).
I'll post the code if it can be useful for a suggestion. Thank you:
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$strsql1 = "TRUNCATE TABLE a_events_ccm";
$db->setQuery($strsql1);
$db->execute();
require_once JPATH_ROOT . '/plugins/fabrik_cron/php/scripts/icalendar.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$filename = JPATH_ROOT . '/Gcalendar/basic.ics';
if (file_exists($filename)) {
$ical = new iCalendar();
$ical->parse($filename);
$ical_data = $ical->get_all_data();
$timezone = "{$ical_data['VCALENDAR']['X-WR-TIMEZONE']}";
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set($timezone);
}
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$strsql1 = "INSERT INTO a_events_ccm (StartDate, StartTime, EndDate, EndTime, Title, Location, Description) VALUES ";
if (!empty($ical_data['VEVENT'])) {
foreach ($ical_data['VEVENT'] as $key => $data) {
$start_dttimearr = explode('T', $data['DTSTART']);
$StartDate = $start_dttimearr[0];
$StartTime = $start_dttimearr[1];
$end_dttimearr = explode('T', $data['DTEND']);
$EndDate = $end_dttimearr[0];
$EndTime = $end_dttimearr[1];
$strsql1 .= "('" . $StartDate . "','" . $StartTime . "','" . $EndDate . "','" . $EndTime . "','" . $db->escape($data['SUMMARY']) . "','" . $db->escape($data['LOCATION']) . "','" . $db->escape($data['DESCRIPTION']) . "')";
$strsql1 .= ",";
}
$strsql1 = rtrim($strsql1, ',');
$db->setQuery($strsql1);
$db->execute();
}
header('Location: index.php');
exit;
} else {
}
}
if ($_GET['stage'] == "empty") {
$db = Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$strsql1 = "TRUNCATE TABLE a_events_ccm";
$db->setQuery($strsql1);
$db->execute();
header('Location: index.php');
exit;
}