Skip to content

Commit

Permalink
Clear FileMap on EntityManager::clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Warxcell committed Feb 23, 2021
1 parent c4a630c commit f3ea858
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
9 changes: 9 additions & 0 deletions DelegatingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ public function getClass(): string
{
return $this->manager->getClass();
}

public function clear(): void
{
$this->manager->clear();

foreach ($this->managers as $manager) {
$manager->clear();
}
}
}
7 changes: 7 additions & 0 deletions EventListener/DoctrineORMListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Arxy\FilesBundle\Model\File;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\OnClearEventArgs;

class DoctrineORMListener implements EventSubscriber
{
Expand All @@ -23,6 +24,7 @@ public function getSubscribedEvents()
return [
'postPersist',
'preRemove',
'onClear',
];
}

Expand All @@ -45,4 +47,9 @@ public function preRemove(LifecycleEventArgs $args)
$this->manager->remove($entity);
}
}

public function onClear(OnClearEventArgs $args)
{
$this->manager->clear();
}
}
11 changes: 8 additions & 3 deletions Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function readStream(File $file)
}
}

private function fileSize(File $file)
private function fileSize(File $file): int
{
$pathname = $this->getPathname($file);

Expand All @@ -164,7 +164,7 @@ private function fileSize(File $file)
}
}

private function md5Hash(File $file)
private function md5Hash(File $file): string
{
$pathname = $this->getPathname($file);

Expand All @@ -175,7 +175,7 @@ private function md5Hash(File $file)
}
}

private function mimeType(File $file)
private function mimeType(File $file): string
{
if ($this->fileMap->has($file)) {
return $this->getMimeTypeByFile($this->fileMap->get($file));
Expand Down Expand Up @@ -212,4 +212,9 @@ public function getClass(): string
{
return $this->class;
}

public function clear(): void
{
$this->fileMap = new FileMap();
}
}
2 changes: 2 additions & 0 deletions ManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public function moveFile(File $file): void;
public function remove(File $file): void;

public function getClass(): string;

public function clear(): void;
}
5 changes: 5 additions & 0 deletions PathResolverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public function getPath(File $file): string
{
return $this->pathResolver->getPath($file);
}

public function clear(): void
{
$this->manager->clear();
}
}

0 comments on commit f3ea858

Please sign in to comment.