Skip to content

Commit

Permalink
Merge pull request #784 from oat-sa/release-2.22.0
Browse files Browse the repository at this point in the history
Release 2.22.0
  • Loading branch information
llecaque committed Apr 4, 2016
2 parents d2aef89 + 17bd313 commit b682a16
Show file tree
Hide file tree
Showing 12 changed files with 475 additions and 49 deletions.
12 changes: 1 addition & 11 deletions doc/structures.dtd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Root Tag -->
<!ELEMENT structures (( structure )* , (toolbar)* ,(entrypoint)*) >
<!ELEMENT structures (( structure )*) >
<!ELEMENT structure ( (description)? , (icon)?, sections )>

<!-- The id of the structure -->
Expand Down Expand Up @@ -84,13 +84,3 @@
<!-- The JS binding of this action -->
<!ATTLIST action binding CDATA "_load">

<!-- DEPRECATED -->
<!ELEMENT toolbar ( (toolbaraction)* )>
<!-- displayed name of the section -->
<!ATTLIST toolbaraction id CDATA #REQUIRED>
<!ATTLIST toolbaraction icon CDATA #REQUIRED>
<!ATTLIST toolbaraction level CDATA #REQUIRED>
<!ATTLIST toolbaraction title CDATA #REQUIRED>
<!ATTLIST toolbaraction js CDATA #IMPLIED>
<!ATTLIST toolbaraction structure CDATA #IMPLIED>

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' => 'Tao base',
'description' => 'TAO meta-extension',
'license' => 'GPL-2.0',
'version' => '2.21.0',
'version' => '2.22.0',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => array(
'generis' => '>=2.12.0'
Expand Down
7 changes: 5 additions & 2 deletions models/classes/export/implementation/CsvExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ public function export($columnNames = false, $download = false, $delimiter = ","
$file->fputcsv($row, $delimiter, $enclosure);
}

$length = $file->ftell();
$file->rewind();
$exportData = trim($file->fread($length));
$exportData = '';
while (!$file->eof()) {
$exportData .= $file->fgets();
}
$exportData = trim($exportData);

if ($download) {
$this->download($exportData, 'export.csv');
Expand Down
64 changes: 35 additions & 29 deletions models/classes/service/class.FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/

use oat\tao\model\websource\WebsourceManager;
use oat\oatbox\service\ConfigurableService;
use oat\oatbox\service\ServiceManager;
use oat\tao\model\websource\Websource;
/**
* Represents the file storage used in services
*
Expand All @@ -28,28 +31,19 @@
* @package tao
*/
class tao_models_classes_service_FileStorage
class tao_models_classes_service_FileStorage extends ConfigurableService
{
const CONFIG_KEY = 'ServiceFileStorage';
const SERVICE_ID = 'tao/ServiceFileStorage';

/**
* @var tao_models_classes_service_FileStorage
*/
private static $instance;
const OPTION_PUBLIC_FS = 'public';
const OPTION_PRIVATE_FS = 'private';
const OPTION_ACCESS_PROVIDER = 'provider';

/**
* @return tao_models_classes_service_FileStorage
*/
public static function singleton() {
if (is_null(self::$instance)) {
$config = common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getConfig(self::CONFIG_KEY);
$privateFs = new core_kernel_fileSystem_FileSystem($config['private']);
$publicFs = new core_kernel_fileSystem_FileSystem($config['public']);
$accessProvider = WebsourceManager::singleton()->getWebsource($config['provider']);
self::$instance = new self($privateFs, $publicFs, $accessProvider);
}

return self::$instance;
return ServiceManager::getServiceManager()->get(self::SERVICE_ID);
}

/**
Expand All @@ -60,11 +54,29 @@ public static function singleton() {
private $privateFs;

private $accessProvider;

protected function getPublicFs()
{
if (is_null($this->publicFs)) {
$this->publicFs = new core_kernel_fileSystem_FileSystem($this->getOption(self::OPTION_PUBLIC_FS));
}
return $this->publicFs;
}

private function __construct(core_kernel_fileSystem_FileSystem $private, core_kernel_fileSystem_FileSystem $public, $provider) {
$this->privateFs = $private;
$this->publicFs = $public;
$this->accessProvider = $provider;
protected function getPrivateFs()
{
if (is_null($this->privateFs)) {
$this->privateFs = new core_kernel_fileSystem_FileSystem($this->getOption(self::OPTION_PRIVATE_FS));
}
return $this->privateFs;
}

protected function getAccessProvider()
{
if (is_null($this->accessProvider)) {
$this->accessProvider = WebsourceManager::singleton()->getWebsource($this->getOption(self::OPTION_ACCESS_PROVIDER));
}
return $this->accessProvider;
}

/**
Expand All @@ -84,9 +96,11 @@ public function spawnDirectory($public = false) {
*/
public function getDirectoryById($id) {
$public = $id[strlen($id)-1] == '+';
$fs = $public ? $this->publicFs : $this->privateFs;
$fs = $public ? $this->getPublicFs() : $this->getPrivateFs();
$path = $this->id2path($id);
return new tao_models_classes_service_StorageDirectory($id, $fs, $path, $public ? $this->accessProvider : null);
$dir = new tao_models_classes_service_StorageDirectory($id, $fs, $path, $public ? $this->getAccessProvider() : null);
$dir->setServiceLocator($this->getServiceLocator());
return $dir;
}

public function import($id, $directoryPath) {
Expand Down Expand Up @@ -122,12 +136,4 @@ private function id2path($id) {

return $returnValue.DIRECTORY_SEPARATOR;
}

public static function configure(core_kernel_fileSystem_FileSystem $private, core_kernel_fileSystem_FileSystem $public, $provider) {
common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->setConfig(self::CONFIG_KEY, array(
'private' => $private->getUri(),
'public' => $public->getUri(),
'provider' => $provider->getId()
));
}
}
94 changes: 91 additions & 3 deletions models/classes/service/class.StorageDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,29 @@
*
*/

use oat\oatbox\filesystem\FileSystemService;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use League\Flysystem\Filesystem;
use Psr\Http\Message\StreamInterface;

/**
* Represents direxctory for file storage
*
* @access public
* @author Joel Bout, <[email protected]>
* @package tao
*/
class tao_models_classes_service_StorageDirectory
class tao_models_classes_service_StorageDirectory implements ServiceLocatorAwareInterface
{
use ServiceLocatorAwareTrait;

private $id;

/**
*
* @var core_kernel_fileSystem_FileSystem
*/
private $fs;
private $relPath;
private $accessProvider;
Expand All @@ -42,9 +54,11 @@ public function __construct($id, $fs, $path, $provider) {
}

/**
* Returns the absolute path to this directory
* Returned the absolute path to this directory
* Please use read and write to access files
*
* @return string
* @deprecated
*/
public function getPath() {
return $this->fs->getPath().$this->relPath;
Expand Down Expand Up @@ -74,6 +88,13 @@ public function isPublic() {
return !is_null($this->accessProvider);
}

/**
* Returns a URL that allows you to access the files in a directory
* preserving the relative paths
*
* @return string
* @throws common_Exception
*/
public function getPublicAccessUrl() {
if (is_null($this->accessProvider)) {
common_Logger::e('accessss');
Expand All @@ -82,4 +103,71 @@ public function getPublicAccessUrl() {
return $this->accessProvider->getAccessUrl($this->relPath);
}

/**
* Return content of file located at $path. Output as string
*
* @param string $path
* @return StreamInterface
*/
public function read($path)
{
return $this->getFileSystem()->readStream($this->getRelativePath().$path);
}

/**
* Return content of file located at $path. Output as stream
* @param $path
* @return \Slim\Http\Stream
*/
public function readStream($path)
{
$resource = $this->read($path);
return new \GuzzleHttp\Psr7\Stream($resource);
}

/**
* Store a file in the directory from resource
*
* @param string $path
* @param mixed $resource
* @return boolean
*/
public function write($path, $resource)
{
common_Logger::d('Writting in ' . $this->getRelativePath().$path);
return $this->getFileSystem()->writeStream($this->getRelativePath().$path, $resource);
}

/**
* Store a file in the directory from stream
*
* @param $path
* @param StreamInterface $stream
* @return bool
* @throws common_Exception
*/
public function writeStream($path, StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new common_Exception('Stream is not readable. Write to filesystem aborted.');
}
if (!$stream->isSeekable()) {
throw new common_Exception('Stream is not seekable. Write to filesystem aborted.');
}
$stream->rewind();

$resource = GuzzleHttp\Psr7\StreamWrapper::getResource($stream);
if (!is_resource($resource)) {
throw new common_Exception('Unable to create resource from the given stream. Write to filesystem aborted.');
}

return $this->write($path, $resource);
}

/**
* @return Filesystem
*/
protected function getFileSystem() {
return $this->getServiceLocator()->get(FileSystemService::SERVICE_ID)->getFileSystem($this->fs->getUri());
}
}
2 changes: 1 addition & 1 deletion models/classes/websource/WebsourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getWebsource($key) {
$ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
$conf = $ext->getConfig(self::CONFIG_PREFIX.$key);
if (!is_array($conf) || !isset($conf['className'])) {
throw new WebsourceNotFound('Undefined websource '.$key);
throw new WebsourceNotFound('Undefined websource "'.$key.'"');
}
$className = $conf['className'];
$options = isset($conf['options']) ? $conf['options'] : array();
Expand Down
10 changes: 8 additions & 2 deletions scripts/install/setupServiceFileStorage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
use oat\tao\model\websource\TokenWebSource;
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -21,6 +20,8 @@
*
*/

use oat\tao\model\websource\TokenWebSource;
use oat\oatbox\service\ServiceManager;
/*
* This post-installation script creates a new local file source for file uploaded
* by end-users through the TAO GUI.
Expand All @@ -41,4 +42,9 @@

$websource = TokenWebSource::spawnWebsource($publicFs);

tao_models_classes_service_FileStorage::configure($privateFs, $publicFs, $websource);
$service = new tao_models_classes_service_FileStorage(array(
tao_models_classes_service_FileStorage::OPTION_PUBLIC_FS => $publicFs->getUri(),
tao_models_classes_service_FileStorage::OPTION_PRIVATE_FS => $privateFs->getUri(),
tao_models_classes_service_FileStorage::OPTION_ACCESS_PROVIDER => $websource->getId()
));
ServiceManager::getServiceManager()->register(tao_models_classes_service_FileStorage::SERVICE_ID, $service);
8 changes: 8 additions & 0 deletions scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,14 @@ public function update($initialVersion) {

$this->skip('2.19.0', '2.21.0');

if ($this->isVersion('2.21.0')) {
$config = common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getConfig('ServiceFileStorage');
$service = new \tao_models_classes_service_FileStorage($config);
$this->getServiceManager()->register(\tao_models_classes_service_FileStorage::SERVICE_ID, $service);
$this->setVersion('2.22.0');
}


}

private function migrateFsAccess() {
Expand Down
Loading

0 comments on commit b682a16

Please sign in to comment.