public function register(Application $app) { $app['storage.legacy'] = $app->share(function ($app) { return new Storage($app); }); $app['storage'] = $app->share(function ($app) { $storage = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata'], $app['logger.system']); $storage->setLegacyStorage($app['storage.legacy']); foreach ($app['storage.repositories'] as $entity => $repo) { $storage->setRepository($entity, $repo); } $storage->setDefaultRepositoryFactory(function ($classMetadata) use($app) { $repoClass = $app['storage.repository.default']; $repo = new $repoClass($app['storage'], $classMetadata); return $repo; }); return $storage; }); $app['storage.repository.default'] = 'Bolt\\Storage\\Repository\\ContentRepository'; $app['storage.typemap'] = ['Doctrine\\DBAL\\Types\\StringType' => 'Bolt\\Storage\\Field\\Type\\TextType', 'Doctrine\\DBAL\\Types\\IntegerType' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'Doctrine\\DBAL\\Types\\FloatType' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'Doctrine\\DBAL\\Types\\TextType' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'Doctrine\\DBAL\\Types\\DateType' => 'Bolt\\Storage\\Field\\Type\\DateType', 'Doctrine\\DBAL\\Types\\DateTimeType' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'checkbox' => 'Bolt\\Storage\\Field\\Type\\CheckboxType', 'date' => 'Bolt\\Storage\\Field\\Type\\DateType', 'datetime' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'file' => 'Bolt\\Storage\\Field\\Type\\FileType', 'filelist' => 'Bolt\\Storage\\Field\\Type\\FileListType', 'float' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'geolocation' => 'Bolt\\Storage\\Field\\Type\\GeolocationType', 'html' => 'Bolt\\Storage\\Field\\Type\\HtmlType', 'image' => 'Bolt\\Storage\\Field\\Type\\ImageType', 'imagelist' => 'Bolt\\Storage\\Field\\Type\\ImageListType', 'integer' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'markdown' => 'Bolt\\Storage\\Field\\Type\\MarkdownType', 'relation' => 'Bolt\\Storage\\Field\\Type\\RelationType', 'repeater' => 'Bolt\\Storage\\Field\\Type\\RepeaterType', 'select' => 'Bolt\\Storage\\Field\\Type\\SelectType', 'slug' => 'Bolt\\Storage\\Field\\Type\\SlugType', 'taxonomy' => 'Bolt\\Storage\\Field\\Type\\TaxonomyType', 'templateselect' => 'Bolt\\Storage\\Field\\Type\\TemplateSelectType', 'text' => 'Bolt\\Storage\\Field\\Type\\TextType', 'textarea' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'video' => 'Bolt\\Storage\\Field\\Type\\VideoType']; $app['storage.repositories'] = ['Bolt\\Storage\\Entity\\Authtoken' => 'Bolt\\Storage\\Repository\\AuthtokenRepository', 'Bolt\\Storage\\Entity\\Cron' => 'Bolt\\Storage\\Repository\\CronRepository', 'Bolt\\Storage\\Entity\\LogChange' => 'Bolt\\Storage\\Repository\\LogChangeRepository', 'Bolt\\Storage\\Entity\\LogSystem' => 'Bolt\\Storage\\Repository\\LogSystemRepository', 'Bolt\\Storage\\Entity\\Users' => 'Bolt\\Storage\\Repository\\UsersRepository']; $app['storage.metadata'] = $app->share(function ($app) { $meta = new MetadataDriver($app['schema'], $app['config']->get('contenttypes'), $app['config']->get('taxonomy'), $app['storage.typemap']); return $meta; }); $app['storage.record_modifier'] = $app->share(function ($app) { $cm = new RecordModifier($app); return $cm; }); $app['storage.listener'] = $app->share(function () use($app) { return new StorageEventListener($app['storage'], $app['authentication.hash.strength']); }); }
/** * @inheritdoc */ public function persist(QuerySet $queries, $entity, EntityManager $em = null) { $field = $this->mapping['fieldname']; $target = $this->mapping['target']; $accessor = "get" . $field; $taxonomy = (array) $entity->{$accessor}(); // Fetch existing relations $existingQuery = $em->createQueryBuilder()->select('*')->from($target)->where('content_id = ?')->andWhere('contenttype = ?')->andWhere('taxonomytype = ?')->setParameter(0, $entity->id)->setParameter(1, $entity->getContenttype())->setParameter(2, $field); $result = $existingQuery->execute()->fetchAll(); $existing = array_map(function ($el) { return $el['slug']; }, $result); $proposed = $taxonomy; $toInsert = array_diff($proposed, $existing); $toDelete = array_diff($existing, $proposed); foreach ($toInsert as $item) { $ins = $em->createQueryBuilder()->insert($target); $ins->values(['content_id' => '?', 'contenttype' => '?', 'taxonomytype' => '?', 'slug' => '?', 'name' => '?'])->setParameters([0 => $entity->id, 1 => $entity->getContenttype(), 2 => $field, 3 => $item, 4 => $this->mapping['data']['options'][$item]]); $queries->append($ins); } foreach ($toDelete as $item) { $del = $em->createQueryBuilder()->delete($target); $del->where('content_id=?')->andWhere('contenttype=?')->andWhere('taxonomytype=?')->andWhere('slug=?')->setParameters([0 => $entity->id, 1 => $entity->getContenttype(), 2 => $field, 3 => $item]); $queries->append($del); } }
/** * @inheritdoc */ public function hydrate($data, $entity, EntityManager $em = null) { $key = $this->mapping['fieldname']; $type = $this->getStorageType(); $val = $data[$key]; $value = $type->convertToPHPValue($val, $em->createQueryBuilder()->getConnection()->getDatabasePlatform()); $entity->{$key} = $value; }
public function __construct(array $mapping = [], EntityManager $em = null) { $this->mapping = $mapping; $this->em = $em; if ($em) { $this->setPlatform($em->createQueryBuilder()->getConnection()->getDatabasePlatform()); } }
public function testGetDefaultRepositoryFactory() { $app = $this->getApp(); $em = $app['storage']; $repo = $em->getRepository('showcases'); // The first check should work, this one should fail because the factory has not been set. $this->setExpectedException('RuntimeException'); $em = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata']); $repo = $em->getRepository('showcases'); }
/** * Get the content records, and fallback a page if none found. * * @param string $contentTypeSlug * @param array $contentParameters * @param ListingOptions $options * * @return Content|false */ protected function getContent($contentTypeSlug, array $contentParameters, ListingOptions $options) { $records = $this->em->getContent($contentTypeSlug, $contentParameters); // UGLY HACK! Remove when cutting over to the new storage layer! $records = empty($records) ? false : $records; if ($records === false && $options->getPage() !== null) { $contentParameters['page'] = $options->getPreviousPage(); $records = $this->em->getContent($contentTypeSlug, $contentParameters); } return $records; }
/** * Kernel request listener callback. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $contenttypes = $this->config->get('contenttypes', []); foreach ($contenttypes as $contenttype) { $contenttype = $this->em->getContentType($contenttype['slug']); // Check if we need to 'publish' any 'timed' records, or 'depublish' any expired records. $this->em->publishTimedRecords($contenttype); $this->em->depublishExpiredRecords($contenttype); } }
/** * Modify an individual ContentType's records. * * @param string $contentTypeName ContentType slug * @param array $changeRequest Change array in the format of: * [id => [action => [field => value]]] */ public function action($contentTypeName, array $changeRequest) { foreach ($changeRequest as $recordId => $actionData) { if ($actionData === null) { continue; } $repo = $this->em->getRepository($contentTypeName); foreach ($actionData as $action => $fieldData) { if (!($entity = $repo->find($recordId))) { continue; } $this->modifyContentTypeRecord($repo, $entity, $action, $fieldData); } } }
/** * @return Builder $builder */ public function getEntityBuilder() { $builder = $this->em->getEntityBuilder(); $builder->setClass($this->getEntityName()); $builder->setClassMetadata($this->getClassMetadata()); return $builder; }
/** * Updates an object into the database. * * @param object $entity The entity to update. * * @return bool */ public function update($entity) { $querySet = new QuerySet(); $qb = $this->em->createQueryBuilder(); $qb->update($this->getTableName())->where('id = :id')->setParameter('id', $entity->getId()); $querySet->append($qb); $this->persister->persist($querySet, $entity, $this->em); return $querySet->execute(); }
/** * Convert POST relationship values to an array of Entity objects keyed by * ContentType. * * @param array $contenttype * * @return array */ private function getRelationsList(array $contenttype) { $list = []; if (!isset($contenttype['relations']) || !is_array($contenttype['relations'])) { return $list; } foreach ($contenttype['relations'] as $contentType => $relation) { $repo = $this->em->getRepository($contentType); $list[$contentType] = $repo->getSelectList($contentType, $relation['order']); } return $list; }
/** * Convert POST relationship values to an array of Entity objects keyed by * ContentType. * * @param array $contentType * * @return array */ private function getRelationsList(array $contentType) { $list = []; if (!isset($contentType['relations']) || !is_array($contentType['relations'])) { return $list; } foreach ($contentType['relations'] as $relationName => $relationValues) { $repo = $this->em->getRepository($relationName); $relationConfig = $this->config->get('contenttypes/' . $relationName, []); $list[$relationName] = $repo->getSelectList($relationConfig, $relationValues['order']); } return $list; }
/** * Fetch a listing of ContentType records. * * @param string $contentTypeSlug * @param string $order * @param integer $page * @param array $taxonomies * @param string $filter */ public function action($contentTypeSlug, $order = null, $page = null, array $taxonomies = null, $filter = null) { // Order has to be set carefully. Either set it explicitly when the user // sorts, or fall back to what's defined in the contenttype. Except for // a ContentType that has a "grouping taxonomy", as that should override // it. That exception state is handled by the query OrderHandler. $contenttype = $this->em->getContentType($contentTypeSlug); $contentParameters = ['paging' => true, 'hydrate' => true, 'order' => $order ?: $contenttype['sort'], 'page' => $page, 'filter' => $filter]; // Set the amount of items to show per page if (!empty($contenttype['recordsperpage'])) { $contentParameters['limit'] = $contenttype['recordsperpage']; } else { $contentParameters['limit'] = $this->config->get('general/recordsperpage'); } // Filter on taxonomies if ($taxonomies !== null) { foreach ($taxonomies as $taxonomy => $value) { $contentParameters[$taxonomy] = $value; } } return $this->em->getContent($contentTypeSlug, $contentParameters); }
/** * Convert POST relationship values to an array of Entity objects keyed by * ContentType. * * @param ContentType $contentType * * @return array */ private function getRelationsList(ContentType $contentType) { $list = []; if (!isset($contentType['relations']) || !is_array($contentType['relations'])) { return $list; } foreach ($contentType['relations'] as $relationName => $relationValues) { /** @var Repository\ContentRepository $repo */ $repo = $this->em->getRepository($relationName); $relationConfig = $this->config->get('contenttypes/' . $relationName, []); $neededFields = $this->neededFields($relationValues, $relationConfig); $order = isset($relationValues['order']) ? $relationValues['order'] : null; $list[$relationName] = $repo->getSelectList($relationConfig, $order, $neededFields); } return $list; }
/** * Commit the record to the database. * * @param Entity\Content $content * @param Entity\Content|null $oldContent * @param array $contentType * @param boolean $new * @param string $comment * @param string $returnTo * @param string $editReferrer * * @return Response */ private function saveContentRecord(Entity\Content $content, $oldContent, array $contentType, $new, $comment, $returnTo, $editReferrer) { // Save the record $repo = $this->em->getRepository($contentType['slug']); // Update the date modified timestamp $content->setDatechanged('now'); $repo->save($content); $id = $content->getId(); // Create the change log entry if configured $this->logChange($contentType, $content->getId(), $content, $oldContent, $comment); // Log the change if ($new) { $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-new', ['%contenttype%' => $contentType['slug']])); $this->loggerSystem->info('Created: ' . $content->getTitle(), ['event' => 'content']); } else { $this->loggerFlash->success(Trans::__('contenttypes.generic.saved-changes', ['%contenttype%' => $contentType['slug']])); $this->loggerSystem->info('Saved: ' . $content->getTitle(), ['event' => 'content']); } /* * We now only get a returnto parameter if we are saving a new * record and staying on the same page, i.e. "Save {contenttype}" */ if ($returnTo) { if ($returnTo === 'new') { return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], 'id' => $id, '#' => $returnTo])); } elseif ($returnTo === 'saveandnew') { return new RedirectResponse($this->generateUrl('editcontent', ['contenttypeslug' => $contentType['slug'], '#' => $returnTo])); } elseif ($returnTo === 'ajax') { return $this->createJsonUpdate($content, true); } elseif ($returnTo === 'test') { return $this->createJsonUpdate($content, false); } } // No returnto, so we go back to the 'overview' for this contenttype. // check if a pager was set in the referrer - if yes go back there if ($editReferrer) { return new RedirectResponse($editReferrer); } else { return new RedirectResponse($this->generateUrl('overview', ['contenttypeslug' => $contentType['slug']])); } }
public function register(Application $app) { $app['storage.legacy'] = $app->share(function ($app) { return new Storage($app); }); $app['storage.legacy_service'] = $app->share(function ($app) { return new ContentLegacyService($app); }); $app['storage'] = $app->share(function ($app) { $storage = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata'], $app['logger.system']); $storage->setLegacyStorage($app['storage.legacy']); $storage->setEntityBuilder($app['storage.entity_builder']); $storage->setFieldManager($app['storage.field_manager']); $storage->setCollectionManager($app['storage.collection_manager']); foreach ($app['storage.repositories'] as $entity => $repo) { $storage->setRepository($entity, $repo); } $storage->setDefaultRepositoryFactory($app['storage.content_repository']); return $storage; }); $app['storage.content_repository'] = $app->protect(function ($classMetadata) use($app) { $repoClass = $app['storage.repository.default']; $repo = new $repoClass($app['storage'], $classMetadata); $repo->setLegacyService($app['storage.legacy_service']); return $repo; }); $app['storage.field_manager'] = $app->share(function ($app) { $manager = new FieldManager($app['storage.typemap'], $app['config']); foreach ($app['storage.typemap'] as $field) { if (isset($app[$field])) { $manager->setHandler($field, $app[$field]); } } return $manager; }); // This uses a class name as the field types can optionally be injected // as services but the field manager only knows the class name, so we // use this to look up if there ss a service registered $app['Bolt\\Storage\\Field\\Type\\TemplateFieldsType'] = $app->protect(function ($mapping) use($app) { $field = new TemplateFieldsType($mapping, $app['storage'], $app['templatechooser']); return $field; }); $app['storage.entity_builder'] = $app->share(function ($app) { $builder = new Builder($app['storage.metadata'], $app['storage.field_manager']); return $builder; }); $app['storage.repository.default'] = 'Bolt\\Storage\\Repository\\ContentRepository'; $app['storage.typemap'] = ['Doctrine\\DBAL\\Types\\StringType' => 'Bolt\\Storage\\Field\\Type\\TextType', 'Doctrine\\DBAL\\Types\\IntegerType' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'Doctrine\\DBAL\\Types\\FloatType' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'Doctrine\\DBAL\\Types\\TextType' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'Doctrine\\DBAL\\Types\\DateType' => 'Bolt\\Storage\\Field\\Type\\DateType', 'Doctrine\\DBAL\\Types\\DateTimeType' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'checkbox' => 'Bolt\\Storage\\Field\\Type\\CheckboxType', 'date' => 'Bolt\\Storage\\Field\\Type\\DateType', 'datetime' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'file' => 'Bolt\\Storage\\Field\\Type\\FileType', 'filelist' => 'Bolt\\Storage\\Field\\Type\\FileListType', 'float' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'geolocation' => 'Bolt\\Storage\\Field\\Type\\GeolocationType', 'hidden' => 'Bolt\\Storage\\Field\\Type\\HiddenType', 'html' => 'Bolt\\Storage\\Field\\Type\\HtmlType', 'image' => 'Bolt\\Storage\\Field\\Type\\ImageType', 'imagelist' => 'Bolt\\Storage\\Field\\Type\\ImageListType', 'incomingrelation' => 'Bolt\\Storage\\Field\\Type\\IncomingRelationType', 'integer' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'markdown' => 'Bolt\\Storage\\Field\\Type\\MarkdownType', 'relation' => 'Bolt\\Storage\\Field\\Type\\RelationType', 'repeater' => 'Bolt\\Storage\\Field\\Type\\RepeaterType', 'select' => 'Bolt\\Storage\\Field\\Type\\SelectType', 'selectmultiple' => 'Bolt\\Storage\\Field\\Type\\SelectMultipleType', 'slug' => 'Bolt\\Storage\\Field\\Type\\SlugType', 'taxonomy' => 'Bolt\\Storage\\Field\\Type\\TaxonomyType', 'templatefields' => 'Bolt\\Storage\\Field\\Type\\TemplateFieldsType', 'templateselect' => 'Bolt\\Storage\\Field\\Type\\TemplateSelectType', 'text' => 'Bolt\\Storage\\Field\\Type\\TextType', 'textarea' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'video' => 'Bolt\\Storage\\Field\\Type\\VideoType']; $app['storage.repositories'] = ['Bolt\\Storage\\Entity\\Authtoken' => 'Bolt\\Storage\\Repository\\AuthtokenRepository', 'Bolt\\Storage\\Entity\\Cron' => 'Bolt\\Storage\\Repository\\CronRepository', 'Bolt\\Storage\\Entity\\FieldValue' => 'Bolt\\Storage\\Repository\\FieldValueRepository', 'Bolt\\Storage\\Entity\\LogChange' => 'Bolt\\Storage\\Repository\\LogChangeRepository', 'Bolt\\Storage\\Entity\\LogSystem' => 'Bolt\\Storage\\Repository\\LogSystemRepository', 'Bolt\\Storage\\Entity\\Users' => 'Bolt\\Storage\\Repository\\UsersRepository']; $app['storage.metadata'] = $app->share(function ($app) { $meta = new MetadataDriver($app['schema'], $app['config']->get('contenttypes'), $app['config']->get('taxonomy'), $app['storage.typemap'], $app['storage.namingstrategy']); return $meta; }); $app['storage.relations_collection'] = $app->protect(function () use($app) { return new Collection\Relations([], $app['storage']); }); $app['storage.taxonomy_collection'] = $app->protect(function () use($app) { return new Collection\Taxonomy([], $app['storage.metadata']); }); $app['storage.collection_manager'] = $app->share(function ($app) { $manager = new Collection\CollectionManager(); $manager->setHandler('Bolt\\Storage\\Entity\\Relations', $app['storage.relations_collection']); $manager->setHandler('Bolt\\Storage\\Entity\\Taxonomy', $app['storage.taxonomy_collection']); return $manager; }); $app['storage.request.edit'] = $app->share(function ($app) { $cr = new ContentRequest\Edit($app['storage'], $app['config'], $app['users'], $app['filesystem'], $app['logger.system'], $app['logger.flash']); return $cr; }); $app['storage.request.listing'] = $app->share(function ($app) { $cr = new ContentRequest\Listing($app['storage'], $app['config']); return $cr; }); $app['storage.request.modify'] = $app->share(function ($app) { $cr = new ContentRequest\Modify($app['storage'], $app['users'], $app['logger.system'], $app['logger.flash']); return $cr; }); $app['storage.request.save'] = $app->share(function ($app) { $cr = new ContentRequest\Save($app['storage'], $app['config'], $app['users'], $app['logger.change'], $app['logger.system'], $app['logger.flash'], $app['url_generator.lazy']); return $cr; }); $app['storage.listener'] = $app->share(function () use($app) { return new StorageEventListener($app['storage'], $app['config'], $app['schema'], $app['url_generator.lazy'], $app['logger.flash'], $app['password_factory'], $app['access_control.hash.strength']); }); $app['storage.namingstrategy'] = $app->share(function ($app) { $strategy = new NamingStrategy($app['config']->get('general/database/prefix', null)); return $strategy; }); }
/** * Delete any save authtokens for a user. * * @param Entity\Users $user */ private function deleteAuthtokens(Entity\Users $user) { /** @var \Bolt\Storage\Repository\AuthtokenRepository $repo */ $repo = $this->em->getRepository('Bolt\\Storage\\Entity\\Authtoken'); $repo->deleteTokens($user->getUsername()); }
public function register(Application $app) { $app['storage.legacy'] = $app->share(function ($app) { return new Storage($app); }); $app['storage.legacy_service'] = $app->share(function ($app) { return new ContentLegacyService($app); }); $app['storage'] = $app->share(function ($app) { $storage = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata'], $app['logger.system']); $storage->setLegacyStorage($app['storage.legacy']); $storage->setEntityBuilder($app['storage.entity_builder']); $storage->setFieldManager($app['storage.field_manager']); foreach ($app['storage.repositories'] as $entity => $repo) { $storage->setRepository($entity, $repo); } $storage->setDefaultRepositoryFactory($app['storage.content_repository']); return $storage; }); $app['storage.content_repository'] = $app->protect(function ($classMetadata) use($app) { $repoClass = $app['storage.repository.default']; $repo = new $repoClass($app['storage'], $classMetadata); $repo->setLegacyService($app['storage.legacy_service']); return $repo; }); $app['storage.field_manager'] = $app->share(function ($app) { $manager = new FieldManager(); foreach ($app['storage.typemap'] as $field) { if (isset($app[$field])) { $manager->setHandler($field, $app[$field]); } } return $manager; }); $app['Bolt\\Storage\\Field\\Type\\TemplateFieldsType'] = $app->protect(function ($mapping) use($app) { $field = new TemplateFieldsType($mapping, $app['storage'], $app['templatechooser']); return $field; }); $app['storage.entity_builder'] = $app->share(function ($app) { $builder = new Builder($app['storage.metadata'], $app['storage.field_manager']); return $builder; }); $app['storage.repository.default'] = 'Bolt\\Storage\\Repository\\ContentRepository'; $app['storage.typemap'] = ['Doctrine\\DBAL\\Types\\StringType' => 'Bolt\\Storage\\Field\\Type\\TextType', 'Doctrine\\DBAL\\Types\\IntegerType' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'Doctrine\\DBAL\\Types\\FloatType' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'Doctrine\\DBAL\\Types\\TextType' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'Doctrine\\DBAL\\Types\\DateType' => 'Bolt\\Storage\\Field\\Type\\DateType', 'Doctrine\\DBAL\\Types\\DateTimeType' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'checkbox' => 'Bolt\\Storage\\Field\\Type\\CheckboxType', 'date' => 'Bolt\\Storage\\Field\\Type\\DateType', 'datetime' => 'Bolt\\Storage\\Field\\Type\\DateTimeType', 'file' => 'Bolt\\Storage\\Field\\Type\\FileType', 'filelist' => 'Bolt\\Storage\\Field\\Type\\FileListType', 'float' => 'Bolt\\Storage\\Field\\Type\\FloatType', 'geolocation' => 'Bolt\\Storage\\Field\\Type\\GeolocationType', 'hidden' => 'Bolt\\Storage\\Field\\Type\\HiddenType', 'html' => 'Bolt\\Storage\\Field\\Type\\HtmlType', 'image' => 'Bolt\\Storage\\Field\\Type\\ImageType', 'imagelist' => 'Bolt\\Storage\\Field\\Type\\ImageListType', 'integer' => 'Bolt\\Storage\\Field\\Type\\IntegerType', 'markdown' => 'Bolt\\Storage\\Field\\Type\\MarkdownType', 'relation' => 'Bolt\\Storage\\Field\\Type\\RelationType', 'repeater' => 'Bolt\\Storage\\Field\\Type\\RepeaterType', 'select' => 'Bolt\\Storage\\Field\\Type\\SelectType', 'selectmultiple' => 'Bolt\\Storage\\Field\\Type\\SelectMultipleType', 'slug' => 'Bolt\\Storage\\Field\\Type\\SlugType', 'taxonomy' => 'Bolt\\Storage\\Field\\Type\\TaxonomyType', 'templatefields' => 'Bolt\\Storage\\Field\\Type\\TemplateFieldsType', 'templateselect' => 'Bolt\\Storage\\Field\\Type\\TemplateSelectType', 'text' => 'Bolt\\Storage\\Field\\Type\\TextType', 'textarea' => 'Bolt\\Storage\\Field\\Type\\TextAreaType', 'video' => 'Bolt\\Storage\\Field\\Type\\VideoType']; $app['storage.repositories'] = ['Bolt\\Storage\\Entity\\Authtoken' => 'Bolt\\Storage\\Repository\\AuthtokenRepository', 'Bolt\\Storage\\Entity\\Cron' => 'Bolt\\Storage\\Repository\\CronRepository', 'Bolt\\Storage\\Entity\\LogChange' => 'Bolt\\Storage\\Repository\\LogChangeRepository', 'Bolt\\Storage\\Entity\\LogSystem' => 'Bolt\\Storage\\Repository\\LogSystemRepository', 'Bolt\\Storage\\Entity\\Users' => 'Bolt\\Storage\\Repository\\UsersRepository']; $app['storage.metadata'] = $app->share(function ($app) { $meta = new MetadataDriver($app['schema'], $app['config']->get('contenttypes'), $app['config']->get('taxonomy'), $app['storage.typemap'], $app['storage.namingstrategy']); return $meta; }); $app['storage.record_modifier'] = $app->share(function ($app) { $cm = new RecordModifier($app); return $cm; }); $app['storage.listener'] = $app->share(function () use($app) { return new StorageEventListener($app['storage'], $app['access_control.hash.strength']); }); $app['storage.namingstrategy'] = $app->share(function ($app) { $strategy = new NamingStrategy($app['config']->get('general/database/prefix', null)); return $strategy; }); }
/** * @depends testInsert */ public function testDelete() { $app = $this->getApp(); $entityName = 'Bolt\\Storage\\Entity\\Users'; $this->runListenCount($app, 'preDelete'); $this->runListenCount($app, 'postDelete'); $em = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata']); $repo = $em->getRepository($entityName); $existing = $repo->findOneBy(['displayname' => 'Test User']); $result = $repo->delete($existing); $confirm = $repo->findOneBy(['displayname' => 'Test User']); $this->assertFalse($confirm); $this->assertEquals(1, $this->eventCount['preDelete']); $this->assertEquals(1, $this->eventCount['postDelete']); }