Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkvanzanten committed Jun 21, 2019
1 parent 8ac1fbb commit b8739c9
Show file tree
Hide file tree
Showing 377 changed files with 39,560 additions and 4,485 deletions.
8 changes: 5 additions & 3 deletions composer.json
Expand Up @@ -38,14 +38,16 @@
"ext-exif": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-gd": "*"
"ext-gd": "*",
"webonyx/graphql-php": "^0.13.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.25"
},
"suggest": {
"paragonie/random_compat": "Generates cryptographically more secure pseudo-random bytes",
"league/flysystem-aws-s3-v3": "Enables the usage of Amazon S3 adapter for storage"
"league/flysystem-aws-s3-v3": "Enables the usage of Amazon S3 adapter for storage",
"aliyuncs/aliyun-oss-flysystem": "Enables the usage of Aliyun OSS adapter for storage"
},
"autoload": {
"psr-4": {
Expand All @@ -60,4 +62,4 @@
"src/helpers/all.php"
]
}
}
}
13 changes: 13 additions & 0 deletions config/api_sample.php
Expand Up @@ -41,10 +41,17 @@
// ],
// 'pool' => [
// 'adapter' => 'memcached',
// //'url' => 'localhost:11211;localhost:11212'
// 'host' => 'localhost',
// 'port' => 11211
// ],
// 'pool' => [
// 'adapter' => 'memcache',
// 'url' => 'localhost:11211;localhost:11212'
// //'host' => 'localhost',
// //'port' => 11211
//],
// 'pool' => [
// 'adapter' => 'redis',
// 'host' => 'localhost',
// 'port' => 6379
Expand Down Expand Up @@ -72,6 +79,12 @@
// 'options' => ['ACL' => 'public-read', 'Cache-Control' => 'max-age=604800']
// Set custom S3 endpoint
// 'endpoint' => 's3-endpoint',
// 'OSS_ACCESS_ID' => 'aliyun-oss-id',
// 'OSS_ACCESS_KEY' => 'aliyun-oss-key',
// 'OSS_ENDPOINT' => 'aliyun-oss-endpoint',
// 'OSS_BUCKET' => 'aliyun-oss-bucket'
// Use an internal proxy for downloading all files
//'proxy_downloads' => false,
],

'mail' => [
Expand Down
19 changes: 8 additions & 11 deletions migrations/db/seeds/CollectionPresetsSeeder.php
Expand Up @@ -18,21 +18,18 @@ public function run()
[
'collection' => 'directus_activity',
'view_type' => 'tabular',
'view_type' => 'timeline',
'view_query' => json_encode([
'tabular' => [
'sort' => '-action_on',
'fields' => 'action,action_by,action_on,collection,item'
'timeline' => [
'sort' => '-action_on'
]
]),
'view_options' => json_encode([
'tabular' => [
'widths' => [
'action' => 170,
'action_by' => 170,
'action_on' => 180,
'collection' => 200,
'item' => 200
]
'timeline' => [
'date' => 'action_on',
'title' => '{{ action_by.first_name }} {{ action_by.last_name }} ({{ action }})',
'content' => 'action_by',
'color' => 'action'
]
])
],
Expand Down
31 changes: 31 additions & 0 deletions migrations/upgrades/schemas/20190520094300_use_timeline.php
@@ -0,0 +1,31 @@
<?php

use Phinx\Migration\AbstractMigration;

class UseTimeline extends AbstractMigration
{
public function up()
{
$this->execute(\Directus\phinx_update(
$this->getAdapter(),
'directus_collection_presets',
[
'view_type' => 'timeline',
'view_query' => json_encode([
'timeline' => [
'sort' => '-action_on'
]
]),
'view_options' => json_encode([
'timeline' => [
'date' => 'action_on',
'title' => '{{ action_by.first_name }} {{ action_by.last_name }} ({{ action }})',
'content' => 'action_by',
'color' => 'action'
]
])
],
['collection' => 'directus_activity']
));
}
}
2 changes: 2 additions & 0 deletions public/downloads/.htaccess
@@ -0,0 +1,2 @@
RewriteEngine On
RewriteRule (.*) index.php [L]
94 changes: 94 additions & 0 deletions public/downloads/index.php
@@ -0,0 +1,94 @@
<?php

require __DIR__ . '/../../vendor/autoload.php';

use Directus\Util\ArrayUtils;
use Directus\Filesystem\Thumbnailer;

$basePath = realpath(__DIR__ . '/../../');
// Get Project name
$projectName = \Directus\get_api_project_from_request();

try {
$app = \Directus\create_app_with_project_name($basePath, $projectName);
} catch (\Exception $e) {
http_response_code(404);
header('Content-Type: application/json');
echo json_encode([
'error' => [
'error' => 8,
'message' => 'API Project Configuration Not Found: ' . $projectName
]
]);
exit;
}

$filesystem = $app->getContainer()->get('filesystem')->getAdapter();

//Remove the project name from the URL
$path = urldecode(\Directus\get_virtual_path());
if (substr($path, 0, strlen($projectName)) == $projectName) {
$path = substr($path, strlen($projectName));
}

$settings = \Directus\get_directus_proxy_downloads_settings();
$timeToLive = \Directus\array_get($settings, 'proxy_downloads_cache_ttl', 86400);
try {

//Forward HTTP headers
$metadata = $filesystem->getMetadata($path);

header('HTTP/1.1 200 OK');
if (array_key_exists('mimetype', $metadata)) {
header('Content-type: ' . $metadata['mimetype']);
} else {
$mimetype = $filesystem->getMimetype($path);
if ($mimetype) {
header('Content-type: ' . $mimetype);
}
}
if (array_key_exists('size', $metadata)) {
header('Content-Length: ' . $metadata['size']);
} else {
$size = $filesystem->getSize($path);
if ($size) {
header('Content-Length: ' . $size);
}
}
header("Pragma: cache");
header('Cache-Control: max-age=' . $timeToLive);
header('Last-Modified: '. gmdate('D, d M Y H:i:s \G\M\T', time()));
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + $timeToLive));

//Forward HTTP body
$resource = $filesystem->readStream($path);
ob_end_flush();
fpassthru($resource);
exit(0);
}

catch (Exception $e) {
$filePath = ArrayUtils::get($settings, 'proxy_downloads_not_found_location');
if (is_string($filePath) && !empty($filePath) && $filePath[0] !== '/') {
$filePath = $basePath . '/' . $filePath;
}

// TODO: Throw message if the error is a invalid configuration
if (file_exists($filePath)) {
$mime = mime_content_type($filePath);

// TODO: Do we need to cache non-existing files?
if ($mime) {
header('Content-type: ' . $mime);
}
header("Pragma: cache");
header('Cache-Control: max-age=' . $timeToLive);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', time()));
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $timeToLive));
echo file_get_contents($filePath);
} else {
http_response_code(404);
}

exit(0);
}
6 changes: 5 additions & 1 deletion public/thumbnail/index.php
Expand Up @@ -26,12 +26,16 @@
$settings = \Directus\get_directus_thumbnail_settings();
$timeToLive = \Directus\array_get($settings, 'thumbnail_cache_ttl', 86400);
try {

parse_str($_SERVER['QUERY_STRING'], $queryParams);

// if the thumb already exists, return it
$thumbnailer = new Thumbnailer(
$app->getContainer()->get('filesystem'),
$app->getContainer()->get('filesystem_thumb'),
$settings,
urldecode(\Directus\get_virtual_path())
urldecode(\Directus\get_virtual_path()),
$queryParams
);

$image = $thumbnailer->get();
Expand Down
2 changes: 1 addition & 1 deletion src/core/Directus/Application/Application.php
Expand Up @@ -13,7 +13,7 @@ class Application extends App
*
* @var string
*/
const DIRECTUS_VERSION = '2.1.0';
const DIRECTUS_VERSION = '2.2.0';

/**
* NOT USED
Expand Down
59 changes: 37 additions & 22 deletions src/core/Directus/Application/CoreServicesProvider.php
Expand Up @@ -7,6 +7,7 @@
use Cache\Adapter\Common\PhpCachePool;
use Cache\Adapter\Filesystem\FilesystemCachePool;
use Cache\Adapter\Memcached\MemcachedCachePool;
use Cache\Adapter\Memcache\MemcacheCachePool;
use Cache\Adapter\PHPArray\ArrayCachePool;
use Cache\Adapter\Redis\RedisCachePool;
use Cache\Adapter\Void\VoidCachePool;
Expand Down Expand Up @@ -356,8 +357,8 @@ protected function getEmitter()

return $payload;
});
$addFilesUrl = function ($rows) {
return \Directus\append_storage_information($rows);
$addFilesUrl = function ($rows, $params = []) {
return \Directus\append_storage_information($rows, $params);
};
$emitter->addFilter('item.read.directus_files:before', function (Payload $payload) {
$columns = $payload->get('columns');
Expand Down Expand Up @@ -445,7 +446,7 @@ protected function getEmitter()

if ($decode === true) {
$value = is_string($value) ? json_decode($value) : $value;
} else if ($value !== null) {
} elseif ($value !== null) {
$value = !is_string($value) ? json_encode($value) : $value;
}

Expand Down Expand Up @@ -524,7 +525,8 @@ protected function getEmitter()
// -------------------------------------------------------------------------------------------
// Add file url and thumb url
$emitter->addFilter('item.read.directus_files', function (Payload $payload) use ($addFilesUrl, $container) {
$rows = $addFilesUrl($payload->getData());

$rows = $addFilesUrl($payload->getData(), $payload->attribute('params'));

$payload->replace($rows);

Expand Down Expand Up @@ -629,18 +631,18 @@ protected function getEmitter()
}

$payload->set($key, $dateTimeValue);
} else if (DataTypes::isDateType($type)) {
} elseif (DataTypes::isDateType($type)) {
$dateTime = new DateTimeUtils($value);
$payload->set($key, $dateTime->toString(DateTimeUtils::DEFAULT_DATE_FORMAT));
} else if (DataTypes::isTimeType($type)) {
} elseif (DataTypes::isTimeType($type)) {
$dateTime = new DateTimeUtils($value);
$payload->set($key, $dateTime->toString(DateTimeUtils::DEFAULT_TIME_FORMAT));
}
}

return $payload;
};

$generateExternalId = function (Payload $payload) {
// generate an external id if none is passed
if (!$payload->get('external_id')) {
Expand Down Expand Up @@ -891,8 +893,8 @@ protected function getCache()
if (is_object($poolConfig) && $poolConfig instanceof PhpCachePool) {
$pool = $poolConfig;
} else {
if (!in_array($poolConfig['adapter'], ['apc', 'apcu', 'array', 'filesystem', 'memcached', 'redis', 'void'])) {
throw new \Exception("Valid cache adapters are 'apc', 'apcu', 'filesystem', 'memcached', 'redis'");
if (!in_array($poolConfig['adapter'], ['apc', 'apcu', 'array', 'filesystem', 'memcached', 'memcache', 'redis', 'void'])) {
throw new \Exception("Valid cache adapters are 'apc', 'apcu', 'filesystem', 'memcached', 'memcache', 'redis'");
}

$pool = new VoidCachePool();
Expand Down Expand Up @@ -928,13 +930,27 @@ protected function getCache()
$pool = new FilesystemCachePool($filesystem);
}

if ($adapter == 'memcached') {
$host = (isset($poolConfig['host'])) ? $poolConfig['host'] : 'localhost';
$port = (isset($poolConfig['port'])) ? $poolConfig['port'] : 11211;
if ($adapter == 'memcached' || $adapter == 'memcache') {
$client = $adapter == 'memcached' ? new \Memcached() : new \Memcache();
if (isset($poolConfig['url'])) {
$urls = explode(';', $poolConfig['url']);
if ($urls === false) {
$urls = 'localhost:11211';
}
foreach ($urls as $url) {
$parts = parse_url($url);
$host = (isset($parts['host'])) ? $parts['host'] : 'localhost';
$port = (isset($parts['port'])) ? $parts['port'] : 11211;

$client = new \Memcached();
$client->addServer($host, $port);
$pool = new MemcachedCachePool($client);
$client->addServer($host, $port);
}
} else {
$host = (isset($poolConfig['host'])) ? $poolConfig['host'] : 'localhost';
$port = (isset($poolConfig['port'])) ? $poolConfig['port'] : 11211;

$client->addServer($host, $port);
}
$pool = $adapter == 'memcached' ? new MemcachedCachePool($client) : new MemcacheCachePool($client);
}

if ($adapter == 'redis') {
Expand Down Expand Up @@ -963,12 +979,12 @@ protected function getSchemaAdapter()
switch ($databaseName) {
case 'MySQL':
return new \Directus\Database\Schema\Sources\MySQLSchema($adapter);
// case 'SQLServer':
// return new SQLServerSchema($adapter);
// case 'SQLite':
// return new \Directus\Database\Schemas\Sources\SQLiteSchema($adapter);
// case 'PostgreSQL':
// return new PostgresSchema($adapter);
// case 'SQLServer':
// return new SQLServerSchema($adapter);
// case 'SQLite':
// return new \Directus\Database\Schemas\Sources\SQLiteSchema($adapter);
// case 'PostgreSQL':
// return new PostgresSchema($adapter);
}

throw new \Exception('Unknown/Unsupported database: ' . $databaseName);
Expand Down Expand Up @@ -1281,4 +1297,3 @@ protected function getStorageConfiguration(Container $container)
return $storageConfig;
}
}

0 comments on commit b8739c9

Please sign in to comment.