Thursday, 29 October 2015
  1 Replies
  1.5K Visits
0
Votes
Undo
Hello everybody,

I have a question here. I lately coded some calendar import that puts together informations on events from both an ics file and an excel file. I almost finished (I think) and tried to make the code as clean as possible, but here I go again on this terrible message saying if I delete the calendar I'll get orphan events, meaning no one can delete calendar from the joomla admin page.

To test my code I had to import then delete calendars several times, and eventually even created triggers to delete all related events, rrules, repetitions, details when I delete an Ical to avoid deleting all this stuff manually.

But I came back on the JEvents code and realized maybe the triggers were not necessary...

I took a look on the JEvents code for deleting icals and I can't figure out why we're talking about "orphan events" here, knowing that all the events which are related to the ics file are deleted later in the _deleteIcal function... Here's the code I think handles the calendar delete :

lines 877 to 943 of icals.php in administrator directory

function delete(){

// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );

$cid = JRequest::getVar( 'cid', array(0) );
JArrayHelper::toInteger($cid);

$db = JFactory::getDBO();

// check this won't create orphan events
$query = "SELECT ev_id FROM #__jevents_vevent WHERE icsid in (".implode(",",$cid).")";
$db->setQuery( $query );
$kids = $db->loadObjectList();
if (count($kids)>0){
$this->setRedirect( "index.php?option=".JEV_COM_COMPONENT."&task=icals.list", JText::_("DELETE_CREATES_ORPHAN_EVENTS") );
return;
}

$icsids = $this->_deleteICal($cid);
$query = "DELETE FROM #__jevents_icsfile WHERE ics_id IN ($icsids)";
$db->setQuery( $query);
$db->query();

$this->setRedirect( "index.php?option=".JEV_COM_COMPONENT."&task=icals.list", "ICal deleted" );
}

function _deleteICal($cid){
$db = JFactory::getDBO();
$icsids = implode(",",$cid);

$query = "SELECT ev_id FROM #__jevents_vevent WHERE icsid IN ($icsids)";
$db->setQuery( $query);
$veventids = $db->loadColumn();
$veventidstring = implode(",",$veventids);

if ($veventidstring) {
// TODO the ruccurences should take care of all of these??
// This would fail if all recurrances have been 'adjusted'
$query = "SELECT DISTINCT (eventdetail_id) FROM #__jevents_repetition WHERE eventid IN ($veventidstring)";
$db->setQuery( $query);
$detailids = $db->loadColumn();
$detailidstring = implode(",",$detailids);

$query = "DELETE FROM #__jevents_rrule WHERE eventid IN ($veventidstring)";
$db->setQuery( $query);
$db->query();

$query = "DELETE FROM #__jevents_repetition WHERE eventid IN ($veventidstring)";
$db->setQuery( $query);
$db->query();

if ($detailidstring) {
$query = "DELETE FROM #__jevents_vevdetail WHERE evdet_id IN ($detailidstring)";
$db->setQuery( $query);
$db->query();
}
}

if ($icsids) {
$query = "DELETE FROM #__jevents_vevent WHERE icsid IN ($icsids)";
$db->setQuery( $query);
$db->query();
}

return $icsids;
}



More precisely, why when you do the request (lines 888 to 891)

$query = "SELECT ev_id FROM #__jevents_vevent WHERE icsid in (".implode(",",$cid).")";
$db->setQuery( $query );
$kids = $db->loadObjectList();
if (count($kids)>0){

You call the events resulting "orphans" , when in fact you do delete them in (lines 936 to 939)

if ($icsids) {
$query = "DELETE FROM #__jevents_vevent WHERE icsid IN ($icsids)";
$db->setQuery( $query);
$db->query();
}


Maybe I got it wrong and it's precisely because I'm not 100% sure about this that I post this. But if I'm right and this is the code to delete ical, the events you're searching for with the first request are not what I would call "orphan events", and you do written the code to delete them, the very same events you get with the select...

Thanks for your reply and sorry if my english isn't correct :D
9 years ago
·
#158964
0
Votes
Undo
We had coded up the event deletion but decided to leave it as a manual process to keep it more under the user's control and therefore avoid the risk of accidental event deletion. Some users were deleting calendars without realising which calendars contained which events.

JEvents Club members can get priority forum support at the Support Forum. As well as access to a variety of custom JEvents addons and benefits. Join the JEvents club today!

  • Page :
  • 1
There are no replies made for this post yet.

Members Area

Show your support

Unlike many Joomla calendars we do not charge to download JEvents - please show your support for this project by becoming a member of the JEvents Club Club members get access to early releases, exclusive member support forums, and Silver and Gold members can use many exciting JEvents addons

Your membership will ensure that JEvents continues to be the best events calendar for Joomla.