public function saveAction() { $userid = $this->getUserId(); $datestr = gmdate("Y-m-d\\TH:i:s\\Z"); $this->disableLayout(); $mashupData = $this->getRequest()->getParam(MashupController::MASHUP_DATA, false); $mashupMeta = $this->getRequest()->getParam(MashupController::MASHUP_META, false); if (!$mashupData || !$mashupMeta) { $this->sendError("Usage: POST me some data in " . MashupController::MASHUP_META . " and " . MashupController::MASHUP_DATA); } $mashupUri = $mashupMeta['uri']; $updateMode = false; if (!empty($mashupUri)) { // existing mashup // load it $m = $this->getLA()->loadMashup($mashupUri); if ($m == null) { $this->sendError("Failed to load mashup " . $mashupUri); } $m->setTitle($mashupMeta['title']); // change title $m->setModifyDate($datestr); $updateMode = true; } else { // new mashup $m = new Mashup($this->getLA()->getURIForTitle($mashupMeta['title'], LOOMP::MASHUP()), $userid, $datestr, $datestr, $mashupMeta['title'], array()); } // rights check if ($updateMode && $m->getCreatorId() != $this->getUserId() && $this->view->user['type'] != "admin") { $this->sendError("You have no rights to edit " . $m->getUri()); } $fragments = array(); // add fragments foreach ($mashupData as $fragment) { $fragmentUri = @$fragment['uri']; if (!empty($fragmentUri)) { // existing fragment $f = $this->getLA()->loadFragment($fragmentUri); if ($f == null) { $this->sendError("Failed to find fragment " . $fragmentUri . " in mashup " . $mashupUri); } $f->setTitle($fragment['title']); $f->setContent($fragment['content']); $f->setModifyDate($datestr); //2002-05-30T09:30:10Z } else { // new fragment $class = "Fragment_" . $fragment['type']; $f = new $class($this->getLA()->getURIForTitle($fragment['title'], LOOMP::FRAGMENT()), $userid, $datestr, $datestr, $fragment['title'], $fragment['content'], $fragment['type']); } $fragments[$fragment['order']] = $f; } $deletedFragments = array(); if ($updateMode) { $oldFragments = $m->getFragments(); foreach ($oldFragments as $fragment) { if (!in_array($fragment, $fragments)) { $deletedFragments[] = $fragment; } } } $m->setFragments($fragments); //print_r($m); $this->getLA()->saveMashup($m, $deletedFragments) or $this->sendError("Failed to save Mashup " . $mashupUri); foreach ($m->getFragments() as $fragment) { searchUpdateFragment($fragment); } // print preview link for usage in frontend if ($updateMode) { $this->getLog()->info("Mashup " . $m->getUri() . " updated"); } else { $this->getLog()->info("Mashup " . $m->getUri() . " created"); } print $m->getUri(); }
/** * Removes a single Mashup from RDF Store by deleting all triples describing the mashup URI * as well as all fragments associated with this mashup which are not part of other mashups * * @param Mashup $mashup Mashup Object */ public function removeMashup($mashup) { $this->_removeResWithAllProps($mashup->getUri()); foreach ($mashup->getFragments() as $f) { // consistency check if ($this->_fragmentCount($f->getUri()) == 0) { $this->_removeFragment($f); searchDeleteFragment($f); } } }