~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Controller/Library.php

  • Committer: Dan Garner
  • Date: 2016-06-28 15:02:11 UTC
  • mto: This revision was merged to the branch mainline in revision 528.
  • Revision ID: git-v1:51031805c36c1d366fa330b2c2320d1927c57003
Fixes for upgrade steps

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
use Xibo\Exception\ConfigurationException;
28
28
use Xibo\Exception\LibraryFullException;
29
29
use Xibo\Factory\DataSetFactory;
30
 
use Xibo\Factory\DisplayFactory;
31
30
use Xibo\Factory\DisplayGroupFactory;
32
31
use Xibo\Factory\LayoutFactory;
33
32
use Xibo\Factory\MediaFactory;
35
34
use Xibo\Factory\PermissionFactory;
36
35
use Xibo\Factory\PlaylistFactory;
37
36
use Xibo\Factory\RegionFactory;
38
 
use Xibo\Factory\ScheduleFactory;
39
37
use Xibo\Factory\TagFactory;
40
38
use Xibo\Factory\UserFactory;
41
39
use Xibo\Factory\UserGroupFactory;
116
114
    /** @var  DataSetFactory */
117
115
    private $dataSetFactory;
118
116
 
119
 
    /** @var  DisplayFactory */
120
 
    private $displayFactory;
121
 
 
122
 
    /** @var ScheduleFactory  */
123
 
    private $scheduleFactory;
124
 
 
125
117
    /**
126
118
     * Set common dependencies.
127
119
     * @param LogServiceInterface $log
145
137
     * @param DisplayGroupFactory $displayGroupFactory
146
138
     * @param RegionFactory $regionFactory
147
139
     * @param DataSetFactory $dataSetFactory
148
 
     * @param DisplayFactory $displayFactory
149
 
     * @param ScheduleFactory $scheduleFactory
150
140
     */
151
 
    public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $store, $pool, $userFactory, $moduleFactory, $tagFactory, $mediaFactory, $widgetFactory, $permissionFactory, $layoutFactory, $playlistFactory, $userGroupFactory, $displayGroupFactory, $regionFactory, $dataSetFactory, $displayFactory, $scheduleFactory)
 
141
    public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $store, $pool, $userFactory, $moduleFactory, $tagFactory, $mediaFactory, $widgetFactory, $permissionFactory, $layoutFactory, $playlistFactory, $userGroupFactory, $displayGroupFactory, $regionFactory, $dataSetFactory)
152
142
    {
153
143
        $this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
154
144
 
166
156
        $this->displayGroupFactory = $displayGroupFactory;
167
157
        $this->regionFactory = $regionFactory;
168
158
        $this->dataSetFactory = $dataSetFactory;
169
 
        $this->displayFactory = $displayFactory;
170
 
        $this->scheduleFactory = $scheduleFactory;
171
159
    }
172
160
 
173
161
    /**
260
248
    }
261
249
 
262
250
    /**
263
 
     * @return DisplayFactory
264
 
     */
265
 
    public function getDisplayFactory()
266
 
    {
267
 
        return $this->displayFactory;
268
 
    }
269
 
 
270
 
    /**
271
 
     * @return ScheduleFactory
272
 
     */
273
 
    public function getScheduleFactory()
274
 
    {
275
 
        return $this->scheduleFactory;
276
 
    }
277
 
 
278
 
    /**
279
251
     * Displays the page logic
280
252
     */
281
253
    function displayPage()
284
256
        $this->getState()->template = 'library-page';
285
257
        $this->getState()->setData([
286
258
            'users' => $this->userFactory->query(),
287
 
            'modules' => $this->moduleFactory->query(['module'], ['regionSpecific' => 0, 'enabled' => 1]),
288
 
            'groups' => $this->userGroupFactory->query()
 
259
            'modules' => $this->moduleFactory->query(['module'], ['regionSpecific' => 0, 'enabled' => 1])
289
260
        ]);
290
261
    }
291
262
 
333
304
     *      type="integer",
334
305
     *      required=false
335
306
     *   ),
336
 
     *  @SWG\Parameter(
337
 
     *      name="tags",
338
 
     *      in="formData",
339
 
     *      description="Filter by Tags - comma seperated",
340
 
     *      type="string",
341
 
     *      required=false
342
 
     *   ),
343
 
     *  @SWG\Parameter(
344
 
     *      name="duration",
345
 
     *      in="formData",
346
 
     *      description="Filter by Duration - a number or less-than,greater-than,less-than-equal or great-than-equal followed by a | followed by a number",
347
 
     *      type="string",
348
 
     *      required=false
349
 
     *   ),
350
 
     *  @SWG\Parameter(
351
 
     *      name="fileSize",
352
 
     *      in="formData",
353
 
     *      description="Filter by File Size - a number or less-than,greater-than,less-than-equal or great-than-equal followed by a | followed by a number",
354
 
     *      type="string",
355
 
     *      required=false
356
 
     *   ),
357
 
     *  @SWG\Parameter(
358
 
     *      name="ownerUserGroupId",
359
 
     *      in="formData",
360
 
     *      description="Filter by users in this UserGroupId",
361
 
     *      type="integer",
362
 
     *      required=false
363
 
     *   ),
364
307
     *  @SWG\Response(
365
308
     *      response=200,
366
309
     *      description="successful operation",
382
325
            'type' => $this->getSanitizer()->getString('type'),
383
326
            'tags' => $this->getSanitizer()->getString('tags'),
384
327
            'ownerId' => $this->getSanitizer()->getInt('ownerId'),
385
 
            'retired' => $this->getSanitizer()->getInt('retired'),
386
 
            'duration' => $this->getSanitizer()->getString('duration'),
387
 
            'fileSize' => $this->getSanitizer()->getString('fileSize'),
388
 
            'ownerUserGroupId' => $this->getSanitizer()->getInt('ownerUserGroupId')
 
328
            'retired' => $this->getSanitizer()->getInt('retired')
389
329
        ]));
390
330
 
391
331
        // Add some additional row content
462
402
        if (!$this->getUser()->checkDeleteable($media))
463
403
            throw new AccessDeniedException();
464
404
 
465
 
        $media->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory, $this->displayFactory, $this->scheduleFactory);
 
405
        $media->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
466
406
        $media->load(['deleting' => true]);
467
407
 
468
408
        $this->getState()->template = 'library-form-delete';
510
450
            throw new AccessDeniedException();
511
451
 
512
452
        // Check
513
 
        $media->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory, $this->displayFactory, $this->scheduleFactory);
 
453
        $media->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
514
454
        $media->load(['deleting' => true]);
515
455
 
516
456
        if ($media->isUsed() && $this->getSanitizer()->getCheckbox('forceDelete') == 0)
579
519
        else
580
520
            $validExt = $this->moduleFactory->getValidExtensions();
581
521
 
582
 
        // Make sure there is room in the library
583
 
        $libraryLimit = $this->getConfig()->GetSetting('LIBRARY_SIZE_LIMIT_KB') * 1024;
584
 
 
585
522
        $options = array(
586
523
            'userId' => $this->getUser()->userId,
587
524
            'controller' => $this,
596
533
            'script_url' => $this->urlFor('library.add'),
597
534
            'upload_url' => $this->urlFor('library.add'),
598
535
            'image_versions' => array(),
599
 
            'accept_file_types' => '/\.' . implode('|', $validExt) . '$/i',
600
 
            'libraryLimit' => $libraryLimit,
601
 
            'libraryQuotaFull' => ($libraryLimit > 0 && $this->libraryUsage() > $libraryLimit)
 
536
            'accept_file_types' => '/\.' . implode('|', $validExt) . '$/i'
602
537
        );
603
538
 
604
 
        // Output handled by UploadHandler
 
539
        // Make sure there is room in the library
 
540
        $libraryLimit = $this->getConfig()->GetSetting('LIBRARY_SIZE_LIMIT_KB') * 1024;
 
541
 
 
542
        if ($libraryLimit > 0 && $this->libraryUsage() > $libraryLimit)
 
543
            throw new LibraryFullException(sprintf(__('Your library is full. Library Limit: %s K'), $libraryLimit));
 
544
 
 
545
        // Check for a user quota
 
546
        $this->getUser()->isQuotaFullByUser();
605
547
        $this->setNoOutput(true);
606
548
 
607
 
        $this->getLog()->debug('Hand off to Upload Handler with options: %s', json_encode($options));
608
 
 
609
 
        // Hand off to the Upload Handler provided by jquery-file-upload
610
 
        new XiboUploadHandler($options);
 
549
        try {
 
550
            $this->getLog()->debug('Hand off to Upload Handler with options: %s', json_encode($options));
 
551
            // Hand off to the Upload Handler provided by jquery-file-upload
 
552
            new XiboUploadHandler($options);
 
553
        }
 
554
        catch (\Exception $e) {
 
555
            // We must not issue an error, the file upload return should have the error object already
 
556
        }
611
557
    }
612
558
 
613
559
    /**
754
700
    /**
755
701
     * Tidies up the library
756
702
     *
757
 
     * @SWG\Delete(
 
703
     * @SWG\Post(
758
704
     *  path="/library/tidy",
759
705
     *  operationId="libraryTidy",
760
706
     *  tags={"library"},
778
724
        foreach ($media as $item) {
779
725
            /* @var Media $item */
780
726
            $i++;
781
 
            $item->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
782
727
            $item->load();
783
728
            $item->delete();
784
729
        }
983
928
 
984
929
                    // Separate out the display name and the referenced name (referenced name cannot contain any odd characters or numbers)
985
930
                    $displayName = $font->name;
986
 
                    $familyName = strtolower(preg_replace('/\s+/', ' ', preg_replace('/\d+/u', '', $font->name)));
 
931
                    $familyName = preg_replace('/\s+/', ' ', preg_replace('/\d+/u', '', $font->name));
987
932
 
988
933
                    // Css for the client contains the actual stored as location of the font.
989
934
                    $css .= str_replace('[url]', $font->storedAs, str_replace('[family]', $familyName, $fontTemplate));
1007
952
                $media = $this->mediaFactory->createModuleSystemFile('fonts.css', $tempUrl);
1008
953
                $media->expires = 0;
1009
954
                $media->moduleSystemFile = true;
1010
 
                $media->isSaveRequired = true;
 
955
                $media->force = true;
1011
956
                $media->save();
1012
957
 
1013
 
                // We can remove the temp file
1014
 
                @unlink($tempUrl);
1015
 
 
1016
958
                $cssDetails = [
1017
959
                    'css' => $localCss,
1018
960
                    'ckeditor' => $ckEditorString
1048
990
            $moduleObject = $this->moduleFactory->create($module->type);
1049
991
            $moduleObject->installFiles();
1050
992
        }
1051
 
 
1052
 
        // Dump the cache on all displays
1053
 
        foreach ($this->displayFactory->query() as $display) {
1054
 
            /** @var \Xibo\Entity\Display $display */
1055
 
            $display->notify();
1056
 
        }
1057
993
    }
1058
994
 
1059
995
    /**
1087
1023
            /* @var \Xibo\Entity\Media $entry */
1088
1024
            // If the media type is a module, then pretend its a generic file
1089
1025
            $this->getLog()->info('Removing Expired File %s', $entry->name);
1090
 
            $entry->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory, $this->displayFactory, $this->scheduleFactory);
 
1026
            $entry->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
1091
1027
            $entry->delete();
1092
1028
        }
1093
1029
    }
1121
1057
 
1122
1058
    /**
1123
1059
     * @SWG\Post(
1124
 
     *  path="/library/{mediaId}/tag",
 
1060
     *  path="/media/{mediaId}/tag",
1125
1061
     *  operationId="mediaTag",
1126
 
     *  tags={"library"},
 
1062
     *  tags={"media"},
1127
1063
     *  summary="Tag Media",
1128
1064
     *  description="Tag a Media with one or more tags",
1129
1065
     * @SWG\Parameter(
1170
1106
            $media->assignTag($this->tagFactory->tagFromString($tag));
1171
1107
        }
1172
1108
 
1173
 
        $media->save(['validate' => false]);
 
1109
        $media->save();
1174
1110
 
1175
1111
        // Return
1176
1112
        $this->getState()->hydrate([
1182
1118
 
1183
1119
    /**
1184
1120
     * @SWG\Delete(
1185
 
     *  path="/library/{mediaId}/untag",
 
1121
     *  path="/media/{mediaId}/tag",
1186
1122
     *  operationId="mediaUntag",
1187
 
     *  tags={"library"},
 
1123
     *  tags={"media"},
1188
1124
     *  summary="Untag Media",
1189
1125
     *  description="Untag a Media with one or more tags",
1190
1126
     * @SWG\Parameter(
1225
1161
        $tags = $this->getSanitizer()->getStringArray('tag');
1226
1162
 
1227
1163
        if (count($tags) <= 0)
1228
 
            throw new \InvalidArgumentException(__('No tags to unassign'));
 
1164
            throw new \InvalidArgumentException(__('No tags to assign'));
1229
1165
 
1230
1166
        foreach ($tags as $tag) {
1231
1167
            $media->unassignTag($this->tagFactory->tagFromString($tag));
1232
1168
        }
1233
1169
 
1234
 
        $media->save(['validate' => false]);
 
1170
        $media->save();
1235
1171
 
1236
1172
        // Return
1237
1173
        $this->getState()->hydrate([