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


PHP RedBeanDatabase类代码示例

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


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

示例1: testSavingTwiceWithAModelThatHasACurrencyValueAsARelation

 public function testSavingTwiceWithAModelThatHasACurrencyValueAsARelation()
 {
     if (!RedBeanDatabase::isFrozen()) {
         Yii::app()->user->userModel = User::getByUsername('super');
         $testItem = new OwnedSecurableTestItem();
         $testItem->member = 'test';
         $saved = $testItem->save();
         $this->assertTrue($saved);
         //Because OwnedSecurableTestItem as a relatedCurrency, there are some strange issues with saving again.
         //It creates currency validation issues for any of the related users like owner, modifiedUser etc.
         //Need to investigate further to fix.
         //$testItem->forget();
         //$testItem = OwnedSecurableTestItem::getById($testItem->id);
         //Save again immediately after.
         $validated = $testItem->validate();
         // echo "<pre>";
         // print_r($testItem->getErrors());
         // echo "</pre>";
         $this->assertTrue($validated);
         $saved = $testItem->save();
         $this->assertTrue($saved);
         //Reset count of test items to 0.
         $testItem->delete();
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:25,代码来源:OwnedSecurableTestItemTest.php

示例2: onEvent

 public function onEvent($type, $info)
 {
     assert('$type == "after_update"');
     if (RedBeanDatabase::isFrozen()) {
         return;
     }
     $hints = $info->getMeta("hint");
     if ($hints !== null) {
         assert('is_array($hints)');
         foreach ($hints as $key => $value) {
             switch ($value) {
                 case 'date':
                     $this->dateOptimizer->setTable($info->getMeta("type"));
                     $this->dateOptimizer->setColumn($key);
                     $this->dateOptimizer->setValue($info->{$key});
                     $this->dateOptimizer->optimize();
                     break;
                 case 'datetime':
                     $this->datetimeOptimizer->setTable($info->getMeta("type"));
                     $this->datetimeOptimizer->setColumn($key);
                     $this->datetimeOptimizer->setValue($info->{$key});
                     $this->datetimeOptimizer->optimize();
                     break;
                 case 'id':
                     $this->idOptimizer->setTable($info->getMeta("type"));
                     $this->idOptimizer->setColumn($key);
                     $this->idOptimizer->setValue($info->{$key});
                     $this->idOptimizer->optimize();
                     break;
             }
         }
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:33,代码来源:RedBeanAfterUpdateHintManager.php

示例3: testSaveModelFromPostSuccessfulSave

 public function testSaveModelFromPostSuccessfulSave()
 {
     //Unfreeze since the test model is not part of the standard schema.
     $freezeWhenComplete = false;
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     Yii::app()->user->userModel = User::getByUsername('super');
     $savedSuccessfully = false;
     $modelToStringValue = null;
     $postData = array('member' => 'abc');
     $model = new OwnedSecurableTestItem();
     $this->assertFalse($model->hasErrors());
     $controllerUtil = new ZurmoControllerUtil();
     $model = $controllerUtil->saveModelFromPost($postData, $model, $savedSuccessfully, $modelToStringValue);
     $this->assertTrue($savedSuccessfully);
     $this->assertEquals('abc', $modelToStringValue);
     $this->assertFalse($model->hasErrors());
     $this->assertTrue($model->id > 0);
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:25,代码来源:ZurmoControllerUtilTest.php

示例4: teardown

 public function teardown()
 {
     if ($this->freeze) {
         RedBeanDatabase::freeze();
     }
     parent::teardown();
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:7,代码来源:MatrixReportDataProviderTest.php

示例5: testBackupAndRestoreDatabase

 public function testBackupAndRestoreDatabase()
 {
     chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
     // Create new database (zurmo_temp).
     if (RedBeanDatabase::getDatabaseType() == 'mysql') {
         $this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName));
         $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
         $this->assertTrue(is_resource($connection));
         @mysql_select_db($this->temporaryDatabaseName);
         @mysql_query("create table temptable (temptable_id int(11) unsigned not null)", $connection);
         @mysql_query("insert into temptable values ('5')", $connection);
         @mysql_query("insert into temptable values ('10')", $connection);
         $result = @mysql_query("SELECT count(*) from temptable");
         $totalRows = mysql_fetch_row($result);
         @mysql_close($connection);
         $this->assertEquals(2, $totalRows[0]);
         $command = "php zurmocTest.php database backup {$this->databaseBackupTestFile} mysql ";
         $command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
         $command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
         if (!IS_WINNT) {
             $command .= ' 2>&1';
         }
         exec($command, $output);
         sleep(2);
         $this->assertTrue(is_file($this->databaseBackupTestFile));
         //Drop database, and restore it from backup.
         $this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName));
         // Ensure that database don't exist
         $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
         $this->assertTrue(is_resource($connection));
         @mysql_select_db($this->temporaryDatabaseName, $connection);
         $result = @mysql_query("SELECT count(*) from temptable", $connection);
         $this->assertFalse($result);
         // Now restore database
         $command = "php zurmocTest.php database restore {$this->databaseBackupTestFile} mysql ";
         $command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
         $command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
         if (!IS_WINNT) {
             $command .= ' 2>&1';
         }
         exec($command, $output);
         sleep(2);
         $connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
         $this->assertTrue(is_resource($connection));
         $result = @mysql_select_db($this->temporaryDatabaseName, $connection);
         $this->assertTrue($result);
         $result = @mysql_query("SELECT count(*) from temptable", $connection);
         $this->assertTrue(is_resource($result));
         $totalRows = mysql_fetch_row($result);
         $result = @mysql_query("SELECT * from temptable", $connection);
         $rows1 = mysql_fetch_row($result);
         $rows2 = mysql_fetch_row($result);
         @mysql_close($connection);
         $this->assertEquals(2, $totalRows[0]);
         $this->assertEquals(5, $rows1[0]);
         $this->assertEquals(10, $rows2[0]);
     }
 }
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:58,代码来源:DatabaseCommandTest.php

示例6: testGetDatabaseNameFromConnectionString

 /**
  * @expectedException FailedAssertionException
  */
 public function testGetDatabaseNameFromConnectionString()
 {
     $dsn = 'mysql:host=localhost;port=3306;dbname=zurmo';
     // Not Coding Standard
     $databaseName = RedBeanDatabase::getDatabaseNameFromDsnString($dsn);
     $this->assertEquals('zurmo', $databaseName);
     $dsn = 'mysql:host=localhost;';
     // Not Coding Standard
     $databaseName = RedBeanDatabase::getDatabaseNameFromDsnString($dsn);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:13,代码来源:RedBeanDatabaseTest.php

示例7: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     if (!RedBeanDatabase::isFrozen()) {
         // TODO: @Shoaibi: High: get rid of this for God's sake.
         $campaignItem = CampaignItemTestHelper::createCampaignItem(0);
         $campaignItem->delete();
     }
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:10,代码来源:CampaignItemsUtilTest.php

示例8: onEvent

 public function onEvent($type, $info)
 {
     assert('$type == "sql_exec"');
     if (!RedBeanDatabase::isFrozen()) {
         return;
     }
     //echo "<pre>";
     //print_r($info->getSQL());
     //echo "</pre>";
     //now we can count total queries, how many time the same query is run,
     //if we want to do db timings we would need to do this from a different listener. (actually not sure how this will work...)
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:12,代码来源:RedBeanSqlExecuteManager.php

示例9: tearDownAfterClass

 public static function tearDownAfterClass()
 {
     if (RedBeanDatabase::isFrozen()) {
         TestDatabaseUtil::deleteRowsFromAllTablesExceptLog();
     } else {
         TestDatabaseUtil::deleteAllTablesExceptLog();
     }
     RedBeanModel::forgetAll();
     RedBeanDatabase::close();
     assert('!RedBeanDatabase::isSetup()');
     // Not Coding Standard
     GeneralCache::forgetAll();
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:13,代码来源:BaseTest.php

示例10: testResolveModelsHasManyFilesFromPost

 public function testResolveModelsHasManyFilesFromPost()
 {
     if (!RedBeanDatabase::isFrozen()) {
         Yii::app()->user->userModel = User::getByUsername('super');
         $fileCount = count(FileModel::getAll());
         $this->assertEquals(0, $fileCount);
         $file1 = ZurmoTestHelper::createFileModel();
         $file2 = ZurmoTestHelper::createFileModel();
         $file3 = ZurmoTestHelper::createFileModel();
         $model = new ModelWithAttachmentTestItem();
         $_POST['myTest'] = array($file1->id, $file2->id, $file3->id);
         FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
         $model->member = 'test';
         $saved = $model->save();
         $this->assertTrue($saved);
         $fileCount = count(FileModel::getAll());
         $this->assertEquals(3, $fileCount);
         $modelId = $model->id;
         $model->forget();
         $model = ModelWithAttachmentTestItem::getById($modelId);
         $this->assertEquals(3, $model->files->count());
         //Add a fourth file.
         $file4 = ZurmoTestHelper::createFileModel();
         $_POST['myTest'] = array($file1->id, $file2->id, $file3->id, $file4->id);
         FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
         $saved = $model->save();
         $this->assertTrue($saved);
         $fileCount = count(FileModel::getAll());
         $this->assertEquals(4, $fileCount);
         $model->forget();
         $model = ModelWithAttachmentTestItem::getById($modelId);
         $this->assertEquals(4, $model->files->count());
         //Remove the 2nd file.
         $_POST['myTest'] = array($file1->id, $file3->id, $file4->id);
         FileModelUtil::resolveModelsHasManyFilesFromPost($model, 'files', 'myTest');
         $saved = $model->save();
         $this->assertTrue($saved);
         $fileCount = count(FileModel::getAll());
         $this->assertEquals(3, $fileCount);
         $model->forget();
         $model = ModelWithAttachmentTestItem::getById($modelId);
         $this->assertEquals(3, $model->files->count());
         $compareIds = array($file1->id, $file3->id, $file4->id);
         foreach ($model->files as $fileModel) {
             $this->assertTrue(in_array($fileModel->id, $compareIds));
         }
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:48,代码来源:FileModelUtilTest.php

示例11: onEvent

 public function onEvent($type, $info)
 {
     assert('$type == "update"');
     if (RedBeanDatabase::isFrozen()) {
         return;
     }
     $hints = $info->getMeta("hint");
     if ($hints !== null) {
         assert('is_array($hints)');
         foreach ($hints as $key => $value) {
             if (in_array($value, array('blob', 'longblob', 'boolean', 'date', 'datetime', 'string', 'text', 'longtext', 'id'))) {
                 RedBeanColumnTypeOptimizer::optimize($info->getMeta("type"), $key, $value);
             }
         }
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:16,代码来源:RedBeanBeforeUpdateHintManager.php

示例12: testASingleAttributeThatRunsFrozenQueryCorrectly

 /**
  * Make sure the query actually runs correctly.
  */
 public function testASingleAttributeThatRunsFrozenQueryCorrectly()
 {
     if (RedBeanDatabase::isFrozen()) {
         $q = DatabaseCompatibilityUtil::getQuote();
         $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('ReportModelTestItem');
         $builder = new FiltersReportQueryBuilder($joinTablesAdapter, '1');
         $filter = new FilterForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
         $filter->attributeIndexOrDerivedType = 'ReadOptimization';
         $content = $builder->makeQueryContent(array($filter));
         $compareContent = "({$q}ownedsecurableitem{$q}.{$q}securableitem_id{$q} = (select securableitem_id " . "from {$q}account_read{$q} where {$q}securableitem_id{$q} = {$q}ownedsecurableitem" . "{$q}.{$q}securableitem_id{$q} and {$q}munge_id{$q} in ('U" . self::$superUserId . "', 'G" . self::$everyoneGroupId . "') limit 1))";
         $this->assertEquals($compareContent, $content);
         $this->assertEquals(1, $joinTablesAdapter->getFromTableJoinCount());
         $this->assertEquals(0, $joinTablesAdapter->getLeftTableJoinCount());
         $selectQueryAdapter = new RedBeanModelSelectQueryAdapter();
         $selectQueryAdapter->addClause(Account::getTableName('Account'), 'id');
         $sql = SQLQueryUtil::makeQuery(Account::getTableName('Account'), $selectQueryAdapter, $joinTablesAdapter, null, null, $content, null, null);
         $rows = R::getAll($sql);
         $this->assertEquals(0, count($rows));
     }
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:23,代码来源:ReadOptimizationFiltersReportQueryBuilderTest.php

示例13: save

 public function save($runValidation = true)
 {
     foreach ($this->deferredRelateBeans as $bean) {
         R::associate($this->bean, $bean);
         if (!RedBeanDatabase::isFrozen()) {
             $types = array($this->bean->getMeta("type"), $bean->getMeta("type"));
             sort($types);
             $tableName = implode("_", $types);
             foreach ($types as $type) {
                 $columnName = "{$type}_id";
                 RedBeanColumnTypeOptimizer::optimize($tableName, $columnName, 'id');
             }
         }
     }
     $this->deferredRelateBeans = array();
     foreach ($this->deferredUnrelateBeans as $bean) {
         R::unassociate($this->bean, $bean);
     }
     $this->deferredUnrelateBeans = array();
     return true;
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:21,代码来源:RedBeanManyToManyRelatedModels.php

示例14: makeDatabaseTableByFileHandleAndTableName

 /**
  * Given a file resource, convert the file into a database table based on the table name provided.
  * Assumes the file is a csv.
  * @param resource $fileHandle
  * @param string $tableName
  * @return true on success.
  */
 public static function makeDatabaseTableByFileHandleAndTableName($fileHandle, $tableName, $delimiter = ',', $enclosure = "'")
 {
     assert('gettype($fileHandle) == "resource"');
     assert('is_string($tableName)');
     assert('$tableName == strtolower($tableName)');
     assert('$delimiter != null && is_string($delimiter)');
     assert('$enclosure != null && is_string($enclosure)');
     $freezeWhenComplete = false;
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     R::exec("drop table if exists {$tableName}");
     $columns = self::optimizeTableImportColumnsAndGetColumnNames($fileHandle, $tableName, $delimiter, $enclosure);
     rewind($fileHandle);
     self::convertCsvIntoRowsInTable($fileHandle, $tableName, $delimiter, $enclosure, $columns);
     self::optimizeTableNonImportColumns($tableName);
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
     return true;
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:29,代码来源:ImportDatabaseUtil.php

示例15: setByModuleName

 /**
  * Set a global configuration value by module name and key
  */
 public static function setByModuleName($moduleName, $key, $value)
 {
     assert('is_string($moduleName)');
     assert('is_string($key)');
     if (!RedBeanDatabase::isSetup()) {
         return null;
     }
     $metadata = $moduleName::getMetadata();
     $metadata['global'][$key] = $value;
     static::cacheValue($moduleName, $key, $value);
     $moduleName::setMetadata($metadata);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:15,代码来源:ZurmoConfigurationUtil.php


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