当前位置: 首页>>代码示例>>PHP>>正文


PHP sfDatabaseManager::initialize方法代码示例

本文整理汇总了PHP中sfDatabaseManager::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP sfDatabaseManager::initialize方法的具体用法?PHP sfDatabaseManager::initialize怎么用?PHP sfDatabaseManager::initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfDatabaseManager的用法示例。


在下文中一共展示了sfDatabaseManager::initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run_migrate

function run_migrate($task, $args)
{
    if (count($args) == 0) {
        throw new Exception('You must provide a app.');
    }
    @(list($app, $env) = explode(':', $args[0]));
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception('The app "' . $app . '" does not exist.');
    }
    // define constants
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', $env ? $env : 'cli');
    define('SF_DEBUG', true);
    // get configuration
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    $migrator = new sfMigrator();
    // if no other arguments besides app, then migrate to latest version
    if (count($args) == 1) {
        $runMigrationsCount = $migrator->migrate();
    } elseif (isset($args[1]) && ctype_digit($args[1])) {
        $runMigrationsCount = $migrator->migrate($args[1]);
    } else {
        throw new Exception('You can provide a destination migration number as a second parameter');
    }
    $currentVersion = $migrator->getCurrentVersion();
    pake_echo_action('migrations', 'migrated ' . $runMigrationsCount . ' step(s)');
    pake_echo_action('migrations', 'current database version: ' . $currentVersion);
}
开发者ID:jcoby,项目名称:sfPropelMigrationsPlugin,代码行数:31,代码来源:sfPakePropelMigrationsLight.php

示例2: execute

 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $scraper = new GovernorScraper($options['test_mode'], $options['debug_mode'], $this->configuration);
     $scraper->execute();
 }
开发者ID:silky,项目名称:littlesis,代码行数:7,代码来源:ScrapeGovernorsTask.class.php

示例3: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     $models = array('Entity', 'Relationship', 'LsList');
     foreach ($models as $model) {
         $modelAlias = strtolower($model);
         $updateAlias = $model == 'LsList' ? 'ls_list' : $modelAlias;
         //get records to update
         $q = LsDoctrineQuery::create()->select('id')->from($model . ' ' . $modelAlias)->where($modelAlias . '.last_user_id IS NULL')->limit($options['limit'])->setHydrationMode(Doctrine::HYDRATE_NONE);
         if (!count($rows = $q->execute())) {
             //nothing to update, go to next model
             continue;
         }
         foreach ($rows as $row) {
             $id = $row[0];
             //get last_user_id
             $result = LsDoctrineQuery::create()->select('m.user_id')->from('Modification m')->where('m.object_model = ? AND m.object_id = ?', array($model, $id))->orderBy('m.id DESC')->setHydrationMode(Doctrine::HYDRATE_NONE)->fetchOne();
             if ($lastUserId = $result[0]) {
                 $query = 'UPDATE ' . $updateAlias . ' SET last_user_id=? WHERE id=?';
                 //use PDO for speed
                 $db->execute($query, array($lastUserId, $id));
             } else {
                 throw new Exception("Couldn't find last_user_id for " . $model . ' #' . $id);
             }
         }
         //only update records of one model at a time
         break;
     }
     //DONE
     LsCli::beep();
 }
开发者ID:silky,项目名称:littlesis,代码行数:34,代码来源:CleanupLastUserIdsTask.class.php

示例4: execute

 protected function execute($arguments = array(), $options = array())
 {
     if (!$this->safeToRun()) {
         print "Process already running!\n";
         die;
     }
     $timer = sfTimerManager::getTimer('execute');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     //set up index
     $index = EntityTable::getLuceneIndex();
     //delete deleted entities
     $q = LsDoctrineQuery::create()->from('Entity e')->where('e.is_deleted = ?', true)->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     foreach ($q->execute() as $entity) {
         if ($hits = $index->find('key:' . $entity['id'])) {
             if ($options['debug_mode']) {
                 printf("Deleting index for Entity %s\n", $entity['id']);
             }
             foreach ($hits as $hit) {
                 $index->delete($hit->id);
             }
         }
     }
     printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage()));
     printf("Index size: %s\n", $index->count());
     $timer->addTime();
     printf("Run time: %s\n", $timer->getElapsedTime());
     sfTimerManager::clearTimers();
 }
开发者ID:silky,项目名称:littlesis,代码行数:29,代码来源:CleanSearchIndexTask.class.php

示例5: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $this->db = Doctrine_Manager::connection();
     $this->s3 = new S3(sfConfig::get('app_amazon_access_key'), sfConfig::get('app_amazon_secret_key'));
     // hide strict errors
     error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
     $sql = "SELECT DISTINCT(r.source) FROM reference r ORDER BY id ASC LIMIT " . $options["limit"] . " OFFSET " . $options["offset"];
     $stmt = $this->db->execute($sql);
     $sources = $stmt->fetchAll(PDO::FETCH_COLUMN);
     foreach ($sources as $source) {
         if (!$options["localdir"]) {
             $s3path = ReferenceTable::generateS3path($source);
             if (!$options["overwrite"] && $this->s3->getObjectInfo(sfConfig::get('app_amazon_s3_bucket'), $s3path) !== false) {
                 print "ALREADY UPLOADED: " . $s3path . "\n";
                 continue;
             }
         }
         $this->writeTmpFile($source, $options["debug_mode"], $options["localdir"]);
         if (!$options["localdir"]) {
             $this->uploadTmpFile($source, $options["overwrite"], $options["debug_mode"]);
             if (unlink($this->getLocalPath($source, $options["local_dir"])) && $options["debug_mode"]) {
                 print "REMOVED LOCAL: " . $source . " [" . sha1($source) . "]\n";
             }
         }
         print "----------------------------------------------------------------\n";
     }
     //DONE
     LsCli::beep();
 }
开发者ID:silky,项目名称:littlesis,代码行数:32,代码来源:UploadS3ReferencesTask.class.php

示例6: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     //get person entities with all-caps names
     $sql = 'SELECT e.id, e.name FROM entity e ' . 'WHERE e.name <> \'\' AND e.primary_ext = ? AND CAST(UPPER(e.name) AS BINARY) = CAST(e.name AS BINARY)';
     $stmt = $db->execute($sql, array('Person'));
     $names = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($names as $ary) {
         $new = PersonTable::nameizePersonName($ary['name']);
         if ($new != $ary['name']) {
             $sql = 'UPDATE entity SET name = ? WHERE id = ?';
             $stmt = $db->execute($sql, array($new, $ary['id']));
             print "Changed Entity name " . $ary['name'] . " to " . $new . "\n";
         }
     }
     //get aliases with all-caps names
     $sql = 'SELECT a.id, a.name FROM alias a LEFT JOIN entity e ON (e.id = a.entity_id) ' . 'WHERE a.name <> \'\' AND a.is_primary = 1 AND e.primary_ext = ? AND ' . 'CAST(UPPER(a.name) AS BINARY) = CAST(a.name AS BINARY)';
     $stmt = $db->execute($sql, array('Person'));
     $names = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($names as $ary) {
         $new = PersonTable::nameizePersonName($ary['name']);
         if ($new != $ary['name']) {
             $sql = 'UPDATE alias SET name = ? WHERE id = ?';
             $stmt = $db->execute($sql, array($new, $ary['id']));
             print "Changed Alias " . $ary['name'] . " to " . $new . "\n";
         }
     }
     //DONE
     LsCli::beep();
 }
开发者ID:silky,项目名称:littlesis,代码行数:33,代码来源:CleanupCapsNamesTask.class.php

示例7: execute

 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $scraper = new PublicCompanyScraper($options['test_mode'], $options['debug_mode'], $this->configuration, null, $browserTimeout = 60);
     if ($options['ticker']) {
         $scraper->setCompanyByTicker($options['ticker']);
     } else {
         if ($options['start_id']) {
             $scraper->setStartId($options['start_id']);
         }
     }
     $scraper->setSearchDepth($options['search_depth']);
     $years = explode(',', $options['years']);
     $scraper->setYears($years);
     $scraper->setLimit($options['limit']);
     $scraper->setSession($options['session']);
     if ($options['repeat_mode']) {
         $scraper->setRepeatMode(true);
     }
     if ($options['list_id']) {
         $scraper->setListId($options['list_id']);
     }
     $scraper->run();
 }
开发者ID:silky,项目名称:littlesis,代码行数:25,代码来源:ScrapePublicCompanyRostersTask.class.php

示例8: execute

 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $db = Doctrine_Manager::connection();
     $str = file_get_contents($options['file_name']);
     $lines = explode("\n", $str);
     foreach ($lines as $line) {
         $arr = explode(",", $line);
         $entity = Doctrine::getTable('Entity')->find($arr[0]);
         if (strlen($arr[1]) > 0) {
             $email = $entity->addEmail($arr[1]);
             if ($email) {
                 if ($options['safe_mode'] == true) {
                     $resp = $this->readline("Do name (" . $entity->name . ") and email (" . $arr[1] . ") match?");
                 } else {
                     $resp = 'y';
                 }
                 if ($resp == 'y') {
                     $email->save();
                 }
             } else {
                 echo "email failed to save\n";
             }
         } else {
             echo "entity skipped\n";
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:29,代码来源:AddEmailTask.class.php

示例9: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $fh = fopen($options['file_name'], 'a+');
     $start = count(file($options['file_name']));
     $this->db = Doctrine_Manager::connection();
     $this->list = Doctrine::getTable('LsList')->find($options['list_id']);
     $q = $this->list->getListEntitiesByRankQuery();
     $list_entities = $q->execute();
     function func($value)
     {
         return $value['name'];
     }
     for ($i = $start; $i < count($list_entities); $i++) {
         $entity = $list_entities[$i]->Entity;
         $people = $entity->getRelatedEntitiesQuery(array('Person'), array(1, 2, 3, 4, 6, 7, 8, 9, 10))->execute();
         $orgs = $entity->getRelatedEntitiesQuery(array('Org'), array(1, 2, 3, 4, 6, 7, 8, 9, 10))->execute();
         $donations = $entity->getRelatedEntitiesQuery(array('Person'), array(5))->execute();
         $people = implode("; ", array_map("func", $people->toArray()));
         $orgs = implode("; ", array_map("func", $orgs->toArray()));
         $donations = implode("; ", array_map("func", $donations->toArray()));
         $arr = array($entity, $people, $orgs, $donations);
         $str = implode("\t", $arr);
         fwrite($fh, $str . "\n");
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:28,代码来源:ListCsvTask.class.php

示例10: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $this->db = Doctrine_Manager::connection();
     if ($options['house_senate'] == 'house') {
         $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.house_fec_id = pc.house_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.house_fec_id is not null and pc.house_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id';
     } else {
         if ($options['house_senate'] == 'senate') {
             $sql = 'select e1.id,e2.id from entity e1 left join political_candidate pc on pc.entity_id = e1.id left join political_candidate pc2 on pc2.senate_fec_id = pc.senate_fec_id left join entity e2 on e2.id = pc2.entity_id where e1.is_deleted = 0 and e2.is_deleted = 0 and e1.id <> e2.id and pc.id is not null and pc2.id is not null and pc.id <> pc2.id and pc.senate_fec_id is not null and pc.senate_fec_id <> "" and e1.id < e2.id group by e1.id,e2.id';
         } else {
             echo 'House or Senate not selected...ending script' . "\n";
             die;
         }
     }
     $stmt = $this->db->execute($sql);
     $rows = $stmt->fetchAll();
     foreach ($rows as $row) {
         $e1 = Doctrine::getTable('Entity')->find($row[0]);
         $e2 = Doctrine::getTable('Entity')->find($row[1]);
         $mergedEntity = EntityTable::mergeAll($e1, $e2);
         $e2->setMerge(true);
         $e2->clearRelated();
         $e2->delete();
         echo '  Successfully merged ' . $e2->name . "\n";
         if ($options['test_mode']) {
             die;
         }
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:31,代码来源:mergePoliticalDuplicatesTask.class.php

示例11: run_propel_build_sql_diff

function run_propel_build_sql_diff($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the application.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception(sprintf('The app "%s" does not exist.', $app));
    }
    run_propel_build_sql($task, $args);
    pake_echo_action('propel-sql-diff', "building database patch");
    define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../../..'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', isset($args[1]) ? $args[1] : 'dev');
    define('SF_DEBUG', 1);
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    $i = new dbInfo();
    $i->loadFromDb();
    $i2 = new dbInfo();
    $i2->loadAllFilesInDir(sfConfig::get('sf_data_dir') . '/sql');
    $diff = $i->getDiffWith($i2);
    $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
    if ($diff == '') {
        pake_echo_comment("no difference found");
    }
    pake_echo_action('propel-sql-diff', "writing file {$filename}");
    file_put_contents($filename, $diff);
}
开发者ID:sgrove,项目名称:cothinker,代码行数:30,代码来源:sfPropelSqlDiffTask.php

示例12: execute

 protected function execute($arguments = array(), $options = array())
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $this->debugMode = $options['debug_mode'];
     $this->db = Doctrine_Manager::connection();
     $this->s3 = new S3(sfConfig::get('app_amazon_access_key'), sfConfig::get('app_amazon_secret_key'));
     // hide strict errors
     error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
     //get array of active entity image filenames
     if ($options['list_id']) {
         $sql = "SELECT i.id, i.filename, i.url, i.entity_id, e.name, e.primary_ext " . "FROM ls_list_entity le " . "LEFT JOIN image i ON (i.entity_id = le.entity_id) " . "LEFT JOIN entity e ON (e.id = le.entity_id) " . "WHERE le.list_id = ? AND le.is_deleted = 0 " . "AND i.is_deleted = 0 AND i.has_square = 0 " . "ORDER BY id DESC LIMIT " . $options['limit'];
         $params = array($options['list_id']);
     } else {
         $sql = "SELECT i.id, i.filename FROM image i " . "WHERE is_deleted = 0 AND has_square = 0 " . "ORDER BY id DESC LIMIT " . $options['limit'];
         $params = array();
     }
     $stmt = $this->db->execute($sql, $params);
     $images = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $count = count($images);
     foreach ($images as $image) {
         $this->printDebug("Processing image {$image['id']} belonging to entity {$image['entity_id']}...");
         if ($this->downloadLarge($image['filename'])) {
             $this->printDebug("Downloaded large image from S3: " . $s3Path);
         } else {
             $s3Path = ImageTable::generateS3Url(ImageTable::getPath($image['filename'], 'large'));
             $this->printDebug("Couldn't download large image from S3: " . $s3Path);
             if ($image['url']) {
                 if ($this->downloadToTmp($image['url'], $image['filename'])) {
                     $this->printDebug("Downloaded original image: " . $image['url']);
                 } else {
                     $this->printDebug("Couldn't download original image: " . $image['url']);
                     if ($this->downloadFromGoogle($image['name'])) {
                         $this->printDebug("Downloaded new image of {$image['name']} from google");
                     } else {
                         $count--;
                         continue;
                     }
                 }
             } else {
                 $count--;
                 continue;
             }
         }
         if (!$this->createSquare($image['filename'], $options['size'])) {
             $this->printDebug("Coudln't create square image: {$image['filename']}");
             $count--;
             continue;
         }
         if ($this->uploadFile($image['filename'], $options['check_first'], $options['debug_mode'])) {
             $this->recordSquare($image['id']);
         }
         $count--;
         print $count . " images remaining...\n";
     }
     //DONE
     LsCli::beep();
 }
开发者ID:silky,项目名称:littlesis,代码行数:59,代码来源:CreateSquareS3ImagesTask.class.php

示例13: execute

 protected function execute($arguments = array(), $options = array())
 {
     // initialize database manager
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $fortune_scraper = new Fortune1000Scraper($options['test_mode'], $options['debug_mode'], $this->configuration);
     $fortune_scraper->run();
 }
开发者ID:silky,项目名称:littlesis,代码行数:8,代码来源:ScrapeFortune1000Task.class.php

示例14: execute

 protected function execute($arguments = array(), $options = array())
 {
     $this->debugMode = $options['debug_mode'];
     $configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
     $databaseManager = new sfDatabaseManager($configuration);
     $databaseManager->initialize($configuration);
     $db = Doctrine_Manager::connection();
     $cache = LsApiCacheFilter::getApiCache();
     $models = array('Entity', 'Relationship', 'LsList', 'Image', 'Alias', 'Reference');
     $modelsToClear = array();
     foreach ($models as $model) {
         //get max modification id from last execution
         if (!$this->hasMeta($model, 'last_modification_id')) {
             //if no max modification id set, then set it
             $sql = 'SELECT MAX(id) FROM modification m WHERE m.object_model = ?';
             $stmt = $db->execute($sql, array($model));
             $result = $stmt->fetch(PDO::FETCH_COLUMN);
             $this->saveMeta($model, 'last_modification_id', $result);
         }
         $lastId = $this->getMeta($model, 'last_modification_id');
         //get records modified since then
         $sql = 'SELECT id, object_id FROM modification m WHERE id > ? AND object_model = ? AND is_create = 0 ORDER BY id';
         $stmt = $db->execute($sql, array($lastId, $model));
         $maxId = null;
         $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
         if (count($rows)) {
             $modelsToClear[] = $model;
         }
         foreach ($rows as $row) {
             $this->printDebug('Clearing API cache for ' . $model . ' ' . $row['object_id']);
             //clear record cache
             $cacheClearMethod = 'get' . $model . 'Patterns';
             foreach (self::$cacheClearMethod($row['object_id']) as $pattern) {
                 $cache->removePattern($pattern);
             }
             $maxId = $row['id'];
         }
         //set new max modification id
         if ($maxId) {
             $this->saveMeta($model, 'last_modification_id', $maxId);
         }
     }
     //we're not done yet! gotta clear searches!
     if (in_array('Entity', $modelsToClear)) {
         $this->printDebug('Clearing API cache for Entity search');
         $cache->removePattern('/entities*');
         $cache->removePattern('/batch/entities*');
     }
     if (in_array('Relationship', $modelsToClear)) {
         $this->printDebug('Clearing API cache for Relationship search');
         $cache->removePattern('/relationships*');
         $cache->removePattern('/batch/relationships*');
     }
     if (in_array('LsList', $modelsToClear)) {
         $this->printDebug('Clearing API cache for List search');
         $cache->removePattern('/lists*');
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:58,代码来源:ClearApiCacheTask.class.php

示例15: execute

 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     $refs = Doctrine::getTable('Reference')->findBySource('');
     foreach ($refs as $ref) {
         $ref->delete();
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:9,代码来源:cleanupReferencesTask.class.php


注:本文中的sfDatabaseManager::initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。