Skip to content

Instantly share code, notes, and snippets.

@jp1987
Created November 21, 2012 14:50
Show Gist options
  • Save jp1987/4125206 to your computer and use it in GitHub Desktop.
Save jp1987/4125206 to your computer and use it in GitHub Desktop.
Solving my mass-inserting problem using a "direct" connection to the DB
<?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