-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
84 changes: 84 additions & 0 deletions
84
src/Dravencms/Gallery/Console/MigrateLinkGalleryCommand.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dravencms\Gallery\Console; | ||
|
||
use Dravencms\Gallery\Gallery; | ||
use Dravencms\Model\File\Entities\StructureFileLink; | ||
use Dravencms\Model\Gallery\Repository\GalleryRepository; | ||
use Dravencms\Model\Gallery\Repository\PictureRepository; | ||
use Kdyby\Doctrine\EntityManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class MigrateLinkGalleryCommand | ||
* @package Dravencms\Gallery\Console | ||
*/ | ||
class MigrateLinkGalleryCommand extends Command | ||
{ | ||
/** @var EntityManager */ | ||
private $entityManager; | ||
|
||
/** @var PictureRepository */ | ||
private $pictureRepository; | ||
|
||
/** | ||
* CleanGalleryCommand constructor. | ||
* @param EntityManager $entityManager | ||
* @param GalleryRepository $galleryRepository | ||
*/ | ||
public function __construct( | ||
EntityManager $entityManager, | ||
PictureRepository $pictureRepository | ||
) | ||
{ | ||
parent::__construct(null); | ||
|
||
$this->entityManager = $entityManager; | ||
$this->pictureRepository = $pictureRepository; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setName('gallery:gallery:migrate-link') | ||
->setDescription('Migrate from direct fileStructure usage to fileStructureLink'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int|null | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
try { | ||
$migrated = 0; | ||
foreach ($this->pictureRepository->getAll() AS $picture) { | ||
if ($picture->getStructureFile() && !$picture->getStructureFileLink()) { | ||
$structureFileLink = new StructureFileLink(Gallery::PLUGIN_NAME, $picture->getStructureFile(), true, true); | ||
$picture->setStructureFileLink($structureFileLink); | ||
$picture->setStructureFile(null); | ||
$this->entityManager->persist($structureFileLink); | ||
$this->entityManager->persist($picture); | ||
$migrated++; | ||
} | ||
} | ||
|
||
$this->entityManager->flush(); | ||
$output->writeLn(sprintf('%s pictures has been migrated!', $migrated)); | ||
return 0; // zero return code means everything is ok | ||
|
||
} catch (\Exception $e) { | ||
$output->writeLn('<error>' . $e->getMessage() . '</error>'); | ||
return 1; // non-zero return code means error | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Dravencms\Gallery\Console\CleanGalleryCommand | ||
- Dravencms\Gallery\Console\CleanGalleryCommand | ||
- Dravencms\Gallery\Console\MigrateLinkGalleryCommand |
This file contains 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
This file contains 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
Oops, something went wrong.