/** * updates an album in the db * * @param album A GalleryAlbum object that already exists in the db. * @param Returns true if successful or false otherwise. */ function updateAlbum($album) { if ($album->getId() == $album->getParentId()) { return false; } $tf = new TextFilter(); $query = "UPDATE " . $this->getPrefix() . "gallery_albums SET\n description = '" . Db::qstr($album->getDescription()) . "',\n name = '" . Db::qstr($album->getName()) . "',\n parent_id = " . $album->getParentId() . ",\n properties = '" . serialize($album->getProperties()) . "',\n show_album = " . $album->getShowAlbum() . ",\n normalized_name = '" . Db::qstr($tf->normalizeText($album->getName())) . "',\n normalized_description = '" . Db::qstr($tf->normalizeText($album->getDescription())) . "',\n\t\t\t\t\t mangled_name = '" . $tf->urlize($album->getName()) . "'\n WHERE id = " . $album->getId() . ";"; return $this->Execute($query); }
function perform() { // get a connection to the db $db = connectDb(); $dbPrefix = getDbPrefix(); $db->debug = false; // no errors here $errors = false; // see how many records we have $queryCount = "SELECT COUNT(*) AS total FROM {$dbPrefix}articles"; $result = $db->Execute($queryCount); $row = $result->FetchRow(); $numRecords = $row["total"]; $this->_totalPosts = $numRecords; // check whether we should use multiple steps $multipleSteps = $numRecords > WIZARD_MAX_RECORDS_THRESHOLD; if ($multipleSteps) { // how many steps do we need? $numSteps = ceil($numRecords / WIZARD_MAX_RECORDS_PER_STEP); $this->_numSteps = $numSteps; //print("using different steps! numSteps = $numSteps<br/>"); } // run the query and loop through the results $query = "SELECT * FROM {$dbPrefix}articles"; if ($multipleSteps) { // generate the LIMIT condition for this page $query .= " LIMIT " . $this->_curStep * WIZARD_MAX_RECORDS_PER_STEP . ", " . WIZARD_MAX_RECORDS_PER_STEP; } //print("query = $query<br/>"); $result = $db->Execute($query); $tf = new TextFilter(); $numPosts = $result->RowCount(); while ($row = $result->FetchRow()) { // for each one of the articles, fill in the mangled_topic, normalized_text and normalized_value $normalizedTopic = Db::qstr($tf->normalizeText($row["topic"])); $postTopic = Db::qstr($row["topic"]); $normalizedText = Db::qstr($tf->normalizeText($row["text"])); $postText = Db::qstr($row["text"]); $mangledTopic = Db::qstr($tf->urlize($row["topic"])); $status = $this->getStatusId($row["old_status"]); $artId = $row["id"]; $catId = $row["category_id"]; $query = "UPDATE {$dbPrefix}articles SET slug = '{$mangledTopic}', date = date, status = {$status}\n WHERE id = {$artId}"; $query2 = "INSERT INTO {$dbPrefix}article_categories_link(article_id, category_id)\n VALUES ( {$artId}, {$catId} )"; $query3 = "INSERT INTO {$dbPrefix}articles_text (article_id,text,topic,normalized_text,normalized_topic,mangled_topic)\n VALUES('{$artId}','{$postText}','{$postTopic}','{$normalizedTopic}','{$normalizedText}','{$mangledTopic}')"; // execute the two queries $res = $db->Execute($query); $res2 = $db->Execute($query2); $res3 = $db->Execute($query3); /*if( !$res || !$res2 || !$res3 ) $errors = true;*/ } // check whether we've already done the last step or not $lastStepDone = $this->_curStep >= $this->_numSteps; // if error if ($errors) { $this->_view = new WizardView("update2"); $this->_view->setErrorMessage("There was an error updating the articles table."); $this->setCommonData(); return false; } //$query1 = "ALTER TABLE {$dbPrefix}articles DROP COLUMN old_status, DROP COLUMN category_id"; //$db->Execute( $query1 ); // if everyhting's fine, say so... if (!$multipleSteps || $lastStepDone) { $this->_view = new WizardView("update3"); $this->_view->setValue("totalPosts", $this->_totalPosts); } else { // if we're using multiple steps, show the same page $this->_view = new WizardView("update2"); $this->_view->setValue("numPosts", $numPosts); $this->_view->setValue("curStep", $this->_curStep + 1); $this->_view->setValue("totalPosts", $this->_totalPosts); $this->_view->setValue("numSteps", $this->_numSteps); $this->_view->setValue("multipleSteps", true); } return true; }
/** * updates a resource in the database. * * @param resource A GalleryResource object with the information of the * resource we'd like to update. * @return Returns true if successful or false otherwise */ function updateResource($resource) { $tf = new TextFilter(); $query = "UPDATE " . $this->getPrefix() . "gallery_resources\n SET album_id = " . $resource->getAlbumId() . ",\n description = '" . Db::qstr($resource->getDescription()) . "',\n flags = " . $resource->getFlags() . ",\n resource_type = " . $resource->getResourceType() . ",\n file_path = '" . $resource->getFilePath() . "',\n file_name = '" . $resource->getFileName() . "',\n metadata = '" . Db::qstr(serialize($resource->getMetadata())) . "',\n\t\t\t\t\t thumbnail_format ='" . $resource->getThumbnailFormat() . "',\n date = '" . $resource->getDate() . "',\n normalized_description = '" . Db::qstr($tf->normalizeText($resource->getDescription())) . "'\n WHERE id = " . $resource->getId(); $result = $this->Execute($query); if (!$result) { return false; } else { return true; } }