Added worker to rebuild media thumbnails
authorAlexander Ebert <ebert@woltlab.com>
Fri, 9 Jun 2017 10:13:43 +0000 (12:13 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 9 Jun 2017 10:13:59 +0000 (12:13 +0200)
See #2298

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/data/media/MediaAction.class.php
wcfsetup/install/files/lib/system/worker/MediaRebuildDataWorker.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 0f466bdca47bc63740fc3224c6e601bbc38ffd3e..bf8c891891051af56826797409bf106633d89b9b 100644 (file)
                        <classname>wcf\system\worker\AttachmentRebuildDataWorker</classname>
                        <nicevalue>100</nicevalue>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.media</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname>wcf\system\worker\MediaRebuildDataWorker</classname>
+                       <nicevalue>105</nicevalue>
+               </type>
                <type>
                        <name>com.woltlab.wcf.statDaily</name>
                        <definitionname>com.woltlab.wcf.rebuildData</definitionname>
index c1be63eab5388714e265b65cbbc7e8ad18056ff2..ac53c452f052d7b799c924c4bbabacff5b9401c8 100644 (file)
@@ -117,6 +117,23 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction,
                return $result;
        }
        
+       /**
+        * Generates thumbnails.
+        */
+       public function generateThumbnails() {
+               if (empty($this->objects)) {
+                       $this->readObjects();
+               }
+               
+               $saveStrategy = new DefaultUploadFileSaveStrategy(self::class);
+               
+               foreach ($this->getObjects() as $mediaEditor) {
+                       if ($mediaEditor->getDecoratedObject()->isImage) {
+                               $saveStrategy->generateThumbnails($mediaEditor->getDecoratedObject());
+                       }
+               }
+       }
+       
        /**
         * Returns the data of the media file to be returned by AJAX requests.
         * 
diff --git a/wcfsetup/install/files/lib/system/worker/MediaRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/MediaRebuildDataWorker.class.php
new file mode 100644 (file)
index 0000000..54d2c7a
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+namespace wcf\system\worker;
+use wcf\data\media\MediaAction;
+use wcf\data\media\MediaList;
+use wcf\system\exception\SystemException;
+
+/**
+ * Worker implementation for updating media thumbnails.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Worker
+ * 
+ * @method     MediaList       getObjectList()
+ */
+class MediaRebuildDataWorker extends AbstractRebuildDataWorker {
+       /**
+        * @inheritDoc
+        */
+       protected $objectListClassName = MediaList::class;
+       
+       /**
+        * @inheritDoc
+        */
+       protected $limit = 10;
+       
+       /**
+        * @inheritDoc
+        */
+       protected function initObjectList() {
+               parent::initObjectList();
+               
+               $this->objectList->sqlOrderBy = 'media.mediaID';
+               $this->objectList->getConditionBuilder()->add('media.isImage = ?', [1]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function execute() {
+               parent::execute();
+               
+               foreach ($this->objectList as $media) {
+                       try {
+                               (new MediaAction([$media], 'generateThumbnails'))->executeAction();
+                       }
+                       catch (SystemException $e) {}
+               }
+       }
+}
index 329a9dc433e1d46ce38a468f8d888ee03d16f715..8e2dfbcc1de9ff62a5f3295de44d4b08ff7ff36c 100644 (file)
@@ -1539,6 +1539,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.like.user.description"><![CDATA[Aktualisiert die Liste der Like-Benutzer]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment"><![CDATA[Dateianhänge aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Erzeugt Vorschaubilder neu]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.media"><![CDATA[Medien aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.media.description"><![CDATA[Erzeugt Vorschaubilder neu]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[Statistiken aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[Erzeugt die täglichen Statistiken neu]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll"><![CDATA[Umfragen aktualisieren]]></item>
index f3d604f3545f1bd826fe37df1143e00691e0835f..f615c559754c0198c2166681864690b588ef5ac8 100644 (file)
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.like.user.description"><![CDATA[Rebuilds the users using the Likes System.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment"><![CDATA[Rebuild Attachments]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Rebuilds the attachment preview images.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.media"><![CDATA[Rebuild Media]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.media.description"><![CDATA[Rebuilds the media preview images.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[Rebuild Statistics]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[Rebuilds the daily statistics.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll"><![CDATA[Rebuild Polls]]></item>