Skip to content

Commit

Permalink
Merge pull request #70 from oat-sa/release-0.6.0
Browse files Browse the repository at this point in the history
Release 0.6.0
  • Loading branch information
Jérôme Bogaerts authored Feb 3, 2017
2 parents 01fc826 + b106164 commit 54e5d44
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 39 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'label' => 'extension-tao-mediamanager',
'description' => 'TAO media manager extension',
'license' => 'GPL-2.0',
'version' => '0.5.2',
'version' => '0.6.0',
'author' => 'Open Assessment Technologies SA',
'requires' => array(
'tao' => '>=3.0.0',
Expand Down
2 changes: 1 addition & 1 deletion model/FileImportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function initElements()
$dataLang = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang'.$dataLang;
if(!is_null($this->instanceUri)){
$instance = new \core_kernel_classes_Resource($this->instanceUri);
$lang = $instance->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE));
$lang = $instance->getOnePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LANGUAGE));
if($lang instanceof \core_kernel_classes_Resource){
$dataLang = $lang->getUri();
}
Expand Down
30 changes: 20 additions & 10 deletions model/MediaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ class MediaService extends \tao_models_classes_ClassService
{
const ROOT_CLASS_URI = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#Media';

const PROPERTY_LINK = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#Link';
const PROPERTY_LANGUAGE = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#Language';
const PROPERTY_ALT_TEXT = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#AltText';
const PROPERTY_MD5 = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#md5';
const PROPERTY_MIME_TYPE = 'http://www.tao.lu/Ontologies/TAOMedia.rdf#mimeType';

/**
* (non-PHPdoc)
* @see tao_models_classes_ClassService::getRootClass()
*/
public function getRootClass()
{
return new \core_kernel_classes_Class(self::ROOT_CLASS_URI);
return $this->getClass(self::ROOT_CLASS_URI);
}


Expand Down Expand Up @@ -69,11 +79,11 @@ public function createMediaInstance($fileSource, $classUri, $language, $label =
$mimeType = is_null($mimeType) ? \tao_helpers_File::getMimeType($fileSource) : $mimeType;
$instance = $clazz->createInstanceWithProperties(array(
RDFS_LABEL => $label,
MEDIA_LINK => $link,
MEDIA_LANGUAGE => $language,
MEDIA_MD5 => $md5,
MEDIA_MIME_TYPE => $mimeType,
MEDIA_ALT_TEXT => $label
self::PROPERTY_LINK => $link,
self::PROPERTY_LANGUAGE => $language,
self::PROPERTY_MD5 => $md5,
self::PROPERTY_MIME_TYPE => $mimeType,
self::PROPERTY_ALT_TEXT => $label
));

if (common_ext_ExtensionsManager::singleton()->isEnabled('taoRevision')) {
Expand Down Expand Up @@ -106,9 +116,9 @@ public function editMediaInstance($fileTmp, $instanceUri, $language)
$md5 = md5_file($fileTmp);
/** @var $instance \core_kernel_classes_Resource */
if (!is_null($instance) && $instance instanceof \core_kernel_classes_Resource) {
$instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LINK), $link);
$instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_LANGUAGE), $language);
$instance->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MD5), $md5);
$instance->editPropertyValues($this->getProperty(self::PROPERTY_LINK), $link);
$instance->editPropertyValues($this->getProperty(self::PROPERTY_LANGUAGE), $language);
$instance->editPropertyValues($this->getProperty(self::PROPERTY_MD5), $md5);
}

if (common_ext_ExtensionsManager::singleton()->isEnabled('taoRevision')) {
Expand Down Expand Up @@ -139,7 +149,7 @@ public function deleteResource(\core_kernel_classes_Resource $resource)
*/
protected function getLink(\core_kernel_classes_Resource $resource)
{
$instance = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$instance = $resource->getUniquePropertyValue($this->getProperty(self::PROPERTY_LINK));
return $instance instanceof \core_kernel_classes_Resource ? $instance->getUri() : (string)$instance;
}
}
10 changes: 5 additions & 5 deletions model/MediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ public function getFileInfo($link)
// get the media link from the resource
$resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link));
if ($resource->exists()) {
$fileLink = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$fileLink = $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
$fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string)$fileLink;
$file = null;
$fileManagement = FileManager::getFileManagementModel();
$mime = (string) $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE));
$mime = (string) $resource->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE));

// add the alt text to file array
$altArray = $resource->getPropertyValues(new \core_kernel_classes_Property(MEDIA_ALT_TEXT));
$altArray = $resource->getPropertyValues(new \core_kernel_classes_Property(MediaService::PROPERTY_ALT_TEXT));
$alt = $resource->getLabel();
if (count($altArray) > 0) {
$alt = $altArray[0];
Expand Down Expand Up @@ -168,7 +168,7 @@ public function getFileInfo($link)
public function getFileStream($link)
{
$resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link));
$fileLink = $resource->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$fileLink = $resource->getOnePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
if (is_null($fileLink)) {
throw new \tao_models_classes_FileNotFoundException($link);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public function getBaseName($link)
public function forceMimeType($link, $mimeType)
{
$resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link));
return $resource->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
return $resource->editPropertyValues(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), $mimeType);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions model/SharedStimulusPackageImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace oat\taoMediaManager\model;

use core_kernel_classes_Class;
use Jig\Utils\FsUtils;
use qtism\data\storage\xml\XmlDocument;
use tao_helpers_form_Form;

Expand Down Expand Up @@ -229,7 +228,7 @@ protected static function secureEncode($basedir, $source)
// relative path
if (\tao_helpers_File::securityCheck($source, false)) {
if (file_exists($basedir . $source)) {
return 'data:' . FsUtils::getMimeType($basedir . $source) . ';'
return 'data:' . \tao_helpers_File::getMimeType($basedir . $source) . ';'
. 'base64,' . base64_encode(file_get_contents($basedir . $source));
} else {
throw new \tao_models_classes_FileNotFoundException($source);
Expand Down
2 changes: 1 addition & 1 deletion model/ZipExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function createZipFile($filename, $exportClasses = array(), $exportFiles

foreach ($files as $file) {
//add each file in the correct directory
$link = $file->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$link = $file->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
if ($link instanceof \core_kernel_classes_Literal) {
$link = $link->literal;
}
Expand Down
2 changes: 1 addition & 1 deletion model/fileManagement/FlySystemManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function storeFile($filePath, $label)
$filesystem = $this->getFileSystem();
$filename = $this->getUniqueFilename(basename($filePath));

$stream = fopen($filePath, 'r+');
$stream = fopen($filePath, 'r');
$filesystem->writeStream($filename, $stream);
fclose($stream);

Expand Down
68 changes: 68 additions & 0 deletions scripts/ImportMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2017 (original work) Open Assessment Technologies SA;
*
*
*/
namespace oat\taoMediaManager\scripts;

use oat\oatbox\action\Action;
use common_report_Report as Report;
use oat\taoMediaManager\model\MediaService;

/**
* Class ImportMedia
*
* Used to import media from the command line
*
* ```
* sudo -u www-data php index.php 'oat\taoMediaManager\scripts\ImportMedia' big_bad_video.mp4 'http://sample/mediaclass.rdf#i1464967192451980'
* ```
*/
class ImportMedia implements Action
{

/**
* @param $params
* @return Report
*/
public function __invoke($params)
{
if (count($params) < 1) {
return new Report(Report::TYPE_ERROR, __('Usage: ImportMedia MEDIA_FILE [DESTINATION_CLASS]'));
};

\common_ext_ExtensionsManager::singleton()->getExtensionById('taoMediaManager');

$file = array_shift($params);
$destinationClassUri = count($params) > 0
? array_shift($params)
: MediaService::ROOT_CLASS_URI;

$service = MediaService::singleton();
$uri = $service->createMediaInstance($file, $destinationClassUri, DEFAULT_LANG, basename($file));
if ($uri !== false) {
$report = new Report(Report::TYPE_SUCCESS, __('Media imported'));
$report->setData($uri);
} else {
$report = new Report(Report::TYPE_ERROR, __('Unable to import'));
}

return $report;
}

}
2 changes: 1 addition & 1 deletion scripts/install/setMediaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$serviceManager = ServiceManager::getServiceManager();
$fsService = $serviceManager->get(FileSystemService::SERVICE_ID);
$fsService->createLocalFileSystem('mediaManager');
$fsService->createFileSystem('mediaManager');
$serviceManager->register(FileSystemService::SERVICE_ID, $fsService);

$flySystemManagement = new FlySystemManagement(array(FlySystemManagement::OPTION_FS => 'mediaManager'));
Expand Down
14 changes: 7 additions & 7 deletions scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function update($initialVersion)
$itemContent = preg_replace_callback('/src="mediamanager\/([^"]+)"/', function ($matches) {
$mediaClass = MediaService::singleton()->getRootClass();
$medias = $mediaClass->searchInstances(array(
MEDIA_LINK => $matches[1]
MediaService::PROPERTY_LINK => $matches[1]
), array('recursive' => true));
$media = array_pop($medias);
$uri = '';
Expand Down Expand Up @@ -179,12 +179,12 @@ public function update($initialVersion)
$mediaClass = MediaService::singleton()->getRootClass();
$fileManager = FileManager::getFileManagementModel();
foreach($mediaClass->getInstances(true) as $media){
$fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
$fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string)$fileLink;
$filePath = $fileManager->retrieveFile($fileLink);
$mimeType = \tao_helpers_File::getMimeType($filePath);
$mimeType = ($mimeType === 'application/xhtml+xml') ? 'application/qti+xml' : $mimeType;
$media->setPropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
$media->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), $mimeType);
}
$currentVersion = '0.2.5';
}
Expand All @@ -193,20 +193,20 @@ public function update($initialVersion)
$fileManager = FileManager::getFileManagementModel();
$iterator = new \core_kernel_classes_ResourceIterator(array(MediaService::singleton()->getRootClass()));
foreach ($iterator as $media) {
$fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
$fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string)$fileLink;
$filePath = $fileManager->retrieveFile($fileLink);
try {
SharedStimulusImporter::isValidSharedStimulus($filePath);
$media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), 'application/qti+xml');
$media->editPropertyValues(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), 'application/qti+xml');
} catch (\Exception $e) {
$mimeType = \tao_helpers_File::getMimeType($filePath);
$media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
$media->editPropertyValues(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), $mimeType);
}
}
$currentVersion = '0.3.0';
}

$this->skip('0.3.0','0.5.2');
$this->skip('0.3.0','0.6.0');
}
}
5 changes: 3 additions & 2 deletions test/model/MediaManagerBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace oat\taoMediaManager\test\model;

use oat\taoMediaManager\model\MediaSource;
use oat\taoMediaManager\model\MediaService;


class MediaManagerBrowserTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -129,8 +130,8 @@ public function testGetFileInfo()

$root = new \core_kernel_classes_Class($this->rootClass);
$instance = $root->createInstance('Brazil.png');
$instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_LINK), 'myGreatLink');
$instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), 'image/png');
$instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK), 'myGreatLink');
$instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_MIME_TYPE), 'image/png');

$uri = $instance->getUri();
$this->fileManagerMock->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion test/model/MediaManagerManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testAdd()
$filePath = dirname(__DIR__) . '/sample/Italy.png';

$instance = $rootClass->createInstance();
$instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_LINK), 'myGreatLink');
$instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK), 'myGreatLink');
$returnedLink = $instance->getUri();
$this->service->expects($this->once())
->method('createMediaInstance')
Expand Down
13 changes: 6 additions & 7 deletions test/model/MediaServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ public function tearDown()

public function testGetRootClass()
{
$rootClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAOMedia.rdf#Media');
$this->assertEquals(
$rootClass,
$this->mediaService->getRootClass(),
'http://www.tao.lu/Ontologies/TAOMedia.rdf#Media',
$this->mediaService->getRootClass()->getUri(),
'The root class of the service is not correct'
);
}
Expand Down Expand Up @@ -110,7 +109,7 @@ public function testCreateMediaInstance()
$instances = $root->getInstances();
/** @var \core_kernel_classes_Resource $instance */
$instance = array_pop($instances);
$thing = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
$thing = $instance->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK));
$linkResult = $thing instanceof \core_kernel_classes_Resource ? $thing->getUri() : (string)$thing;
$this->assertInstanceOf(
'\core_kernel_classes_Resource',
Expand All @@ -123,7 +122,7 @@ public function testCreateMediaInstance()
$this->assertEquals($linkResult, 'MyGreatLink', 'The returned link is wrong');
$this->assertEquals(
$lang,
$instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE)),
$instance->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LANGUAGE)),
'The instance language is wrong'
);

Expand All @@ -146,13 +145,13 @@ public function testEditMediaInstance()
$lang = 'EN-en';
$instanceUri = 'http://myFancyDomain.com/myGreatInstanceUri';
$instance = new \core_kernel_classes_Class($instanceUri);
$instance->setPropertyValue(new \core_kernel_classes_Property(MEDIA_LINK), 'MyLink');
$instance->setPropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LINK), 'MyLink');

$this->mediaService->editMediaInstance($fileTmp, $instanceUri, $lang);

$this->assertEquals(
$lang,
$instance->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE)),
$instance->getUniquePropertyValue(new \core_kernel_classes_Property(MediaService::PROPERTY_LANGUAGE)),
'The instance language is wrong'
);

Expand Down

0 comments on commit 54e5d44

Please sign in to comment.