From: Steve Sutton Date: Thu, 13 Feb 2014 20:45:53 +0000 (+0000) Subject: add for Toolbox Import X-Git-Tag: v1.0.0~46 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d40c6f791b967446e8ae3db2d4501f45d177c1d8;p=web%2FTroutCreek.git add for Toolbox Import --- diff --git a/Toolkit/Toolbox/Importer/Controller.php b/Toolkit/Toolbox/Importer/Controller.php new file mode 100644 index 0000000..80589e4 --- /dev/null +++ b/Toolkit/Toolbox/Importer/Controller.php @@ -0,0 +1,711 @@ +setDbhLocal($pdo); + $this->setDbhRemote($pdo2); + } + + public function createNewPage($id, $name, $parent, $pos) + { + try { + $sql = " + SELECT max(id) + FROM paragraphs"; + $stmt = $this->dbhLocal->query($sql); + $maxId = $stmt->fetchColumn(); + ++$maxId; + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + $page = new Toolkit_Toolbox_Importer_Pages(); + $page->setId($id) + ->setActive(true) + ->setHidden(false) + ->setMobile_active(false) + ->setHeadline(false) + ->setTemplate(1) + ->setParagraph_links(false) + ->setSearch_form(false) + ->setInclude_coupons(false) + ->setInclude_members(false) + ->setNavigation_name($name) + ->setParent($parent) + ->setPos($pos) + ->save($this->dbhLocal); + var_dump($page); + $paragraph = new Toolkit_Toolbox_Importer_Paragraphs(); + $paragraph->setId($maxId) + ->setActive(true) + ->setPage($id) + ->setPos(1) + ->save($this->dbhLocal); + var_dump($paragraph); + } + + public function cleanToolboxTables() + { + try { + $this->dbhLocal->query("DELETE FROM toolbox.pages"); + $this->dbhLocal->query("DELETE FROM toolbox.pages_draft"); + $this->dbhLocal->query("DELETE FROM toolbox.pages_history"); + $this->dbhLocal->query("DELETE FROM toolbox.paragraphs"); + $this->dbhLocal->query("DELETE FROM toolbox.paragraphs_draft"); + $this->dbhLocal->query("DELETE FROM toolbox.paragraphs_history"); + $this->dbhLocal->query("DELETE FROM toolbox.files"); + $this->dbhLocal->query("DELETE FROM toolbox.files_draft"); + $this->dbhLocal->query("DELETE FROM toolbox.files_history"); + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function resetMemberFlags() + { + try { + $sql = " + UPDATE toolbox.pages + SET include_members = :include_member, + include_member_map = :include_member_map, + search_form = :search_form + WHERE id = :id"; + $update = $this->dbhLocal->prepare($sql); + $sql = " + SELECT id,category,no_search_form,include_member_map,region + FROM oldtoolbox.bus_category + WHERE id IN + (SELECT DISTINCT catid FROM oldtoolbox.bus_cat_member)"; + $stmt = $this->dbhLocal->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $includeMember = true; + $update->bindParam(':include_member', $includeMember, PDO::PARAM_BOOL); + $includeMemberMap = (bool)$row['include_member_map']; + $update->bindParam(':include_member_map', $includeMemberMap, PDO::PARAM_BOOL); + $searchForm = (bool) (!$row['no_search_form']); + $update->bindParam(':search_form', $searchForm, PDO::PARAM_BOOL); + $update->bindParam(':id', $row['id'], PDO::PARAM_INT); + var_dump($row); + var_dump($searchForm); + var_dump($includeMember); + var_dump($includeMemberMap); + $update->execute(); + + } + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + + } + + public function resetMemberWithRegions() + { + try { + $sql = " + UPDATE toolbox.pages + SET include_members = :include_member, + include_member_map = :include_member_map, + search_form = :search_form + WHERE id = :id"; + $update = $this->dbhLocal->prepare($sql); + $sql = " + INSERT INTO toolbox.member_regions2toolbox_pages + (page, region) + VALUES + (:page, :region)"; + $addPageRegion = $this->dbhLocal->prepare($sql); + $sql = " + SELECT id,category,no_search_form,include_member_map,region + FROM oldtoolbox.bus_category + WHERE region IS NOT NULL"; + $stmt = $this->dbhLocal->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $includeMember = false; + $update->bindParam(':include_member', $includeMember, PDO::PARAM_BOOL); + $includeMemberMap = (bool)$row['include_member_map']; + $update->bindParam(':include_member_map', $includeMemberMap, PDO::PARAM_BOOL); + $searchForm = (bool) (!$row['no_search_form']); + $update->bindParam(':search_form', $searchForm, PDO::PARAM_BOOL); + $update->bindParam(':id', $row['id'], PDO::PARAM_INT); + var_dump($row); + $update->execute(); + $addPageRegion->bindParam(':page', $row['id'], PDO::PARAM_INT); + $addPageRegion->bindParam(':region', $row['region'], PDO::PARAM_INT); + $addPageRegion->execute(); + } + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function getOldPages() + { + $mainParaStartCounter = 5000; + $sql = " + SELECT * + FROM files + WHERE bus_id = :id + ORDER BY pos"; + $getFiles = $this->dbhRemote->prepare($sql); + $sql = " + SELECT b.*,bcb.pos + FROM bus b, bus_category_bus bcb + WHERE bcb.busid = b.id + AND bcb.catid = :catid + ORDER BY bcb.pos"; + $getParas = $this->dbhRemote->prepare($sql); + try { + $sql = " + SELECT * + FROM bus_category + ORDER BY parent,pos"; + $stmt = $this->dbhRemote->query($sql); + $stmt->execute(); + + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + // first paragraph actually comes from the old bus_category table + $paragraph = new Toolkit_Toolbox_Importer_Paragraphs(); + $paragraph + ->setId(++$mainParaStartCounter) + ->setTitle($row['intro']) + ->setPage($row['id']) + ->setPos(1) + ->setActive(true) + ->setDescription($row['description']) + ->setCaption($row['imagename']) + ->setImage($row['image']); + $this->paragraphs[] = $paragraph; + // now let's get the paragraphs from bus_category_bus and bus + // remember that we need to increment the pos by one + // because we already have one paragraph + $getParas->bindValue( + ":catid", + $row['id'], + PDO::PARAM_INT + ); + $getParas->execute(); + while ($row2 = $getParas->fetch(PDO::FETCH_ASSOC)) { + $paragraph = new Toolkit_Toolbox_Importer_Paragraphs(); + $paragraph + ->setId($row2['id']) + ->setTitle($row2['name']) + ->setPage($row['id']) + ->setPos($row2['pos'] + 1) + ->setActive(true) + ->setDescription($row2['description']) + ->setCaption($row2['imagename']) + ->setImage($row2['image']); + $this->paragraphs[] = $paragraph; + // get the files for this paragraph + $getFiles->bindParam( + ':id', + $row2['id'], + PDO::PARAM_INT + ); + $getFiles->execute(); + while ($row3 = $getFiles->fetch(PDO::FETCH_ASSOC)) { + $file = new Toolkit_Toolbox_Importer_Files(); + $file + ->setId($row3['id']) + ->setFilename($row3['filename']) + ->setBytes($row3['bytes']) + ->setType($row3['type']) + ->setUrltext($row3['urltext']) + ->setParagraph($row2['id']) + ->setPos($row3['pos']); + $this->files[] = $file; + } + } + $page = new Toolkit_Toolbox_Importer_Pages(); + $includeMembers = false; + $searchForm = false; + $includeMemberMap = (bool)$row['include_member_map']; + $headline + = ($row['featured']) + ? true + : false; + $active + = ($row['active']) + ? true + : false; + $page + ->setId($row['id']) + ->setActive($active) + ->setMobile_active($active) + ->setMeta_title($row['title']) + ->setMeta_description($row['meta_descr']) + ->setNavigation_name($row['category']) + ->setPos($row['pos']) + ->setParent($row['parent']) + ->setKeyword($row['keyword']) + ->setTemplate($row['template']) + ->setHeadline($headline) + ->setHeadline_intro($row['feature_intro']) + ->setInclude_coupons(false) + ->setInclude_members($includeMembers) + ->setInclude_member_map($includeMemberMap) + ->setSearch_form($searchForm) + ->setShort_url($row['short_url']) + ->setParagraph_links($row['section_links']); + + // set the page to pages array + $this->pages[$page->getParent()][$page->getId()] = $page; + } + //var_dump($this->pages); + //var_dump($this->paragraphs); + var_dump($this->files); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function getNewParagraphs() + { + $sql = " + SELECT * + FROM paragraphs + WHERE image != '' + AND image not like 'is%'"; + $this->paragraphs = array(); + try { + $stmt = $this->dbhLocal->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $paragraph = new Toolkit_Toolbox_Importer_Paragraphs(); + $paragraph + ->setId($row['id']) + ->setImage($row['image']); + $this->paragraphs[] = $paragraph; + } +// var_dump($this->paragraphs); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function getNewParagraphsWithDescr() + { + $sql = " + SELECT * + FROM paragraphs + WHERE description != '' + AND strpos(description, 'ht_images') > 0"; + $this->paragraphs = array(); + try { + $stmt = $this->dbhLocal->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $paragraph = new Toolkit_Toolbox_Importer_Paragraphs(); + $paragraph + ->setId($row['id']) + ->setDescription($row['description']); + preg_match_all('/< *img[^>]*src *= *["\']?([^"\']*)/i', $row['description'], $matches); + if ($matches) { + foreach ($matches[1] as $match) { + $this->htImages[$match] = true; + } + } + $this->paragraphs[] = $paragraph; + } +// var_dump($this->htImages); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function getNewFiles() + { + $this->files = array(); + $sql = " + SELECT * + FROM files + WHERE filename != '' + AND filename not like 'fs%'"; + try { + $stmt = $this->dbhLocal->query($sql); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + $file = new Toolkit_Toolbox_Importer_Files(); + $file + ->setId($row['id']) + ->setFilename($row['filename']); + $this->files[] = $file; + } +// var_dump($this->files); + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function resetSequences() + { + $this->_resetPagesSequence(); + $this->_resetParagraphsSequence(); + $this->_resetFilesSequence(); + } + + private function _resetPagesSequence() + { + try { + $this->dbhLocal->query( + "SELECT setval('pages_id_seq', (SELECT max(id) FROM pages))" + ); + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + private function _resetParagraphsSequence() + { + try { + $this->dbhLocal->query( + "SELECT setval('paragraphs_id_seq', (SELECT max(id) FROM paragraphs))" + ); + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + private function _resetFilesSequence() + { + try { + $this->dbhLocal->query( + "SELECT setval('files_id_seq', (SELECT max(id) FROM files))" + ); + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function addPages() + { + if (!is_array($this->pages)) { + die('no pages'); + } + foreach ($this->pages as $parent => $pages) { + foreach ($pages as $page) { + $page->save($this->dbhLocal); + } + } + } + + public function addParagraphs() + { + if (!is_array($this->paragraphs)) { + return false; + } + foreach ($this->paragraphs as $paragraph) { + $paragraph->save($this->dbhLocal); + } + } + + public function addFiles() + { + if (!is_array($this->files)) { + return false; + } + foreach ($this->files as $file) { + $file->save($this->dbhLocal); + } + } + + public function addFolder($folderName, $parentId) + { + if (!is_numeric($parentId)) { + throw new InvalidArgumentException('parentId must be numeric'); + } + if ($folderName == '') { + throw new InvalidArgumentException('folderName must not be empty'); + } + try { + // check to see if the folder is already there + $sql = " + SELECT id + FROM ckeditor_folders + WHERE name = :name"; + $stmt2 = $this->dbhLocal->prepare($sql); + $stmt2->bindParam(':name', $folderName); + $stmt2->execute(); + $folderId = $stmt2->fetchColumn(); + if ($folderId) { + return $folderId; + } else { + $sql = " + INSERT INTO ckeditor_folders + (name, parent) + VALUES + (:name, :parent)"; + $stmt = $this->dbhLocal->prepare($sql); + $stmt->bindParam(':name', $folderName, PDO::PARAM_STR); + $stmt->bindParam(':parent', $parentId, PDO::PARAM_INT); + $stmt->execute(); + return $this->dbhLocal->lastInsertId('ckeditor_folders_id_seq'); + } + } catch (PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + public function addImage(Toolkit_FileServer_ImageAdapter $ia, $folder, $image) + { + if ($image == '') { + throw new InvalidArgumentException('Image must not be empty'); + } + if (!is_numeric($folder['id'])) { + throw new InvalidArgumentException('Folder array must contain id'); + } + // check to see if the folder is already there + $sql = " + SELECT name_on_disk + FROM ckeditor_images + WHERE file_name = :file_name"; + $stmt2 = $this->dbhLocal->prepare($sql); + $stmt2->bindParam(':file_name', $image); + $stmt2->execute(); + $imageName = $stmt2->fetchColumn(); + if ($imageName) { + return $imageName; + } + $imageUrl + = FILEMANAGER_URL_ORG + . $folder['path'] + . urlencode($image); + if ($image != '') { + try { + $img = $ia->upload($imageUrl); + } catch(PEAR_Exception $e) { + Toolkit_Common::handleError($e); + } catch(Toolkit_FileServer_Exception $e) { + return false; + } + } + $dimensions = $ia->getImageSize(CKIMAGE . $img['name']); + $sql = " + INSERT INTO ckeditor_images (file_name, name_on_disk, folder, + original_width, original_height) + VALUES (:fname, :nod, :folder, :width, :height)"; + + $stmt = $this->dbhLocal->prepare($sql); + $stmt->bindParam( + ':fname', + $image, + PDO::PARAM_STR + ); + $stmt->bindParam(':nod', $img['name'], PDO::PARAM_STR); + $stmt->bindValue(':folder', $folder['id'], PDO::PARAM_INT); + $stmt->bindValue(':width', $dimensions[0], PDO::PARAM_INT); + $stmt->bindValue(':height', $dimensions[1], PDO::PARAM_INT); + + $stmt->execute(); + return $img['name']; + } + + public function importFiles(Toolkit_FileServer_FileAdapter $fs) + { + if (is_array($this->files)) { + foreach ($this->files as $file) { + $filename = $file->getFilename(); + $pattern = '/^fs/'; + if ($filename != '' && !preg_match($pattern, $filename)) { + $file->importFile($this->dbhLocal, $fs); + } + } + } + } + + public function importImages(Toolkit_Image_Server $is) + { + if (is_array($this->paragraphs)) { + foreach ($this->paragraphs as $paragraph) { + $img = $paragraph->getImage(); + $pattern = '/^is/'; + if ($img != '' && !preg_match($pattern, $img)) { + $paragraph->importImage($this->dbhLocal, $is); + } + } + } + } + + public function importParagraphImages(Toolkit_FileServer_ImageAdapter $ia) + { + if (is_array($this->htImages)) { + foreach ($this->htImages as $href => $found) { + // parse out the url to find the ending +// var_dump($href); +// var_dump(FILEMANAGER_URL_ORG); + $dirPart = str_replace(FILEMANAGER_URL_ORG, '', $href); +// var_dump($dirPart); + if ($dirPart != '') { + $items = explode('/', $dirPart); +// var_dump($items); + $itemCount = count($items); + switch ($itemCount) { + case 3 : + $this->htImageFolders[$items[0]][$items[1]][] = $items[2]; + break; + case 2 : + $this->htImageFolders[$items[0]][] = $items[1]; + break; + case 1 : + $this->htImageFolders[] = $items[0]; + break; + } + } + // old site name visittraversecity.com +// var_dump($href); +// var_dump(FILEMANAGER_URL_ORG2); + $dirPart = str_replace(FILEMANAGER_URL_ORG2, '', $href); +// var_dump($dirPart); + if ($dirPart != '') { + $items = explode('/', $dirPart); +// var_dump($items); + $itemCount = count($items); + switch ($itemCount) { + case 3 : + $this->htImageFolders2[$items[0]][$items[1]][] = $items[2]; + break; + case 2 : + $this->htImageFolders2[$items[0]][] = $items[1]; + break; + case 1 : + $this->htImageFolders2[] = $items[0]; + break; + } + } + } +// var_dump($this->htImageFolders); +// var_dump($this->htImageFolders2); +// exit; + if (is_array($this->htImageFolders)) { + foreach ($this->htImageFolders as $folderName => $images) { + if (!is_numeric($folderName)) { +// var_dump($folderName); + $folderId = $this->addFolder($folderName, 0); + $folder = array( + 'id' => $folderId, + 'path' => $folderName . '/' + ); + foreach ($images as $image) { + if (!$img = $this->addImage($ia, $folder, $image)) { + //echo 'not found!'; + } else { + $this->newHtImages[] = array( + 'oldPath' => FILEMANAGER_URL_ORG + . $folderName . '/' . $image, + 'newPath' => CKIMAGE_ORIGINAL + . $img + ); + } + } + + } else { + $folder = array( + 'id' => 1, + 'path' => '' + ); +// var_dump($images); + if (!$img = $this->addImage($ia, $folder, $images)) { + //echo 'not found!'; + } else { + $this->newHtImages[] = array( + 'oldPath' => FILEMANAGER_URL_ORG + . $images, + 'newPath' => CKIMAGE_ORIGINAL + . $img + ); + } + } + } + } + if (is_array($this->htImageFolders2)) { + foreach ($this->htImageFolders2 as $folderName => $images) { + if (!is_numeric($folderName)) { +// var_dump($folderName); + $folderId = $this->addFolder($folderName, 0); + $folder = array( + 'id' => $folderId, + 'path' => $folderName . '/' + ); + foreach ($images as $image) { + if (!$img = $this->addImage($ia, $folder, $image)) { + //echo 'not found!'; + } else { + $this->newHtImages[] = array( + 'oldPath' => FILEMANAGER_URL_ORG2 + . $folderName . '/' . $image, + 'newPath' => CKIMAGE_ORIGINAL + . $img + ); + } + } + + } else { + $folder = array( + 'id' => 1, + 'path' => '' + ); +// var_dump($images); + if (!$img = $this->addImage($ia, $folder, $images)) { + //echo 'not found!'; + } else { + $this->newHtImages[] = array( + 'oldPath' => FILEMANAGER_URL_ORG2 + . $images, + 'newPath' => CKIMAGE_ORIGINAL + . $img + ); + } + } + } + } + //var_dump($this->htImages); + + } + } + + public function setDbhLocal($dbh) { + $this->dbhLocal = $dbh; + } + + public function setDbhRemote($dbh) { + $this->dbhRemote = $dbh; + } + + public function updateParagraphsWithImageNames() + { +// var_dump($this->htImageFolders); +// var_dump($this->newHtImages); + try { + $sql = " + UPDATE paragraphs + SET description = replace(description, :oldImageName, :newImageName)"; + $updateParagraphs = $this->dbhLocal->prepare($sql); + if (is_array($this->newHtImages)) { + foreach ($this->newHtImages as $image) { + $updateParagraphs->bindParam( + ':oldImageName', + $image['oldPath'], + PDO::PARAM_STR + ); + $updateParagraphs->bindParam( + ':newImageName', + $image['newPath'], + PDO::PARAM_STR + ); + $updateParagraphs->execute(); + } + } + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + +} diff --git a/Toolkit/Toolbox/Importer/Files.php b/Toolkit/Toolbox/Importer/Files.php new file mode 100644 index 0000000..4e93b27 --- /dev/null +++ b/Toolkit/Toolbox/Importer/Files.php @@ -0,0 +1,160 @@ +id; + } + + public function setId($id) { + if (!is_numeric($id)) { + throw new Exception('id must be a number'); + } + if (!$this->id) { + $this->id = $id; + } + return $this; + } + + public function getFilename() { + return $this->filename; + } + + public function setFilename($filename) + { + $this->filename = $filename; + return $this; + } + + public function getBytes() + { + return $this->bytes; + } + + public function setBytes($bytes) + { + $this->bytes = $bytes; + return $this; + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + return $this; + } + + public function getUrltext() + { + return $this->urltext; + } + + public function setUrltext($urltext) + { + $this->urltext = $urltext; + return $this; + } + + public function getParagraph() + { + return $this->paragraph; + } + + public function setParagraph($paragraph) + { + $this->paragraph = $paragraph; + return $this; + } + + public function getPos() + { + return $this->pos; + } + + public function setPos($pos) + { + $this->pos = $pos; + return $this; + } + + public function importFile(PDO $dbh, Toolkit_FileServer_FileAdapter $fs) + { + static $update; + if (!$update) { + $sql = " + UPDATE files + SET filename = :filename + WHERE id = :id"; + $update = $dbh->prepare($sql); + } + $filename = $this->getFilename(); + if (!$filename) { + return false; + } + $fileUrl + = FILE_URL_ORG + . urlencode($this->getFilename()); + try { + $res = $fs->upload($fileUrl); + } catch (Toolkit_FileServer_Exception $e) { + Toolkit_Logger::logException('File Server', $e); + echo -1; // Don't return "false", it will mess up the JS plugin. + return; + } + $this->setFilename($res['name']); + if ($res['name']) { + try { + $update->bindParam( + ':filename', + $res['name'], + PDO::PARAM_STR + ); + $update->bindParam( + ':id', + $this->getId(), + PDO::PARAM_INT + ); + $update->execute(); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + } + + public function save(PDO $dbh) + { + try { + $tablename = 'toolbox.files'; + $values = get_object_vars($this); +// unset($values['id']); + $sql = Toolkit_Common::createSQLInsert( + $tablename, + array_keys($values) + ); + $sql .= ' RETURNING id'; + $stmt = Toolkit_Common::prepareQuery( + $dbh, + $tablename, + $sql, + $values + ); + $stmt->execute(); + $this->setId($stmt->fetchColumn()); + return $this; + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } +} diff --git a/Toolkit/Toolbox/Importer/Notes b/Toolkit/Toolbox/Importer/Notes new file mode 100644 index 0000000..4fade6c --- /dev/null +++ b/Toolkit/Toolbox/Importer/Notes @@ -0,0 +1,24 @@ +Svn: +Need to merge the svn branch back into the trunk (branch created at 14935) +1. bring branch up to date + svn merge http://cvs2/svn/prod/www.brewbakers.com +2. commit your branch + svn ci -m "Bring in trunk changes into my branch" +3. switch to prod svn copy + svn switch http://cvs2/svn/prod/www.brewbakers.com . +4. merge in branch + svn merge --reintegrate http://cvs2/svn/dev/www.brewbakers.com +5. commit + + +For the toolbox upgrade on the live ds3 database + + +Back up the database first!!! +pg_dump -Fc -f brewbakers-ds3-3.5-13.9.27.tar -h ds3 brewbakers + + +1. run upgradeToolbox.sql to move the schemas +2. dump the schemas for the new toolbox and photos + pg_dump --column-inserts -f newToolbox.sql -h devdb -n toolbox -n ckimages -n photos brewbakers +3. run the newToolbox.sql into brewbakers database diff --git a/Toolkit/Toolbox/Importer/Pages.php b/Toolkit/Toolbox/Importer/Pages.php new file mode 100644 index 0000000..6a04c8e --- /dev/null +++ b/Toolkit/Toolbox/Importer/Pages.php @@ -0,0 +1,249 @@ +id; + } + + public function setId($id) { + if (!is_numeric($id)) { + throw new Exception('id must be a number'); + } + if (!$this->id) { + $this->id = $id; + } + return $this; + } + + public function getActive() { + return (bool)$this->active; + } + + public function setActive($active) { + $this->active = ($active) ? true: false; + return $this; + } + + public function getMobile_active() { + return (bool)$this->mobile_active; + } + + public function setMobile_active($mobile_active) { + $this->mobile_active = ($mobile_active) ? true: false; + return $this; + } + + public function getNavigation_name() { + return $this->navigation_name; + } + + public function setNavigation_name($navigation_name) { + $this->navigation_name = $navigation_name; + return $this; + } + + public function getKeyword() { + return $this->keyword; + } + + public function setKeyword($keyword) { + $this->keyword = $keyword; + return $this; + } + + public function getMeta_title() { + return $this->meta_title; + } + + public function setMeta_title($meta_title) { + $this->meta_title = $meta_title; + return $this; + } + + public function getMeta_description() { + return $this->meta_description; + } + + public function setMeta_description($meta_description) { + $this->meta_description = $meta_description; + return $this; + } + + public function getTemplate() { + return $this->template; + } + + public function setTemplate($template) { + $this->template = $template; + return $this; + } + + public function getParent() { + return $this->parent; + } + + public function setParent($parent) { + $this->parent = $parent; + return $this; + } + + public function getPos() { + return (int)$this->pos; + } + + public function setPos($pos) { + $this->pos = $pos; + return $this; + } + + public function getHeadline() + { + return $this->headline; + } + + public function setHeadline($headline) + { + $this->headline = ($headline) ? true : false; + return $this; + } + + public function getHeadline_intro() + { + return $this->headline_intro; + } + + public function setHeadline_intro($headline_intro) + { + $this->headline_intro = $headline_intro; + return $this; + } + + public function getSearch_form() + { + return $this->search_form; + } + + public function setSearch_form($search_form) + { + $this->search_form = $search_form; + return $this; + } + + public function getInclude_members() + { + return $this->include_members; + } + + public function setInclude_members($include_members) + { + $this->include_members = $include_members; + return $this; + } + + public function getInclude_member_map() + { + return $this->include_member_map; + } + + public function setInclude_member_map($include_member_map) + { + $this->include_member_map = $include_member_map; + return $this; + } + + public function getInclude_coupons() + { + return $this->include_coupons; + } + + public function setInclude_coupons($include_coupons) + { + $this->include_coupons = $include_coupons; + return $this; + } + + public function getShort_url() + { + return $this->short_url; + } + + public function setShort_url($short_url) + { + $this->short_url = $short_url; + return $this; + } + + public function getParagraph_links() + { + return (bool)$this->paragraph_links; + } + + public function setParagraph_links($paragraph_links) + { + $this->paragraph_links = ($paragraph_links) ? true : false; + return $this; + } + + public function save(PDO $dbh) + { + try { + $sql = " + INSERT INTO toolbox.pages + (id, active, mobile_active, navigation_name, keyword, meta_title, + meta_description, template, parent, pos, headline, headline_intro, + search_form, include_members, include_member_map, include_coupons, short_url, + paragraph_links) + VALUES + (:id, :active, :mobile_active, :navigation_name, :keyword, :meta_title, + :meta_description, :template, :parent, :pos, :headline, :headline_intro, + :search_form, :include_members, :include_member_map, :include_coupons, :short_url, + :paragraph_links) + RETURNING id"; + $stmt = $dbh->prepare($sql); + $stmt->bindParam(':id', $this->getId(), PDO::PARAM_INT); + $stmt->bindParam(':active', $this->getActive(), PDO::PARAM_BOOL); + $stmt->bindParam(':mobile_active', $this->getMobile_active(), PDO::PARAM_BOOL); + $stmt->bindParam(':navigation_name', $this->getNavigation_name()); + $stmt->bindParam(':keyword', $this->getKeyword()); + $stmt->bindParam(':meta_title', $this->getMeta_title()); + $stmt->bindParam(':meta_description', $this->getMeta_description()); + $stmt->bindParam(':template', $this->getTemplate(), PDO::PARAM_INT); + $stmt->bindParam(':parent', $this->getParent(), PDO::PARAM_INT); + $stmt->bindParam(':pos', $this->getPos(), PDO::PARAM_INT); + $stmt->bindParam(':headline', $this->getHeadline(), PDO::PARAM_BOOL); + $stmt->bindParam(':headline_intro', $this->getHeadline_intro()); + $stmt->bindParam(':search_form', $this->getSearch_form(), PDO::PARAM_BOOL); + $stmt->bindParam(':include_members', $this->getInclude_members(), PDO::PARAM_BOOL); + $stmt->bindParam(':include_member_map', $this->getInclude_member_map(), PDO::PARAM_BOOL); + $stmt->bindParam(':include_coupons', $this->getInclude_coupons(), PDO::PARAM_BOOL); + $stmt->bindParam(':short_url', $this->getShort_url(), PDO::PARAM_BOOL); + $stmt->bindParam(':paragraph_links', $this->getParagraph_links(), PDO::PARAM_BOOL); + + $stmt->execute(); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + +} diff --git a/Toolkit/Toolbox/Importer/Paragraphs.php b/Toolkit/Toolbox/Importer/Paragraphs.php new file mode 100644 index 0000000..8828953 --- /dev/null +++ b/Toolkit/Toolbox/Importer/Paragraphs.php @@ -0,0 +1,157 @@ +id; + } + + public function setId($id) { + if (!is_numeric($id)) { + throw new Exception('id must be a number'); + } + if (!$this->id) { + $this->id = $id; + } + return $this; + } + + public function getTitle() { + return $this->title; + } + + public function setTitle($title) { + $this->title = $title; + return $this; + } + + public function getPage() { + return $this->page; + } + + public function setPage($page) { + $this->page = $page; + return $this; + } + + public function getPos() { + return $this->pos; + } + + public function setPos($pos) { + $this->pos = $pos; + return $this; + } + + public function getActive() { + return $this->active; + } + + public function setActive($active) { + $this->active = $active; + return $this; + } + + public function getDescription() { + return $this->description; + } + + public function setDescription($description) { + $this->description = $description; + return $this; + } + + public function getCaption() { + return $this->caption; + } + + public function setCaption($caption) { + $this->caption = $caption; + return $this; + } + + public function getImage() { + return $this->image; + } + + public function setImage($image) { + $this->image = $image; + return $this; + } + + public function importImage(PDO $dbh, Toolkit_Image_Server $is) + { + static $update; + if (!$update) { + $sql = " + UPDATE paragraphs + SET image = :image + WHERE id = :id"; + $update = $dbh->prepare($sql); + } + $imageUrl + = IMG_URL_ORG + . urlencode($this->getImage()); + if ($this->image != '') { + try { + $img = $is->imageUpload($imageUrl); + } catch(PEAR_Exception $e) { + Toolkit_Common::handleError($e); + } + } + $this->setImage($img); + if ($img) { + try { + $update->bindParam( + ':image', + $img, + PDO::PARAM_STR + ); + $update->bindParam( + ':id', + $this->getId(), + PDO::PARAM_INT + ); + $update->execute(); + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + } + + public function save(PDO $dbh) + { + try { + $tablename = 'toolbox.paragraphs'; + $values = get_object_vars($this); +// unset($values['id']); + $sql = Toolkit_Common::createSQLInsert( + $tablename, + array_keys($values) + ); + $sql .= ' RETURNING id'; + $stmt = Toolkit_Common::prepareQuery( + $dbh, + $tablename, + $sql, + $values + ); + $stmt->execute(); + $this->setId($stmt->fetchColumn()); + return $this; + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + +} diff --git a/Toolkit/Toolbox/Importer/index.php b/Toolkit/Toolbox/Importer/index.php new file mode 100644 index 0000000..f16e897 --- /dev/null +++ b/Toolkit/Toolbox/Importer/index.php @@ -0,0 +1,44 @@ + PDO::FETCH_BOTH, + ) +); +$dbhRemote->setAttribute( + PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION +); +$is = new Toolkit_Image_Server(); +$ia = new Toolkit_FileServer_ImageAdapter(); +$importer = new Toolkit_Toolbox_Importer_Controller( + $dbhLocal, + $dbhRemote +); + +//flush(); +echo '

Get pages from remote

'; +//$importer->resetMemberFlags(); +//$importer->resetMemberWithRegions(); + +//$importer->getOldPages(); + +//echo '

Clean Toolbox

'; +//$importer->cleanToolboxTables(); +//echo '

Create New pages

'; +//$importer->addPages(); +//echo '

Create New Paragraphs

'; +//$importer->addParagraphs(); +//echo '

Create New Files

'; +//$importer->addFiles(); +flush(); +//$importer->resetSequences(); diff --git a/Toolkit/Toolbox/Importer/upgradeToolbox.sql b/Toolkit/Toolbox/Importer/upgradeToolbox.sql new file mode 100644 index 0000000..6cc36c9 --- /dev/null +++ b/Toolkit/Toolbox/Importer/upgradeToolbox.sql @@ -0,0 +1,35 @@ +-- +-- Upgrade script for moving schemas around +-- + +CREATE SCHEMA oldtoolbox; + +ALTER TABLE bus SET SCHEMA oldtoolbox; +ALTER TABLE bus2 SET SCHEMA oldtoolbox; +ALTER TABLE bus_cat2 SET SCHEMA oldtoolbox; +ALTER TABLE bus_cat_bus2 SET SCHEMA oldtoolbox; +ALTER TABLE bus_category SET SCHEMA oldtoolbox; +ALTER TABLE bus_category_bus SET SCHEMA oldtoolbox; +ALTER TABLE bus_category_busold SET SCHEMA oldtoolbox; +ALTER TABLE bus_categoryold SET SCHEMA oldtoolbox; +ALTER TABLE busold SET SCHEMA oldtoolbox; +ALTER TABLE files SET SCHEMA oldtoolbox; +ALTER SEQUENCE bus_category_bus_id_seq SET SCHEMA oldtoolbox; +ALTER SEQUENCE bus_category_id_seq SET SCHEMA oldtoolbox; +ALTER SEQUENCE bus_id_seq SET SCHEMA oldtoolbox; + +CREATE SCHEMA oldphotos; + +ALTER TABLE photo SET SCHEMA oldphotos; +ALTER TABLE photo_category SET SCHEMA oldphotos; +ALTER TABLE photo_category_bus SET SCHEMA oldphotos; +ALTER TABLE photo_default SET SCHEMA oldphotos; +ALTER SEQUENCE photo_category_bus_id_seq SET SCHEMA oldphotos; +ALTER SEQUENCE photo_category_id_seq SET SCHEMA oldphotos; +ALTER SEQUENCE photo_default_id_seq SET SCHEMA oldphotos; +ALTER SEQUENCE photo_id_seq SET SCHEMA oldphotos; + +-- +-- add the table functions for ckimages and toolbox to work +-- +\i /usr/share/postgresql/8.4/contrib/tablefunc.sql \ No newline at end of file