示例#1
0
文件: Tag.php 项目: kotow/work
 public function save($con = null, $parent = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         parent::save($con);
         // create relationship
         if (!$parent && !Document::getParentOf($this->getId())) {
             $parent = Rootfolder::getRootfolder($this);
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         if (sfConfig::get('sf_cache_relations')) {
             Tagrelation::updateTagRelationCache();
         }
         Document::cacheObj($this, get_class($this));
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
示例#2
0
文件: Newsletter.php 项目: kotow/work
 public function save($con = null, $parent = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (!$this->getId()) {
             $genDoc = Document::getGenericDocument($this);
             $genDoc->setPublicationStatus("WAITING");
             $genDoc->save();
             $this->setId($genDoc->getId());
         }
         parent::save($con);
         // create relationship
         if (!$parent && !Document::getParentOf($this->getId())) {
             $parent = Rootfolder::getRootfolder($this);
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         Document::cacheObj($this, get_class($this));
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
示例#3
0
文件: Listitem.php 项目: kotow/work
 public function save($con = null, $parent = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         parent::save($con);
         // create relationship
         if (!$parent && !Document::getParentOf($this->getId())) {
             $parent = Rootfolder::getRootfolder($this);
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         Document::cacheObj($this, get_class($this));
         // get Lists object
         if (!$parent) {
             $parent = Document::getParentOf($this->getId());
         }
         // update list cache
         if (get_class($parent) == "Lists") {
             Lists::updateListCache($parent->getListId());
         }
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
示例#4
0
文件: Rootfolder.php 项目: kotow/work
 public function save($con = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         parent::save($con);
         $con->commit();
         Document::cacheObj($this, get_class($this));
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
示例#5
0
文件: User.php 项目: kotow/work
 public function save($con = null, $parent = null)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         if (trim($this->__toString()) != "") {
             $this->setLabel($this->__toString());
         }
         switch ($this->getType()) {
             case "admin":
                 //case "site_admin":
                 $this->setBackend(1);
                 break;
             default:
                 $this->setBackend(0);
         }
         if ($this->getLogin() == "") {
             $this->setLogin($this->getEmail());
         }
         if (!$this->getId()) {
             $this->setId(Document::getGenericDocument($this)->getId());
         }
         /*if (!$this->getPublicationStatus())
         		{
         			$this->setPublicationStatus(UtilsHelper::STATUS_ACTIVE);
         		}*/
         parent::save($con);
         // create relationship
         if (!$parent && !Document::getParentOf($this->getId())) {
             $parent = Rootfolder::getRootfolder($this);
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         Document::cacheObj($this, get_class($this));
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
示例#6
0
 public function executeSetPublicationStatus()
 {
     $items = explode(",", $this->getRequestParameter('items'));
     $status = $this->getRequestParameter('status');
     try {
         foreach ($items as $item) {
             $genericDocument = Document::getGenericDocument($item);
             $item = Document::getDocumentInstance($item);
             if ($genericDocument) {
                 $genericDocument->setPublicationStatus($status);
                 $genericDocument->save();
                 Document::cacheObj($item, null, true);
             }
         }
     } catch (Exception $e) {
         exit("A probleme occured: " . $e->getMessage());
     }
     exit("OK");
 }
示例#7
0
文件: sfPakeMisc.php 项目: kotow/work
function run_generate_cache($task, $args)
{
    ini_set("memory_limit", "2048M");
    ini_set("display_errors", 1);
    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();
    run_url_relations($task, $args);
    run_tags_relations($task, $args);
    echo_cms_title("GENERATING CACHE...");
    if (!class_exists("XMLParser")) {
        include sfConfig::get('sf_root_dir') . "/lib/tools/XMLParser.class.php";
    }
    if (!class_exists("FileHelper")) {
        include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php";
    }
    //echo_cms_sep();
    echo_cms("sf_cache_objects = " . sfConfig::get('sf_cache_objects'));
    echo_cms("sf_cache_relations = " . sfConfig::get('sf_cache_relations'));
    echo_cms("sf_cache_trees = " . sfConfig::get('sf_cache_trees'));
    //echo_cms_sep();
    if (count($args) > 0) {
        $relationsFlag = substr($args[0], 0, 3) == "rel";
        $listsFlag = substr($args[0], 0, 4) == "list";
        $cacheModel = $args[0];
        if (is_numeric($cacheModel)) {
            $obj = Document::getDocumentInstance($cacheModel);
            if ($obj) {
                $phpName = get_class($obj);
            } else {
                echo_cms_error("Object with ID=" . $cacheModel . " not found!");
                exit;
            }
        }
    }
    // parse schema file to make Schema.class.php
    $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/schema.xml");
    $schemaFile = sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
    $content = $content = "<?php\n class Schema\n{\n\n";
    echo_cms("Building " . $schemaFile . "... ");
    foreach ($objects as $obj) {
        if ($obj['tag'] == 'TABLE' && $obj['type'] == 'open') {
            $table = $obj['attributes']['PHPNAME'];
            if ($phpName && $phpName == $table) {
                $tableName = $obj['attributes']['NAME'];
            }
            $trees = explode(",", $obj['attributes']['TREE']);
            $content .= "\tpublic static function get" . $table . "Trees()\n\t{\n";
            $content .= "\t\treturn array(";
            foreach ($trees as $tree) {
                $content .= "'" . strtolower($tree) . "', ";
            }
            $content = substr($content, 0, -2);
            $content .= ");\n\t}\n\n";
            $content .= "\tpublic static function get" . $table . "Properties()\n\t{\n";
            $content .= "\t\treturn array(";
        }
        if ($obj['tag'] == 'COLUMN' && $obj['type'] == 'complete') {
            $property = $obj['attributes']['NAME'];
            $getProperty = UtilsHelper::convertFieldName($property);
            $content .= "'" . $getProperty . "', ";
        }
        if ($obj['tag'] == 'TABLE' && $obj['type'] == 'close') {
            $content = substr($content, 0, -2);
            $content .= ");\n\t}\n\n";
        }
    }
    $content .= "\n}";
    //echo_cms_sep();
    if (FileHelper::writeFile($schemaFile, $content)) {
        echo_cms($schemaFile . " writen successfully!");
    } else {
        echo_cms_error("Error writing " . $schemaFile . "!");
    }
    echo "\n";
    //echo_cms_sep();
    if (substr($args[0], 0, 5) == "schema") {
        echo_cms(" Done!");
        exit;
    }
    if (!$relationsFlag && !$listsFlag) {
        try {
            if (is_numeric($cacheModel)) {
                $obj = array();
                $obj['tag'] = 'OBJECT';
                $obj['type'] = 'complete';
                $obj['id'] = $cacheModel;
                $objects = array($obj);
                $exit = true;
            } elseif ($cacheModel) {
                $obj = array();
                $obj['tag'] = 'OBJECT';
                $obj['type'] = 'complete';
                $obj['value'] = $cacheModel;
                $objects = array($obj);
                $exit = true;
            } else {
                $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml");
            }
            foreach ($objects as $obj) {
                if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
                    if ($id = $obj['id']) {
                        $obj = Document::getDocumentInstance($id);
                        $model = get_class($obj);
                        $c = new Criteria();
                        $c->add($tableName . '.ID', $id);
                    } else {
                        $model = $obj['value'];
                        $c = new Criteria();
                    }
                    $classPeer = ucfirst($model) . "Peer";
                    //$c = new Criteria();
                    //$results = call_user_func(array($classPeer, 'doSelect'), $c);
                    $peerMethod = "doSelect";
                    $results = call_user_func(array($classPeer, $peerMethod), $c);
                    echo_cms("  Caching " . $model . " documents");
                    $ind = 0;
                    foreach ($results as $result) {
                        if ($ind % 20 == 0) {
                            echo $ind . "  .\r";
                        } else {
                            if ($ind % 10 == 0) {
                                echo $ind . "  o\r";
                            }
                        }
                        $ind++;
                        Document::cacheObj($result, $model, false);
                    }
                    echo_cms(" ====> " . $ind . " " . $model . " Document(s) cached.");
                    //echo_cms_sep();
                }
            }
            if ($exit) {
                exit;
            }
        } catch (Expection $e) {
            echo_cms_error(" Error: {$e}");
        }
    }
    if (!$listsFlag) {
        echo "\n";
        //echo_cms_sep();
        echo_cms("Writing relations cache");
        Relation::checkRelationCache('lock');
        try {
            $c = new Criteria();
            $c->addAscendingOrderByColumn('id1');
            $c->addAscendingOrderByColumn('document_model2');
            $c->addAscendingOrderByColumn('sort_order');
            $relations = RelationPeer::doSelect($c);
            $relationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/childrenRelations.php";
            echo_cms("Processing children :");
            $i = 0;
            $content = "<?php \n";
            $oldIDModel = '';
            $currIDModel = '';
            $idStr = '';
            foreach ($relations as $relation) {
                $currIDModel = $relation->getId1() . ':' . $relation->getDocumentModel2();
                if ($i == 0) {
                    $oldIDModel = $currIDModel;
                }
                $i++;
                echo $i . "\t\t\r";
                if ($currIDModel == $oldIDModel) {
                    $idStr .= "," . $relation->getId2();
                } else {
                    $idStr = substr($idStr, 1);
                    $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
                    $idStr = "," . $relation->getId2();
                }
                $oldIDModel = $currIDModel;
                $oldId1 = $relation->getId1();
                $oldModel2 = $relation->getDocumentModel2();
            }
            if ($idStr) {
                $idStr = substr($idStr, 1);
                $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
            }
            echo "\n";
            $content .= "\n?>";
            //echo_cms_sep();
            if (FileHelper::writeFile($relationsFile, $content)) {
                echo_cms($relationsFile . " written successfully");
            } else {
                echo_cms_error("Error writing " . $relationsFile . " !");
            }
            //echo_cms_sep();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }
        Relation::checkRelationCache('unlock');
    }
    if (!$relationsFlag) {
        echo "\n";
        //echo_cms_sep();
        echo_cms_title("Writing Lists cache");
        $listsRootFolder = Rootfolder::getRootfolderByModule("lists");
        if ($listsRootFolder) {
            $lists = Document::getChildrenOf($listsRootFolder->getId(), "Lists");
        }
        foreach ($lists as $list) {
            $listId = $list->getListId();
            echo "\t\tprocessing \"" . $listId . "\" list ...";
            $listPath = sfConfig::get('sf_root_dir') . "/cache/listscache/" . $listId . ".php";
            @unlink($listPath);
            $content = "<?php \n";
            $content .= "\$listItemsForSelect = array(\n";
            $items = Lists::getListitemsForSelect($listId, array(), false);
            foreach ($items as $key => $item) {
                $content .= "\"" . str_replace("\"", "\\\"", $key) . "\" => \"" . str_replace("\"", "\\\"", $item) . "\",\n";
            }
            $content .= ");\n?>";
            if (FileHelper::writeFile($listPath, $content)) {
                echo_cms(" Done!");
            } else {
                echo_cms_error(" Error!");
            }
        }
        //echo_cms_sep();
    }
    sfConfig::set("sf_use_relations_cache", true);
}
示例#8
0
 public function executeSetPublicationStatus()
 {
     $items = explode(",", $this->getRequestParameter('items'));
     $status = $this->getRequestParameter('status');
     if ($status == 'online') {
         $status = UtilsHelper::STATUS_ACTIVE;
     }
     if ($status == 'offline') {
         $status = UtilsHelper::STATUS_DEACTIVATED;
     }
     try {
         foreach ($items as $item) {
             $document = Document::getDocumentInstance($item);
             if (method_exists($document, 'setPublicationStatus')) {
                 $document->setPublicationStatus($status);
                 $document->save();
                 Document::cacheObj($document, null, true);
             }
         }
     } catch (Exception $e) {
         exit("A probleme occured: " . $e->getMessage());
     }
     exit("OK");
 }
示例#9
0
文件: Media.php 项目: kotow/work
 public function save($con = null, $parent = null, $refreshTree = true)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         $genericDoc = Document::getGenericDocument($this);
         if (!$this->getId()) {
             $this->setId($genericDoc->getId());
         }
         parent::save($con);
         // create relationship
         if (!$parent) {
             $parent = Document::getParentOf($this->getId(), null, true, false);
             if (empty($parent)) {
                 $parent = Rootfolder::getRootfolder($this);
             }
         }
         Relation::saveRelation($parent, $this);
         $con->commit();
         Document::cacheObj($this, "Media", $refreshTree);
         return true;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }