Skip to content

Instantly share code, notes, and snippets.

@jeroendesloovere
Created April 11, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroendesloovere/0acd229cf6255b4fd4fbca89701affa1 to your computer and use it in GitHub Desktop.
Save jeroendesloovere/0acd229cf6255b4fd4fbca89701affa1 to your computer and use it in GitHub Desktop.
MediaLibraryImporter module

MediaLibraryImporter

/**

  • Creating */

// Creating the media group $createMediaGroupCommand = new CreateMediaGroupCommand(Type::image());

// Handle the MediaGroup create $this->get('command_bus')->handle($createMediaGroupCommand); $vehicle->setMediaGroup($createMediaGroupCommand->getMediaGroup());

/**

  • Updating */

// Updating the media group $updateMediaGroupCommand = new UpdateMediaGroupCommand($vehicle->getMediaGroup());

// Handle the MediaGroup update $this->get('command_bus')->handle($updateMediaGroupCommand);

// WERKWIJZE // We voorzien een extra tabel, die moet bijhouden wat er gebeurd met de media. // Nadien wordt alle media uitgevoerd.

class MediaItemImport { /** * @var string * * @ORM\Id() * @ORM\GeneratedValue(strategy="UUID") * @ORM\Column(type="guid") */ protected $id;

/** @var Status */
protected $status;

/** @var Method */
protected $method;

/** @var string */
protected $path;

/** @var MediaItem|null */
protected $mediaItem;

/** @var \DateTime */
protected $createdOn;

}

class Method { const COPY = 'copy'; const DOWNLOAD = 'download'; const MOVE = 'move'; const POSSIBLE_VALUES = [ self::COPY, self::DOWNLOAD, self::MOVE ]; }

class SaveMediaItemImportHandler { public function __construct public function handle(SaveMediaItemImport $saveMediaItemImport) { $mediaItemImport = MediaItemImport::fromDataTransferObject($saveMediaItemImport); $this->mediaItemImportRepository->add($mediaItemImport); $saveMediaItemImport->setMediaItemImport($mediaItemImport); } }

class Importingxxx { public function execute() { // Get all items from database - which we need to import (including the ones that failed previously - BUT we need to check if there are still needed, or if they are old) // Loop all items and create a command for every

}

}

$move = true;

$mediaToImport = $this->get('media_library.helper.import')->getMediaToImportHelper();

foreach ($vehicle->getImages() as $image) { $imagesToImport[] = n }

$images = [ new ImportMediaGroup($path, $move); ];

$mediaGroup = $this->get('media_library.helper.import')->createMediaGroup($images);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment