コード例 #1
0
ファイル: index.php プロジェクト: psion/phptest
 public function action($key)
 {
     $populate = new Populate($key);
     $view = new View();
     $populate->populateData($fields);
     $view->render($populate, $key);
 }
コード例 #2
0
 /**
  * @var bool
  *
  * @throws Exception
  */
 public static function requireRecords($force = false)
 {
     if (self::$ran && !$force) {
         return true;
     }
     self::$ran = true;
     if (!(Director::isDev() || Director::isTest())) {
         throw new Exception('requireRecords can only be run in development or test environments');
     }
     $factory = Injector::inst()->create('PopulateFactory');
     foreach (self::config()->get('truncate_objects') as $objName) {
         $versions = array();
         if (class_exists($objName)) {
             foreach (DataList::create($objName) as $obj) {
                 // if the object has the versioned extension, make sure we delete
                 // that as well
                 if ($obj->hasExtension('Versioned')) {
                     foreach ($obj->getVersionedStages() as $stage) {
                         $versions[$stage] = true;
                         $obj->deleteFromStage($stage);
                     }
                 }
                 try {
                     @$obj->delete();
                 } catch (Exception $e) {
                     // notice
                 }
             }
         }
         if ($versions) {
             self::truncate_versions($objName, $versions);
         }
         foreach ((array) ClassInfo::getValidSubClasses($objName) as $table) {
             self::truncate_table($table);
             self::truncate_versions($table, $versions);
         }
         self::truncate_table($objName);
     }
     foreach (self::config()->get('include_yaml_fixtures') as $fixtureFile) {
         $fixture = new YamlFixture($fixtureFile);
         $fixture->writeInto($factory);
         $fixture = null;
     }
     // hook allowing extensions to clean up records, modify the result or
     // export the data to a SQL file (for importing performance).
     $static = !(isset($this) && get_class($this) == __CLASS__);
     if ($static) {
         $populate = Injector::inst()->create('Populate');
     } else {
         $populate = $this;
     }
     $populate->extend('onAfterPopulateRecords');
     return true;
 }
コード例 #3
0
 /**
  * @var bool
  *
  * @throws Exception
  */
 public static function requireRecords($force = false)
 {
     if (self::$ran && !$force) {
         return true;
     }
     self::$ran = true;
     if (!(Director::isDev() || Director::isTest())) {
         throw new Exception('requireRecords can only be run in development or test environments');
     }
     $factory = Injector::inst()->create('PopulateFactory');
     foreach (self::config()->get('truncate_objects') as $objName) {
         $versions = array();
         if (class_exists($objName)) {
             foreach (DataList::create($objName) as $obj) {
                 // if the object has the versioned extension, make sure we delete
                 // that as well
                 if ($obj->hasExtension('Versioned')) {
                     foreach ($obj->getVersionedStages() as $stage) {
                         $versions[$stage] = true;
                         $obj->deleteFromStage($stage);
                     }
                 }
                 try {
                     @$obj->delete();
                 } catch (Exception $e) {
                     // notice
                 }
             }
         }
         if ($versions) {
             self::truncate_versions($objName, $versions);
         }
         foreach (ClassInfo::getValidSubClasses($objName) as $table) {
             self::truncate_table($table);
             self::truncate_versions($table, $versions);
         }
         self::truncate_table($objName);
     }
     foreach (self::config()->get('include_yaml_fixtures') as $fixtureFile) {
         $fixture = new YamlFixture($fixtureFile);
         $fixture->writeInto($factory);
         $fixture = null;
     }
     return true;
 }
コード例 #4
0
 public function run($request)
 {
     Populate::requireRecords();
 }
コード例 #5
0
ファイル: example1.php プロジェクト: tacno/populate-mysql-db
CREATE TABLE `table_test` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `title` varchar(45) DEFAULT NULL,
 `bigint` bigint(20) DEFAULT NULL,
 `mediumint` mediumint(9) DEFAULT NULL,
 `smallint` smallint(6) DEFAULT NULL,
 `tinyint` tinyint(4) DEFAULT NULL,
 `date` date DEFAULT NULL,
 `datetime` datetime DEFAULT NULL,
 `text` text,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Command:
php examples/example1.php
*/
require dirname(dirname(__FILE__)) . '/src/Populate/LoremIpsumGenerator.class.php';
require dirname(dirname(__FILE__)) . '/src/Populate/Populate.class.php';
try {
    $pdo = new PDO("mysql:host=localhost;dbname=test;charset=utf8", 'root', 'Piko-iko');
    $populate = new Populate();
    $populate->beginWithLoremIpsum(false);
    $populate->setPDO($pdo);
    $populate->setTable('table_test');
    $populate->setFixValue('image_example', '/assets/image/photo.jpg');
    echo $populate->insert(100);
    //echo $populate->clear();
} catch (Exception $e) {
    die($e->getMessage());
}