/** * Before page is being deleted * * @param object $a_page page object */ static function beforePageDelete($a_page) { $files = self::collectFileItems($a_page, $a_page->getDomDoc()); // delete all file usages include_once "./Modules/File/classes/class.ilObjFile.php"; ilObjFile::_deleteAllUsages($a_page->getParentType() . ":pg", $a_page->getId(), false, $a_page->getLanguage()); include_once "./Modules/File/classes/class.ilObjFile.php"; foreach ($files as $file_id) { if (ilObject::_exists($file_id)) { $file_obj = new ilObjFile($file_id, false); $file_obj->delete(); } } }
/** * update complete page content in db (dom xml content is used) */ function update($a_validate = true, $a_no_history = false, $skip_handle_usages = false) { global $lng, $ilDB, $ilUser, $ilLog, $ilCtrl; $lm_set = new ilSetting("lm"); //echo "<br>**".$this->getId()."**"; //echo "<br>PageObject::update[".$this->getId()."],validate($a_validate)"; //echo "\n<br>dump_all2:".$this->dom->dump_mem(0, "UTF-8").":"; //echo "\n<br>PageObject::update:".$this->getXMLFromDom().":"; //echo "<br>PageObject::update:".htmlentities($this->getXMLFromDom()); // add missing pc ids if (!$this->checkPCIds()) { $this->insertPCIds(); } // test validating if ($a_validate) { $errors = $this->validateDom(); } //echo "-".htmlentities($this->getXMLFromDom())."-"; exit; if (empty($errors)) { $this->performAutomaticModifications(); $content = $this->getXMLFromDom(); // this needs to be locked // write history entry $old_set = $ilDB->query("SELECT * FROM page_object WHERE " . "page_id = " . $ilDB->quote($this->getId(), "integer") . " AND " . "parent_type = " . $ilDB->quote($this->getParentType(), "text")); $last_nr_set = $ilDB->query("SELECT max(nr) as mnr FROM page_history WHERE " . "page_id = " . $ilDB->quote($this->getId(), "integer") . " AND " . "parent_type = " . $ilDB->quote($this->getParentType(), "text")); $last_nr = $ilDB->fetchAssoc($last_nr_set); if ($old_rec = $ilDB->fetchAssoc($old_set)) { // only save, if something has changed and not in layout mode if ($content != $old_rec["content"] && !$a_no_history && !$this->history_saved && !$this->layout_mode && $lm_set->get("page_history", 1)) { if ($old_rec["content"] != "<PageObject></PageObject>") { $ilDB->manipulateF("DELETE FROM page_history WHERE " . "page_id = %s AND parent_type = %s AND hdate = %s", array("integer", "text", "timestamp"), array($old_rec["page_id"], $old_rec["parent_type"], $old_rec["last_change"])); // the following lines are a workaround for // bug 6741 $last_c = $old_rec["last_change"]; if ($last_c == "") { $last_c = ilUtil::now(); } $ilDB->insert("page_history", array("page_id" => array("integer", $old_rec["page_id"]), "parent_type" => array("text", $old_rec["parent_type"]), "hdate" => array("timestamp", $last_c), "parent_id" => array("integer", $old_rec["parent_id"]), "content" => array("clob", $old_rec["content"]), "user_id" => array("integer", $old_rec["last_change_user"]), "ilias_version" => array("text", ILIAS_VERSION_NUMERIC), "nr" => array("integer", (int) $last_nr["mnr"] + 1))); /*$h_query = "REPLACE INTO page_history ". "(page_id, parent_type, hdate, parent_id, content, user_id, ilias_version, nr) VALUES (". $ilDB->quote($old_rec["page_id"]).",". $ilDB->quote($old_rec["parent_type"]).",". $ilDB->quote($old_rec["last_change"]).",". $ilDB->quote($old_rec["parent_id"]).",". $ilDB->quote($old_rec["content"]).",". $ilDB->quote($old_rec["last_change_user"]).",". $ilDB->quote(ILIAS_VERSION_NUMERIC).",". $ilDB->quote($last_nr["mnr"] + 1).")"; //echo "<br><br>+$a_no_history+$h_query"; $ilDB->query($h_query);*/ $this->saveMobUsage($old_rec["content"], $last_nr["mnr"] + 1); $this->saveStyleUsage($old_rec["content"], $last_nr["mnr"] + 1); $this->saveFileUsage($old_rec["content"], $last_nr["mnr"] + 1); $this->saveContentIncludeUsage($old_rec["content"], $last_nr["mnr"] + 1); $this->saveSkillUsage($old_rec["content"], $last_nr["mnr"] + 1); $this->history_saved = true; // only save one time } else { $this->history_saved = true; // do not save on first change } } } //echo htmlentities($content); $em = trim($content) == "<PageObject/>" ? 1 : 0; $iel = $this->containsDeactivatedElements($content); $inl = $this->containsIntLinks($content); /*$query = "UPDATE page_object ". "SET content = ".$ilDB->quote($content)." ". ", parent_id= ".$ilDB->quote($this->getParentId())." ". ", last_change_user= "******" ". ", last_change = now() ". ", is_empty = ".$ilDB->quote($em, "integer")." ". ", active = ".$ilDB->quote($this->getActive())." ". ", activation_start = ".$ilDB->quote($this->getActivationStart())." ". ", activation_end = ".$ilDB->quote($this->getActivationEnd())." ". ", inactive_elements = ".$ilDB->quote($iel, "integer")." ". ", int_links = ".$ilDB->quote($inl, "integer")." ". " WHERE page_id = ".$ilDB->quote($this->getId()). " AND parent_type= ".$ilDB->quote($this->getParentType());*/ $ilDB->update("page_object", array("content" => array("clob", $content), "parent_id" => array("integer", $this->getParentId()), "last_change_user" => array("integer", $ilUser->getId()), "last_change" => array("timestamp", ilUtil::now()), "is_empty" => array("integer", $em), "active" => array("integer", $this->getActive()), "activation_start" => array("timestamp", $this->getActivationStart()), "activation_end" => array("timestamp", $this->getActivationEnd()), "show_activation_info" => array("integer", $this->getShowActivationInfo()), "inactive_elements" => array("integer", $iel), "int_links" => array("integer", $inl)), array("page_id" => array("integer", $this->getId()), "parent_type" => array("text", $this->getParentType()))); // todo put this into update function /* if(!$this->ilias->db->checkQuerySize($query)) { $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE); return false; }*/ // $this->ilias->db->query($query); if (!$skip_handle_usages) { // handle media object usage include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $mob_ids = ilObjMediaObject::_getMobsOfObject($this->getParentType() . ":pg", $this->getId()); $this->saveMobUsage($this->getXMLFromDom()); $this->saveMetaKeywords($this->getXMLFromDom()); foreach ($mob_ids as $mob) { if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") { $mob_obj = new ilObjMediaObject($mob); $usages = $mob_obj->getUsages(false); if (count($usages) == 0) { $mob_obj->delete(); } } } // handle file usages include_once "./Modules/File/classes/class.ilObjFile.php"; $file_ids = ilObjFile::_getFilesOfObject($this->getParentType() . ":pg", $this->getId()); $this->saveFileUsage(); foreach ($file_ids as $file) { if (ilObject::_exists($file)) { $file_obj = new ilObjFile($file, false); $usages = $file_obj->getUsages(); if (count($usages) == 0) { if ($file_obj->getMode() == "filelist") { $file_obj->delete(); } } } } // save style usage $this->saveStyleUsage($this->getXMLFromDom()); // save content include usage $this->saveContentIncludeUsage($this->getXMLFromDom()); $this->saveSkillUsage($this->getXMLFromDom()); } // save internal link information $this->saveInternalLinks($this->getXMLFromDom()); $this->saveAnchors($this->getXMLFromDom()); $this->callUpdateListeners(); //echo "<br>PageObject::update:".htmlentities($this->getXMLContent()).":"; return true; } else { return $errors; } }
public function deleteFile($obj_id) { if (ilObject2::_lookupObjId($obj_id)) { $file = new ilObjFile($obj_id, false); $file->delete(); } }
/** * Delete a file * * @param $obj_id */ public function deleteFile($obj_id) { if (ilObject2::_exists($obj_id, false)) { $file = new ilObjFile($obj_id, false); $file->delete(); } }