Created
November 21, 2012 14:50
-
-
Save jp1987/4125206 to your computer and use it in GitHub Desktop.
Solving my mass-inserting problem using a "direct" connection to the DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace TYPO3\Docs\Build\Storage; | |
/* * | |
* This script belongs to the FLOW3 package "TYPO3.Docs.Build". * | |
* * | |
* * | |
*/ | |
use TYPO3\FLOW3\Annotations as FLOW3; | |
/** | |
* Class dealing with Package Storage | |
* | |
* @FLOW3\Scope("singleton") | |
*/ | |
class PackageStorage { | |
/** | |
* @FLOW3\Inject | |
* @var \Doctrine\Common\Persistence\ObjectManager | |
*/ | |
protected $entityManager; | |
/** | |
* @FLOW3\Inject | |
* @var \TYPO3\FLOW3\Persistence\Doctrine\Mapping\Driver\Flow3AnnotationDriver | |
*/ | |
protected $flow3AnnotationDriver; | |
/** | |
* @var \Doctrine\DBAL\Connection | |
*/ | |
protected $connection; | |
/** | |
* @var string | |
*/ | |
protected $tableName; | |
/** | |
* Further object initialization | |
* | |
* @return void | |
*/ | |
public function initializeObject() { | |
/** @var $entityManager \Doctrine\ORM\EntityManager */ | |
$entityManager = $this->entityManager; | |
$this->connection = $entityManager->getConnection(); | |
$this->tableName = $this->flow3AnnotationDriver->inferTableNameFromClassName('TYPO3\Docs\Build\Domain\Model\Package'); | |
} | |
/** | |
* Persist data | |
* | |
* @param array $data | |
* @return boolean | |
*/ | |
public function persist($data) { | |
$data['flow3_persistence_identifier'] = \TYPO3\FLOW3\Utility\Algorithms::generateUUID(); | |
$this->connection->insert($this->tableName, (array) $data);; | |
} | |
/** | |
* Delete records given a repository type | |
* | |
* @param string $repositoryType | |
*/ | |
public function deleteByRepositoryType($repositoryType) { | |
$data['repositoryType'] = $repositoryType; | |
$this->connection->delete($this->tableName, (array) $data);; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment