Skip to content

Commit

Permalink
Merge pull request #157 from wimvds/master
Browse files Browse the repository at this point in the history
Folder tree & client requests
  • Loading branch information
Wim Vandersmissen committed Aug 14, 2014
2 parents 0781410 + 7f1d93b commit f86e1c7
Show file tree
Hide file tree
Showing 66 changed files with 2,548 additions and 795 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:


before_script:
- sudo apt-get install -qq imagemagick ghostscript
- composer selfupdate
- composer --prefer-source install

Expand Down
2 changes: 1 addition & 1 deletion AdminList/ItemAction/MediaDeleteItemAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MediaDeleteItemAction implements ItemActionInterface
/**
* @param string $redirectUrl
*/
function __construct($redirectUrl)
public function __construct($redirectUrl)
{
$this->redirectUrl = $redirectUrl;
}
Expand Down
24 changes: 11 additions & 13 deletions AdminList/MediaAdminListConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ class MediaAdminListConfigurator extends AbstractDoctrineORMAdminListConfigurato

/**
* @param EntityManager $em The entity manager
* @param AclHelper $aclHelper The acl helper
* @param MediaManager $mediaManager The media manager
* @param Folder $folder The current folder
* @param Request $request The request object
*/
public function __construct(
EntityManager $em,
AclHelper $aclHelper = null,
MediaManager $mediaManager,
Folder $folder,
Request $request
EntityManager $em,
MediaManager $mediaManager,
Folder $folder,
Request $request
) {
parent::__construct($em, $aclHelper);
parent::__construct($em);

$this->setAdminType(new MediaType($mediaManager, $em));
$this->folder = $folder;
Expand Down Expand Up @@ -168,26 +166,26 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder)
switch ($type) {
case 'file':
$queryBuilder->andWhere('b.location = :location')
->setParameter('location', 'local');
->setParameter('location', 'local');
break;
case 'image':
$queryBuilder->andWhere('b.contentType LIKE :ctype')
->setParameter('ctype', '%image%');
->setParameter('ctype', '%image%');
break;
case RemoteAudioHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteAudioHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteAudioHandler::CONTENT_TYPE);
break;
case RemoteSlideHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteSlideHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteSlideHandler::CONTENT_TYPE);
break;
case RemoteVideoHandler::TYPE:
$queryBuilder->andWhere('b.contentType = :ctype')
->setParameter('ctype', RemoteVideoHandler::CONTENT_TYPE);
->setParameter('ctype', RemoteVideoHandler::CONTENT_TYPE);
break;
}
}
}
}
}
}
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

### dev (2014-08-13)

* The originalFilename property has been added to Media, to store the original filename (so the name property can
be used to add a meaningful name for use in the backend)
* The Folder entity has been converted to a nested tree for performance reasons.
* A command 'kuma:media:rebuild-folder-tree' was added to (re)build the folder tree.
* Preview images for PDF documents will be created when you upload them (if you have PDF support
44 changes: 44 additions & 0 deletions Command/CreatePdfPreviewCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Kunstmaan\MediaBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CreatePdfPreviewCommand extends ContainerAwareCommand
{

protected function configure()
{
parent::configure();

$this
->setName('kuma:media:create-pdf-previews')
->setDescription('Create preview images for PDFs that have already been uploaded')
->setHelp(
"The <info>kuma:media:create-pdf-previews</info> command can be used to create preview images for PDFs that have already been uploaded."
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Creating PDF preview images...');

$pdfTransformer = $this->getContainer()->get('kunstmaan_media.pdf_transformer');
$webPath = realpath($this->getContainer()->get('kernel')->getRootDir() . '/../web') . DIRECTORY_SEPARATOR;

/**
* @var EntityManager
*/
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$medias = $em->getRepository('KunstmaanMediaBundle:Media')->findBy(
array('contentType' => 'application/pdf', 'deleted' => false)
);
/** @var Media $media */
foreach ($medias as $media) {
$pdfTransformer->apply($webPath . $media->getUrl());
}
$output->writeln('<info>PDF preview images have been created.</info>');
}
}
58 changes: 58 additions & 0 deletions Command/MigrateNameCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Kunstmaan\MediaBundle\Command;

use Doctrine\ORM\EntityManager;
use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Repository\FolderRepository;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MigrateNameCommand extends ContainerAwareCommand
{
/** @var EntityManager $em */
protected $em;

protected function configure()
{
parent::configure();

$this
->setName('kuma:media:migrate-name')
->setDescription('Migrate media name to new column.')
->setHelp(
"The <info>kuma:media:migrate-name</info> command can be used to migrate the media name to the newly added column."
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Migrating media name...');
/**
* @var EntityManager
*/
$em = $this->getContainer()->get('doctrine.orm.entity_manager');

$medias = $em->getRepository('KunstmaanMediaBundle:Media')->findAll();
$updates = 0;
try {
$em->beginTransaction();
/** @var Media $media */
foreach ($medias as $media) {
$filename = $media->getOriginalFilename();
if (empty($filename)) {
$media->setOriginalFilename($media->getName());
$em->persist($media);
$updates++;
}
}
$em->flush();
$em->commit();
} catch (\Exception $e) {
$em->rollback();
$output->writeln('An error occured while migrating media name : <error>' . $e->getMessage() . '</error>');
}
$output->writeln('<info>' . $updates . ' media files have been migrated.</info>');
}
}
32 changes: 32 additions & 0 deletions Command/RebuildFolderTreeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Kunstmaan\MediaBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RebuildFolderTreeCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();

$this->setName('kuma:media:rebuild-folder-tree')
->setDescription('Rebuild the media folder tree.')
->setHelp("The <info>kuma:media:rebuild-folder-tree</info> will loop over all media folders and update the media folder tree.");
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$em->getRepository('KunstmaanMediaBundle:Folder')->rebuildTree();
$output->writeln('Updated all folders');
}
}
15 changes: 7 additions & 8 deletions Controller/AviaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Kunstmaan\MediaBundle\Controller;


use Kunstmaan\MediaBundle\Entity\Folder;
use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Helper\MediaManager;
Expand All @@ -12,7 +11,7 @@
use Symfony\Component\HttpFoundation\Request;

/**
* controllerclass which Aviary can use to upload the edited image and add it to the database
* Controller class which Aviary can use to upload the edited image and add it to the database
*/
class AviaryController extends Controller
{
Expand All @@ -35,18 +34,18 @@ public function indexAction(Request $request, $folderId, $mediaId)
$media = $em->getRepository('KunstmaanMediaBundle:Media')->getMedia($mediaId);
/* @var MediaManager $mediaManager */
$mediaManager = $this->get('kunstmaan_media.media_manager');

$handler = $mediaManager->getHandler($media);
$fileHelper = $handler->getFormHelper($media);
$fileHelper->getMediaFromUrl($request->get('url'));
$media = $fileHelper->getMedia();

$em->persist($media);
$em->flush();

return new RedirectResponse($this->generateUrl(
'KunstmaanMediaBundle_folder_show',
array('folderId' => $folder->getId())
));
return new RedirectResponse(
$this->generateUrl(
'KunstmaanMediaBundle_folder_show',
array('folderId' => $folder->getId())
)
);
}
}
49 changes: 24 additions & 25 deletions Controller/ChooserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kunstmaan\MediaBundle\AdminList\MediaAdminListConfigurator;
use Kunstmaan\MediaBundle\Entity\Folder;
use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Helper\Media\AbstractMediaHandler;
use Kunstmaan\MediaBundle\Helper\MediaManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
Expand All @@ -28,18 +29,18 @@ class ChooserController extends Controller
*/
public function chooserIndexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$em = $this->getDoctrine()->getManager();
$session = $request->getSession();
$folderId = false;

$type = $request->get('type');
$cKEditorFuncNum = $request->get('CKEditorFuncNum');
$linkChooser = $request->get('linkChooser');
$folderId = false;

// Go to the last visited folder
if ($session->get('last-media-folder')) {
try {
$folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($session->get('last-media-folder'));
$em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($session->get('last-media-folder'));
$folderId = $session->get('last-media-folder');
} catch (EntityNotFoundException $e) {
$folderId = false;
Expand All @@ -54,10 +55,10 @@ public function chooserIndexAction(Request $request)
}

$params = array(
'folderId' => $folderId,
'type' => $type,
'CKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser
'folderId' => $folderId,
'type' => $type,
'CKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser
);

return $this->redirect($this->generateUrl('KunstmaanMediaBundle_chooser_show_folder', $params));
Expand Down Expand Up @@ -97,9 +98,8 @@ public function chooserShowFolderAction(Request $request, $folderId)

/* @var Folder $folder */
$folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
/* @var array $mediaHandler */
$folders = $em->getRepository('KunstmaanMediaBundle:Folder')->getAllFolders();

/** @var AbstractMediaHandler $handler */
$handler = null;
if ($type) {
$handler = $mediaHandler->getHandlerForType($type);
Expand All @@ -108,7 +108,7 @@ public function chooserShowFolderAction(Request $request, $folderId)
/* @var MediaManager $mediaManager */
$mediaManager = $this->get('kunstmaan_media.media_manager');

$adminListConfigurator = new MediaAdminListConfigurator($em, null, $mediaManager, $folder, $request);
$adminListConfigurator = new MediaAdminListConfigurator($em, $mediaManager, $folder, $request);
$adminList = $this->get('kunstmaan_adminlist.factory')->createList($adminListConfigurator);
$adminList->bindRequest($request);

Expand All @@ -125,19 +125,19 @@ public function chooserShowFolderAction(Request $request, $folderId)
}

return array(
'cKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser,
'linkChooserLink' => $linkChooserLink,
'mediamanager' => $mediaHandler,
'handler' => $handler,
'type' => $type,
'folder' => $folder,
'folders' => $folders,
'adminlist' => $adminList,
'fileform' => $this->createTypeFormView($mediaHandler, "file"),
'videoform' => $this->createTypeFormView($mediaHandler, "video"),
'slideform' => $this->createTypeFormView($mediaHandler, "slide"),
'audioform' => $this->createTypeFormView($mediaHandler, "audio")
'cKEditorFuncNum' => $cKEditorFuncNum,
'linkChooser' => $linkChooser,
'linkChooserLink' => $linkChooserLink,
'mediamanager' => $mediaHandler,
'foldermanager' => $this->get('kunstmaan_media.folder_manager'),
'handler' => $handler,
'type' => $type,
'folder' => $folder,
'adminlist' => $adminList,
'fileform' => $this->createTypeFormView($mediaHandler, 'file'),
'videoform' => $this->createTypeFormView($mediaHandler, 'video'),
'slideform' => $this->createTypeFormView($mediaHandler, 'slide'),
'audioform' => $this->createTypeFormView($mediaHandler, 'audio')
);
}

Expand All @@ -155,5 +155,4 @@ private function createTypeFormView(MediaManager $mediaManager, $type)

return $this->createForm($handler->getFormType(), $helper)->createView();
}

}
Loading

0 comments on commit f86e1c7

Please sign in to comment.