private function processCat($cat) { $blocksize = 10; $db = JFactory::getDBO(); $query = "SELECT ev.*, cc.name AS category, " . "\n UNIX_TIMESTAMP(ev.publish_up) AS dtstart ," . "\n UNIX_TIMESTAMP(ev.publish_down) AS dtend " . "\n FROM #__events AS ev" . "\n LEFT JOIN #__categories AS cc ON ev.catid = cc.id" . "\n WHERE cc.id = {$cat->id}" . "\n AND migrated = 0" . "\n LIMIT {$blocksize}"; $db->setQuery($query); $detevents = null; $detevents = $db->loadObjectList(); if (count($detevents) == 0) { return 0; } $showBR = intval(JRequest::getVar('showBR', '0')); // get vCal with HTML encoded descriptions global $cal; $cal = new vCal("", true); if (count($detevents) > 0) { foreach ($detevents as $event) { $cal->addEvent($event); // mark as migrated $query = "UPDATE #__events set migrated=1 WHERE id=" . $event->id; $db->setQuery($query); $db->query(); } $detevents = null; global $output; $output = $cal->getVCal(); $cal = null; if ($showBR) { echo "Processing cat {$cat->title}<br/>"; echo $output; echo "<hr/>"; } // Map them to the new cat id $catid = $cat->newid; $access = $cat->access; $state = $cat->published; // find the default icsfile - if none then create a new one $sql = "SELECT * FROM #__jevents_icsfile WHERE icaltype=2 AND isdefault=1"; $db->setQuery($sql); $ics = $db->loadObject(); if (!$ics || is_null($ics)) { $icsid = 0; // new $icsLabel = "{$cat->title} (imp)"; } else { $icsid = $ics->ics_id; $icsLabel = $ics->label; if ($ics->catid == 0) { $sql = "UPDATE #__jevents_icsfile SET catid=" . $cat->newid . " WHERE ics_id=" . $icsid; $db->setQuery($sql); $db->query(); } } $icsFile = iCalICSFile::newICSFileFromString($output, $icsid, $catid, $access, $state, $icsLabel); // DO NOT CLEAN OUT EXISTING EVENTS $icsFileid = $icsFile->store($catid, false); $icsFile = null; } $query = "SELECT count(ev.id)" . "\n FROM #__events AS ev" . "\n LEFT JOIN #__categories AS cc ON ev.catid = cc.id" . "\n WHERE cc.id = {$cat->id}" . "\n AND migrated = 0"; $db->setQuery($query); $detevents = null; $eventsleft = $db->loadResult(); return $eventsleft; }