本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::getConnection方法的具体用法?PHP ObjectManager::getConnection怎么用?PHP ObjectManager::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Change the property on the given node.
*
* @param NodeData $node
* @return void
*/
public function execute(NodeData $node)
{
foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
if (isset($propertyConfiguration['type']) && in_array(trim($propertyConfiguration['type']), $this->getHandledObjectTypes())) {
if (!isset($nodeProperties)) {
$nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?');
$nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]);
$nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC);
$nodeProperties = unserialize($nodeRecord['properties']);
}
if (!isset($nodeProperties[$propertyName]) || !is_object($nodeProperties[$propertyName])) {
continue;
}
/** @var Asset $assetObject */
$assetObject = $nodeProperties[$propertyName];
$nodeProperties[$propertyName] = null;
$stream = $assetObject->getResource()->getStream();
if ($stream === false) {
continue;
}
fclose($stream);
$objectType = TypeHandling::getTypeForValue($assetObject);
$objectIdentifier = ObjectAccess::getProperty($assetObject, 'Persistence_Object_Identifier', true);
$nodeProperties[$propertyName] = array('__flow_object_type' => $objectType, '__identifier' => $objectIdentifier);
}
}
if (isset($nodeProperties)) {
$nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?');
$nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]);
}
}
示例2: createTable
public function createTable($name)
{
// remove table
$pdo = $this->pdo->query('DROP TABLE IF EXISTS `' . $name . '`;');
$pdo->execute();
// create table
$newSchema = new \Doctrine\DBAL\Schema\Schema();
$newTable = $newSchema->createTable($name);
$newTable->addColumn('container_id', 'integer');
$newTable->addColumn('context_id', 'integer');
$newTable->addColumn('module_id', 'integer');
$newTable->addColumn('resource_id', 'integer')->setNotnull(false);
$newTable->addColumn('by_resource_id', 'integer')->setNotnull(false);
$newTable->addColumn('sequence', 'integer')->setNotnull(false);
$newTable->addColumn('deleted', 'datetime')->setNotnull(false);
$newTable->addColumn('display', 'boolean')->setNotnull(true);
$newTable->addColumn('expire_temporary_date', 'datetime')->setNotnull(false);
$newTable->addColumn('culture', 'string')->setLength(11);
foreach ($this->eavColumns->getColumns() as $column) {
if ($this->getTypeToColumn($column['column'])) {
$newTable->addColumn($column['identifier'], $this->getTypeToColumn($column['column']))->setNotnull(false);
$columnsToFill[] = $column['identifier'];
}
}
$newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Container')->getTablename(), array('container_id'), array('container_id'), array('onDelete' => 'CASCADE'));
$newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishEavBundle:Module')->getTablename(), array('module_id'), array('module_id'), array('onDelete' => 'CASCADE'));
$newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishContextBundle:Context')->getTablename(), array('context_id'), array('context_id'), array('onDelete' => 'CASCADE'));
$newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('resource_id'), array('resource_id'), array('onDelete' => 'CASCADE'));
$newTable->addForeignKeyConstraint($this->objectManager->getClassMetadata('BigfishResourceBundle:Resource')->getTablename(), array('by_resource_id'), array('resource_id'), array('onDelete' => 'CASCADE'));
foreach ($newSchema->toSql($this->objectManager->getConnection()->getDatabasePlatform()) as $l) {
$pdo = $this->pdo->prepare($l);
$pdo->execute();
}
}
示例3: getSql
/**
* @param DoctrineSqlFilter $sqlFilter
* @param ClassMetadata $targetEntity Metadata object for the target entity to create the constraint for
* @param string $targetTableAlias The target table alias used in the current query
* @return string
*/
public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
{
$quotedCollectionTitle = $this->entityManager->getConnection()->quote($this->collectionTitle);
return $targetTableAlias . '.persistence_object_identifier IN (
SELECT ' . $targetTableAlias . '_a.persistence_object_identifier
FROM typo3_media_domain_model_asset AS ' . $targetTableAlias . '_a
LEFT JOIN typo3_media_domain_model_assetcollection_assets_join ' . $targetTableAlias . '_acj ON ' . $targetTableAlias . '_a.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_asset
LEFT JOIN typo3_media_domain_model_assetcollection ' . $targetTableAlias . '_ac ON ' . $targetTableAlias . '_ac.persistence_object_identifier = ' . $targetTableAlias . '_acj.media_assetcollection
WHERE ' . $targetTableAlias . '_ac.title = ' . $quotedCollectionTitle . ')';
}
开发者ID:bwaidelich,项目名称:Wwwision.AssetConstraints,代码行数:16,代码来源:AssetAssetCollectionConditionGenerator.php
示例4: load
/**
* Load data fixtures with the passed EntityManager
*
* @param \Doctrine\Common\Persistence\ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$query = $manager->createQuery('SELECT COUNT(f) FROM \\Acme\\Bundle\\AppBundle\\Entity\\Fabric f');
if (0 === $query->getSingleScalarResult()) {
$stmt = $manager->getConnection()->prepare($this->getFabricsSql());
$stmt->execute();
}
$query = $manager->createQuery('SELECT COUNT(c) FROM \\Acme\\Bundle\\AppBundle\\Entity\\Color c');
if (0 === $query->getSingleScalarResult()) {
$stmt = $manager->getConnection()->prepare($this->getColorSql());
$stmt->execute();
}
}
示例5: collectResourcePointersCommand
/**
* Runs garbage collection for the ResourcePointers and their associated physical files
*
* @return void
*/
public function collectResourcePointersCommand()
{
$connection = $this->entityManager->getConnection();
$path = FLOW_PATH_DATA . "Persistent/Resources/";
// Find and delete all orphaned ResourcePointers
$stmt = $connection->executeQuery('SELECT `hash` ' . 'FROM `typo3_flow_resource_resourcepointer` AS `rp` ' . 'LEFT OUTER JOIN `typo3_flow_resource_resource` AS `r` ON `r`.`resourcepointer` = `rp`.`hash` ' . 'WHERE `r`.`persistence_object_identifier` IS NULL ');
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$hash = $row["hash"];
$this->outputLine("Found orphaned ResourcePointer: %s", array($hash));
// Remove ResoursePointer from database
$result = $connection->executeUpdate('DELETE FROM `typo3_flow_resource_resourcepointer` ' . 'WHERE `hash` = "' . $hash . '"');
if ($result) {
$this->outputLine("...deleted entity");
} else {
$this->outputLine("...COULD NOT DELETE ENTITY!");
}
// Remove physical file
if (file_exists($path . $hash)) {
if (unlink($path . $hash)) {
$this->outputLine("...deleted physical file");
} else {
$this->outputLine("...COULD NOT DELETE PHYSICAL FILE!");
}
} else {
$this->outputLine("...physical file already deleted");
}
}
// Find and delete all orphaned physical files
$files = scandir($path);
$files = array_filter($files, function ($elem) {
return preg_match('/^[0-9a-f]+$/', $elem);
});
// Create temporary table in memory and fill it with physical file hashes
$connection->executeUpdate('CREATE TEMPORARY TABLE `etg24_cleanup_command_garbage_files` (`hash` CHAR(40)) ENGINE=MEMORY');
if (!empty($files)) {
$connection->executeUpdate('INSERT INTO `etg24_cleanup_command_garbage_files` (`hash`) VALUES ("' . implode('"), ("', $files) . '")');
}
$stmt = $connection->executeQuery('SELECT `f`.`hash` ' . 'FROM `etg24_cleanup_command_garbage_files` AS `f` ' . 'LEFT OUTER JOIN `typo3_flow_resource_resourcepointer` AS `rp` USING(`hash`) ' . 'WHERE `rp`.`hash` IS NULL ');
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$hash = $row["hash"];
$this->outputLine("Found orphaned physical file: %s", array($hash));
// Remove physical file
if (unlink($path . $hash)) {
$this->outputLine("...deleted physical file");
} else {
$this->outputLine("...COULD NOT DELETE PHYSICAL FILE!");
}
}
}
示例6: getMaxIdentifierLength
/**
* Derive maximum identifier length from doctrine DBAL
*
* @return integer
*/
protected function getMaxIdentifierLength()
{
if ($this->tableNameLengthLimit === null) {
$this->tableNameLengthLimit = $this->entityManager->getConnection()->getDatabasePlatform()->getMaxIdentifierLength();
}
return $this->tableNameLengthLimit;
}
示例7: load
public function load(ObjectManager $manager)
{
$filename = "src/ESN/AdministrationBundle/DataFixtures/SQL/University.sql";
$sql = file_get_contents($filename);
$manager->getConnection()->exec($sql);
$manager->flush();
}
示例8: truncate
/**
*
* @param ObjectManager|EntityManager $manager
* @param
* $class
* @return bool
*/
public static function truncate(ObjectManager $manager, $class)
{
/**
* @var $connection \Doctrine\DBAL\Connection
*/
$connection = $manager->getConnection();
/**
* @var $cmd ClassMetadata
*/
$cmd = $manager->getClassMetadata($class);
$connection->beginTransaction();
try {
if ($connection->getDatabasePlatform()->getName() !== 'sqlite') {
$connection->query('SET FOREIGN_KEY_CHECKS=0');
$connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql($cmd->getTableName()));
$connection->query('SET FOREIGN_KEY_CHECKS=1');
} else {
$connection->executeUpdate($connection->getDatabasePlatform()->getTruncateTableSql($cmd->getTableName()));
}
$connection->commit();
return true;
} catch (\Exception $e) {
$connection->rollback();
return false;
}
}
示例9: load
public function load(ObjectManager $manager)
{
$conn = $manager->getConnection();
$stmt = $conn->prepare('select id from lots');
$stmt->execute();
$lotIds = [];
while ($lotId = $stmt->fetchColumn()) {
$lotIds[] = (int) $lotId;
}
$stmt = $conn->prepare('select id from users');
$stmt->execute();
$usrIds = [];
while ($usrId = $stmt->fetchColumn()) {
$usrIds[] = (int) $usrId;
}
for ($i = 0, $l = count($lotIds) * count($usrIds); $i < $l; $i++) {
$lot = $manager->getRepository('BankrotSiteBundle:Lot')->find($lotIds[array_rand($lotIds)]);
if ($lot->getBeginDate()) {
if (0 === rand(0, 2)) {
$lw = new LotWatch();
$lw->setOwner($manager->getRepository('BankrotSiteBundle:User')->find($usrIds[array_rand($usrIds)]));
$lw->setLot($lot);
$lw->setPrice(rand(0, 1000000));
$lw->setCutOffPrice(rand(10, 5000));
$lw->setDay(new \DateTime('@' . rand($lot->getBeginDate()->getTimestamp(), $lot->getEndDate()->getTimestamp())));
$manager->persist($lw);
}
}
}
$manager->flush();
}
示例10: load
public function load(ObjectManager $manager)
{
$data = (include __DIR__ . '/../fixtures/user/users.php');
$encoder = $this->container->get('security.password_encoder');
$userManager = $this->container->get('medievistes.user_manager');
$connection = $manager->getConnection();
if ($connection->getDatabasePlatform()->getName() === 'mysql') {
$connection->exec("ALTER TABLE {$manager->getClassMetadata(User::class)->getTableName()} AUTO_INCREMENT = 1;");
}
foreach ($data as $userData) {
$class = $userManager->getUserClass($userData['type']);
$user = (new $class())->setId((int) $userData['id'])->setUsername($userData['username'])->setEmail($userData['email'])->setPlainPassword($userData['plain_password'])->setSalt(md5(uniqid(null, true)))->enable((bool) $userData['is_active'])->setCreatedAt(new \DateTime($userData['created_at']))->setUpdatedAt(new \DateTime($userData['updated_at']));
if (!empty($userData['activation_link_id'])) {
$user->setActivationLink($this->getReference("activation-link-{$userData['activation_link_id']}"));
}
foreach ($userData['roles'] as $role) {
$user->addRole($role);
}
foreach ($userData['troops'] as $troop) {
$association = (new Association())->setUser($user)->setTroop($this->getReference("troop-{$troop['troop_id']}"))->setRole($this->getReference("troop-role-{$troop['role_id']}"));
$user->addTroopAssociation($association);
$manager->persist($association);
}
$password = $encoder->encodePassword($user, $userData['plain_password']);
$user->setPassword($password);
$manager->persist($user);
$manager->flush();
$this->addReference("user-{$user->getId()}", $user);
}
$manager->clear($class);
$manager->clear(Association::class);
}
示例11: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$manager->getConnection()->executeQuery("SET foreign_key_checks = 0;");
$pageEtat = new PageEtat();
$pageEtat->setLibelle('brouillon');
$manager->persist($pageEtat);
$manager->flush();
$pageEtat = new PageEtat();
$pageEtat->setLibelle('A valider');
$manager->persist($pageEtat);
$manager->flush();
$pageEtat = new PageEtat();
$pageEtat->setLibelle('Validée');
$manager->persist($pageEtat);
$manager->flush();
$manager->getConnection()->executeQuery("SET foreign_key_checks = 1;");
}
示例12: alisInkKlosterImportCommand
/**
*/
public function alisInkKlosterImportCommand()
{
/** @var DataImportController $importer */
$importer = new DataImportController($this->logger, $this->settings);
/** @var \Doctrine\DBAL\Connection $sqlConnection */
$sqlConnection = $this->entityManager->getConnection();
$sql = 'SET unique_checks = 0';
$sqlConnection->executeUpdate($sql);
$sql = 'SET foreign_key_checks = 0';
$sqlConnection->executeUpdate($sql);
$importer->delAccessKlosterTabAction();
$importer->importAccessInkKlosterDataAction();
$importer->importKlosterAction();
$sql = 'SET foreign_key_checks = 1';
$sqlConnection->executeUpdate($sql);
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
$this->logger->log('Import completed in ' . $time . ' seconds.');
}
示例13: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
/** @var \Doctrine\ORM\EntityManagerInterface $manager */
$connection = $manager->getConnection();
$date = (new \DateTime('-3 days'))->format('Y-m-d H:i:s');
// we need to use bare sql
// since the auth process is difficult to build when using the domain models
$connection->exec("\nINSERT INTO SEN_Token (apiKey, tokenId) VALUES (PASSWORD(RAND()), 1);\nINSERT INTO SEN_User (credentials_username, credentials_password, profile_email, profile_realName, profile_registrationDate, profile_lastAction, profile_locked, profile_locale, tokenId) VALUES ('Ma27', PASSWORD('test-password'), 'foo@bar.de', '', '" . $date . "', '" . $date . "', 0, 'en', 1);");
}
示例14: initializeConnection
/**
* Initializes the DBAL connection which is currently bound to the Doctrine Entity Manager
*
* @return void
*/
protected function initializeConnection()
{
if (!$this->entityManager instanceof EntityManager) {
$this->outputLine('This command only supports database connections provided by the Doctrine ORM Entity Manager.
However, the current entity manager is an instance of %s.', array(get_class($this->entityManager)));
$this->quit(1);
}
$this->dbalConnection = $this->entityManager->getConnection();
}
示例15: __construct
/**
* @param ObjectManager $objectManager
* @param LanguageManager $languageManager
* @param ModuleRepository $moduleRepository
* @param FlatternTable $flatternTable
*/
public function __construct(ObjectManager $objectManager, LanguageManager $languageManager, ModuleRepository $moduleRepository, FlatternTable $flatternTable)
{
$this->objectManager = $objectManager;
$this->pdo = $objectManager->getConnection();
$this->languageManager = $languageManager;
$this->moduleRepository = $moduleRepository;
$this->flatternTable = $flatternTable;
return $this;
}