Skip to content

Commit

Permalink
Internal: Allow to create/write/delete a file needed to query between…
Browse files Browse the repository at this point in the history
… migrations chamilo#5088
  • Loading branch information
AngelFQC committed Mar 29, 2024
1 parent 95cd8ea commit 8d660ba
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/CoreBundle/Migrations/AbstractMigrationChamilo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
use DateTimeZone;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\ORM\EntityManager;
use ReflectionClass;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\UploadedFile;

abstract class AbstractMigrationChamilo extends AbstractMigration implements ContainerAwareInterface
Expand Down Expand Up @@ -358,4 +360,34 @@ public function findSession(int $id): ?Session

return $this->getEntityManager()->find(Session::class, $id);
}

private function generateFilePath(string $filename): string
{
$cacheDir = $this->getContainer()->get('kernel')->getCacheDir();

return $cacheDir.'/migration_'.$filename;
}

protected function writeFile(string $filename, string $content): void
{
$fullFilename = $this->generateFilePath($filename);

$fs = new Filesystem();
$fs->dumpFile($fullFilename, $content);
}

protected function readFile(string $filename): string
{
$fullFilename = $this->generateFilePath($filename);

return file_get_contents($fullFilename);
}

protected function removeFile(string $filename): string
{
$fullFilename = $this->generateFilePath($filename);

$fs = new Filesystem();
$fs->remove($fullFilename);
}
}

0 comments on commit 8d660ba

Please sign in to comment.