예제 #1
0
파일: sfPakeMisc.php 프로젝트: kotow/work
function run_url_relations($task, $args)
{
    ini_set("memory_limit", "2048M");
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', 'frontend');
    define('SF_ENVIRONMENT', 'dev');
    define('SF_DEBUG', false);
    sfConfig::set("sf_use_relations_cache", false);
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    echo_cms_title("GENERATING URL RELATION CACHE...");
    if (!class_exists("FileHelper")) {
        include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php";
    }
    $urlRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/urlRelations.php";
    try {
        $c = new Criteria();
        $rewriteUrls = UrlrewritePeer::doSelect($c);
        echo_cms("Processing urls :");
        $i = 0;
        $content = "<?php \n";
        foreach ($rewriteUrls as $singleUrl) {
            $content .= "\$_UrlRel['" . $singleUrl->getlabel() . "'] = " . $singleUrl->getPageId() . ";\n";
            $i++;
        }
        echo " ====> " . $i . " urls cached\n";
        $content .= "\n?>";
        if (FileHelper::writeFile($urlRelationsFile, $content)) {
            echo_cms($urlRelationsFile . " Written successfully");
        } else {
            echo_cms_error("Error writing " . $urlRelationsFile . " !");
        }
        //echo_cms_sep();
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();
    }
    sfConfig::set("sf_use_relations_cache", true);
    //echo_cms_sep();
}
예제 #2
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(UrlrewritePeer::ID, $pks, Criteria::IN);
         $objs = UrlrewritePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #3
0
파일: Page.php 프로젝트: kotow/work
 public function setRewriteUrl($value)
 {
     try {
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         $con = Propel::getConnection();
         $con->begin();
         //			$rewriteUrl = UrlrewritePeer::retrieveByPk($value);
         $c = new Criteria();
         $c->add(UrlrewritePeer::PAGE_ID, $this->getId());
         $rewriteUrl = UrlrewritePeer::doSelectOne($c);
         //$rewriteUrl = Document::getDocumentInstance($value);
         $value = trim($value);
         if ($rewriteUrl) {
             if ($value != '') {
                 $value = Urlrewrite::checkRewriteUrl($value, $this->getId());
                 $rewriteUrl->setLabel($value);
                 $rewriteUrl->save(null, $this);
             } else {
                 if ($value == '') {
                     $rewriteUrl->delete();
                 }
             }
         } else {
             if ($value) {
                 $value = Urlrewrite::checkRewriteUrl($value, $this->getId());
                 $rewriteUrl = new Urlrewrite();
                 $rewriteUrl->setLabel($value);
                 $rewriteUrl->setPageId($this->getId());
                 $rewriteUrl->save(null, $this);
             }
         }
         $con->commit();
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
     return true;
 }
예제 #4
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = UrlrewritePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setLabel($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setPageId($arr[$keys[2]]);
     }
 }
예제 #5
0
 public function executeDisplay()
 {
     $parameters = $this->getRequest()->getParameterHolder()->getAll();
     $culture = $this->getUser()->getCulture();
     $user = $this->getUser()->getSubscriber();
     if (isset($parameters['rewriteUrl'])) {
         if (isset($parameters['pageref'])) {
             $document = Document::getDocumentInstance($parameters['pageref']);
         } else {
             if (BackendService::loadUrlRelations()) {
                 if (array_key_exists('urlRelations', $_SESSION) && array_key_exists($parameters['rewriteUrl'], $_SESSION['urlRelations'])) {
                     $documentId = $_SESSION['urlRelations'][$parameters['rewriteUrl']];
                     $document = Document::getDocumentInstance($documentId);
                 }
             } else {
                 $c = new Criteria();
                 $c->add(UrlrewritePeer::LABEL, $parameters['rewriteUrl']);
                 $rewriteUrl = UrlrewritePeer::doSelectOne($c);
                 /*if ($rewriteUrl && array_key_exists('sf_culture', $parameters))
                 					{
                 						$document = Document::getDocumentInstance($rewriteUrl->getPageId());
                 
                 						if(substr(get_class($document), -4) == "I18n")
                 						{
                 							$parent = Document::getParentOf($rewriteUrl->getPageId());
                 							$document = Document::getDocumentInstance($parent->getId());
                 						}
                 					}
                 					else*/
                 if ($rewriteUrl) {
                     $document = Document::getDocumentInstance($rewriteUrl->getPageId());
                 }
             }
         }
         if (!isset($document)) {
             $elements = explode("_", substr($parameters['rewriteUrl'], 0, -5));
             $id = array_pop($elements);
             $key = $elements[0];
             if (Document::getStatus($id) == UtilsHelper::STATUS_ACTIVE) {
                 if ($key == "news") {
                     if ($document = Document::getDocumentByExclusiveTag("website_page_newslist")) {
                         $this->getRequest()->setParameter("month", $id);
                         $this->getRequest()->setParameter("year", $elements[2]);
                         $this->pageTitle = "News - " . $elements[1] . " " . $elements[2];
                     }
                 } else {
                     $rewritedDoc = Document::getDocumentInstance($id);
                     if ($rewritedDoc) {
                         $documentClass = get_class($rewritedDoc);
                         if ($document = Document::getDocumentByExclusiveTag("website_page_" . $documentClass . "_detail")) {
                             $this->getRequest()->setParameter($documentClass . "_id", $id);
                             /*if(class_exists($documentClass."I18n"))
                             			$this->pageTitle = $rewritedDoc->getLabelI18n();
                             		else*/
                             $this->pageTitle = $rewritedDoc->getLabel();
                         }
                     }
                 }
             }
         }
     } else {
         if (array_key_exists('pageref', $parameters) && is_numeric($parameters['pageref'])) {
             $document = Document::getDocumentInstance($parameters['pageref']);
         } else {
             $document = Document::getDocumentByExclusiveTag('website_page_home');
         }
     }
     if (isset($document)) {
         //$page = Document::getDocumentByCulture($document, $culture);
         //if(Document::getStatus($document->getId()) != UtilsHelper::STATUS_ACTIVE) $this->forward404();
         $page = $document;
         if ($page->getPublicationStatus() != UtilsHelper::STATUS_ACTIVE) {
             $this->forward404();
         }
     }
     if (isset($page) && get_class($page) == "Page") {
         //$culture = $pageI18n->getCulture();
         //$this->getUser()->setCulture($culture);
     } else {
         $page = null;
     }
     if ($page && $page->getIsSecure() && !$this->getUser()->isAuthenticated()) {
         $page = Document::getDocumentByExclusiveTag('website_page_login');
     }
     $this->pageDocument = $page;
     $this->forward404Unless($page);
     $this->getRequest()->setParameter('pageref', $page->getId());
     $this->getRequest()->setParameter('rewriteUrl', null);
     switch ($page->getPageType()) {
         //			case "ACTIONPAGE": return $this->redirect($page->getActionName());
         case "EXTERNAL":
             return $this->redirect($page->getUrl());
         case "REFERENCE":
             $this->redirect(Document::getDocumentInstance($page->getPageId())->getHref());
             break;
     }
     if (is_object($user)) {
         if ($user->getBackend()) {
             $this->setLayout('editPageContent');
             $this->content = $this->getContent(true);
         } else {
             $this->content = $this->getContent();
         }
         $this->setResponseParams($user);
     } else {
         $this->content = $this->getContent();
         $this->setResponseParams();
     }
 }