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

Commit b8739c9

Browse files
committed
v2.2.0
1 parent 8ac1fbb commit b8739c9

File tree

377 files changed

+39560
-4485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

377 files changed

+39560
-4485
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@
3838
"ext-exif": "*",
3939
"ext-mbstring": "*",
4040
"ext-openssl": "*",
41-
"ext-gd": "*"
41+
"ext-gd": "*",
42+
"webonyx/graphql-php": "^0.13.0"
4243
},
4344
"require-dev": {
4445
"phpunit/phpunit": "^5.7.25"
4546
},
4647
"suggest": {
4748
"paragonie/random_compat": "Generates cryptographically more secure pseudo-random bytes",
48-
"league/flysystem-aws-s3-v3": "Enables the usage of Amazon S3 adapter for storage"
49+
"league/flysystem-aws-s3-v3": "Enables the usage of Amazon S3 adapter for storage",
50+
"aliyuncs/aliyun-oss-flysystem": "Enables the usage of Aliyun OSS adapter for storage"
4951
},
5052
"autoload": {
5153
"psr-4": {
@@ -60,4 +62,4 @@
6062
"src/helpers/all.php"
6163
]
6264
}
63-
}
65+
}

config/api_sample.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@
4141
// ],
4242
// 'pool' => [
4343
// 'adapter' => 'memcached',
44+
// //'url' => 'localhost:11211;localhost:11212'
4445
// 'host' => 'localhost',
4546
// 'port' => 11211
4647
// ],
4748
// 'pool' => [
49+
// 'adapter' => 'memcache',
50+
// 'url' => 'localhost:11211;localhost:11212'
51+
// //'host' => 'localhost',
52+
// //'port' => 11211
53+
//],
54+
// 'pool' => [
4855
// 'adapter' => 'redis',
4956
// 'host' => 'localhost',
5057
// 'port' => 6379
@@ -72,6 +79,12 @@
7279
// 'options' => ['ACL' => 'public-read', 'Cache-Control' => 'max-age=604800']
7380
// Set custom S3 endpoint
7481
// 'endpoint' => 's3-endpoint',
82+
// 'OSS_ACCESS_ID' => 'aliyun-oss-id',
83+
// 'OSS_ACCESS_KEY' => 'aliyun-oss-key',
84+
// 'OSS_ENDPOINT' => 'aliyun-oss-endpoint',
85+
// 'OSS_BUCKET' => 'aliyun-oss-bucket'
86+
// Use an internal proxy for downloading all files
87+
//'proxy_downloads' => false,
7588
],
7689

7790
'mail' => [

migrations/db/seeds/CollectionPresetsSeeder.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ public function run()
1818
[
1919
'collection' => 'directus_activity',
2020
'view_type' => 'tabular',
21+
'view_type' => 'timeline',
2122
'view_query' => json_encode([
22-
'tabular' => [
23-
'sort' => '-action_on',
24-
'fields' => 'action,action_by,action_on,collection,item'
23+
'timeline' => [
24+
'sort' => '-action_on'
2525
]
2626
]),
2727
'view_options' => json_encode([
28-
'tabular' => [
29-
'widths' => [
30-
'action' => 170,
31-
'action_by' => 170,
32-
'action_on' => 180,
33-
'collection' => 200,
34-
'item' => 200
35-
]
28+
'timeline' => [
29+
'date' => 'action_on',
30+
'title' => '{{ action_by.first_name }} {{ action_by.last_name }} ({{ action }})',
31+
'content' => 'action_by',
32+
'color' => 'action'
3633
]
3734
])
3835
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Phinx\Migration\AbstractMigration;
4+
5+
class UseTimeline extends AbstractMigration
6+
{
7+
public function up()
8+
{
9+
$this->execute(\Directus\phinx_update(
10+
$this->getAdapter(),
11+
'directus_collection_presets',
12+
[
13+
'view_type' => 'timeline',
14+
'view_query' => json_encode([
15+
'timeline' => [
16+
'sort' => '-action_on'
17+
]
18+
]),
19+
'view_options' => json_encode([
20+
'timeline' => [
21+
'date' => 'action_on',
22+
'title' => '{{ action_by.first_name }} {{ action_by.last_name }} ({{ action }})',
23+
'content' => 'action_by',
24+
'color' => 'action'
25+
]
26+
])
27+
],
28+
['collection' => 'directus_activity']
29+
));
30+
}
31+
}

public/downloads/.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RewriteEngine On
2+
RewriteRule (.*) index.php [L]

public/downloads/index.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
require __DIR__ . '/../../vendor/autoload.php';
4+
5+
use Directus\Util\ArrayUtils;
6+
use Directus\Filesystem\Thumbnailer;
7+
8+
$basePath = realpath(__DIR__ . '/../../');
9+
// Get Project name
10+
$projectName = \Directus\get_api_project_from_request();
11+
12+
try {
13+
$app = \Directus\create_app_with_project_name($basePath, $projectName);
14+
} catch (\Exception $e) {
15+
http_response_code(404);
16+
header('Content-Type: application/json');
17+
echo json_encode([
18+
'error' => [
19+
'error' => 8,
20+
'message' => 'API Project Configuration Not Found: ' . $projectName
21+
]
22+
]);
23+
exit;
24+
}
25+
26+
$filesystem = $app->getContainer()->get('filesystem')->getAdapter();
27+
28+
//Remove the project name from the URL
29+
$path = urldecode(\Directus\get_virtual_path());
30+
if (substr($path, 0, strlen($projectName)) == $projectName) {
31+
$path = substr($path, strlen($projectName));
32+
}
33+
34+
$settings = \Directus\get_directus_proxy_downloads_settings();
35+
$timeToLive = \Directus\array_get($settings, 'proxy_downloads_cache_ttl', 86400);
36+
try {
37+
38+
//Forward HTTP headers
39+
$metadata = $filesystem->getMetadata($path);
40+
41+
header('HTTP/1.1 200 OK');
42+
if (array_key_exists('mimetype', $metadata)) {
43+
header('Content-type: ' . $metadata['mimetype']);
44+
} else {
45+
$mimetype = $filesystem->getMimetype($path);
46+
if ($mimetype) {
47+
header('Content-type: ' . $mimetype);
48+
}
49+
}
50+
if (array_key_exists('size', $metadata)) {
51+
header('Content-Length: ' . $metadata['size']);
52+
} else {
53+
$size = $filesystem->getSize($path);
54+
if ($size) {
55+
header('Content-Length: ' . $size);
56+
}
57+
}
58+
header("Pragma: cache");
59+
header('Cache-Control: max-age=' . $timeToLive);
60+
header('Last-Modified: '. gmdate('D, d M Y H:i:s \G\M\T', time()));
61+
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + $timeToLive));
62+
63+
//Forward HTTP body
64+
$resource = $filesystem->readStream($path);
65+
ob_end_flush();
66+
fpassthru($resource);
67+
exit(0);
68+
}
69+
70+
catch (Exception $e) {
71+
$filePath = ArrayUtils::get($settings, 'proxy_downloads_not_found_location');
72+
if (is_string($filePath) && !empty($filePath) && $filePath[0] !== '/') {
73+
$filePath = $basePath . '/' . $filePath;
74+
}
75+
76+
// TODO: Throw message if the error is a invalid configuration
77+
if (file_exists($filePath)) {
78+
$mime = mime_content_type($filePath);
79+
80+
// TODO: Do we need to cache non-existing files?
81+
if ($mime) {
82+
header('Content-type: ' . $mime);
83+
}
84+
header("Pragma: cache");
85+
header('Cache-Control: max-age=' . $timeToLive);
86+
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', time()));
87+
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $timeToLive));
88+
echo file_get_contents($filePath);
89+
} else {
90+
http_response_code(404);
91+
}
92+
93+
exit(0);
94+
}

public/thumbnail/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
$settings = \Directus\get_directus_thumbnail_settings();
2727
$timeToLive = \Directus\array_get($settings, 'thumbnail_cache_ttl', 86400);
2828
try {
29+
30+
parse_str($_SERVER['QUERY_STRING'], $queryParams);
31+
2932
// if the thumb already exists, return it
3033
$thumbnailer = new Thumbnailer(
3134
$app->getContainer()->get('filesystem'),
3235
$app->getContainer()->get('filesystem_thumb'),
3336
$settings,
34-
urldecode(\Directus\get_virtual_path())
37+
urldecode(\Directus\get_virtual_path()),
38+
$queryParams
3539
);
3640

3741
$image = $thumbnailer->get();

src/core/Directus/Application/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Application extends App
1313
*
1414
* @var string
1515
*/
16-
const DIRECTUS_VERSION = '2.1.0';
16+
const DIRECTUS_VERSION = '2.2.0';
1717

1818
/**
1919
* NOT USED

src/core/Directus/Application/CoreServicesProvider.php

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cache\Adapter\Common\PhpCachePool;
88
use Cache\Adapter\Filesystem\FilesystemCachePool;
99
use Cache\Adapter\Memcached\MemcachedCachePool;
10+
use Cache\Adapter\Memcache\MemcacheCachePool;
1011
use Cache\Adapter\PHPArray\ArrayCachePool;
1112
use Cache\Adapter\Redis\RedisCachePool;
1213
use Cache\Adapter\Void\VoidCachePool;
@@ -356,8 +357,8 @@ protected function getEmitter()
356357

357358
return $payload;
358359
});
359-
$addFilesUrl = function ($rows) {
360-
return \Directus\append_storage_information($rows);
360+
$addFilesUrl = function ($rows, $params = []) {
361+
return \Directus\append_storage_information($rows, $params);
361362
};
362363
$emitter->addFilter('item.read.directus_files:before', function (Payload $payload) {
363364
$columns = $payload->get('columns');
@@ -445,7 +446,7 @@ protected function getEmitter()
445446

446447
if ($decode === true) {
447448
$value = is_string($value) ? json_decode($value) : $value;
448-
} else if ($value !== null) {
449+
} elseif ($value !== null) {
449450
$value = !is_string($value) ? json_encode($value) : $value;
450451
}
451452

@@ -524,7 +525,8 @@ protected function getEmitter()
524525
// -------------------------------------------------------------------------------------------
525526
// Add file url and thumb url
526527
$emitter->addFilter('item.read.directus_files', function (Payload $payload) use ($addFilesUrl, $container) {
527-
$rows = $addFilesUrl($payload->getData());
528+
529+
$rows = $addFilesUrl($payload->getData(), $payload->attribute('params'));
528530

529531
$payload->replace($rows);
530532

@@ -629,18 +631,18 @@ protected function getEmitter()
629631
}
630632

631633
$payload->set($key, $dateTimeValue);
632-
} else if (DataTypes::isDateType($type)) {
634+
} elseif (DataTypes::isDateType($type)) {
633635
$dateTime = new DateTimeUtils($value);
634636
$payload->set($key, $dateTime->toString(DateTimeUtils::DEFAULT_DATE_FORMAT));
635-
} else if (DataTypes::isTimeType($type)) {
637+
} elseif (DataTypes::isTimeType($type)) {
636638
$dateTime = new DateTimeUtils($value);
637639
$payload->set($key, $dateTime->toString(DateTimeUtils::DEFAULT_TIME_FORMAT));
638640
}
639641
}
640642

641643
return $payload;
642644
};
643-
645+
644646
$generateExternalId = function (Payload $payload) {
645647
// generate an external id if none is passed
646648
if (!$payload->get('external_id')) {
@@ -891,8 +893,8 @@ protected function getCache()
891893
if (is_object($poolConfig) && $poolConfig instanceof PhpCachePool) {
892894
$pool = $poolConfig;
893895
} else {
894-
if (!in_array($poolConfig['adapter'], ['apc', 'apcu', 'array', 'filesystem', 'memcached', 'redis', 'void'])) {
895-
throw new \Exception("Valid cache adapters are 'apc', 'apcu', 'filesystem', 'memcached', 'redis'");
896+
if (!in_array($poolConfig['adapter'], ['apc', 'apcu', 'array', 'filesystem', 'memcached', 'memcache', 'redis', 'void'])) {
897+
throw new \Exception("Valid cache adapters are 'apc', 'apcu', 'filesystem', 'memcached', 'memcache', 'redis'");
896898
}
897899

898900
$pool = new VoidCachePool();
@@ -928,13 +930,27 @@ protected function getCache()
928930
$pool = new FilesystemCachePool($filesystem);
929931
}
930932

931-
if ($adapter == 'memcached') {
932-
$host = (isset($poolConfig['host'])) ? $poolConfig['host'] : 'localhost';
933-
$port = (isset($poolConfig['port'])) ? $poolConfig['port'] : 11211;
933+
if ($adapter == 'memcached' || $adapter == 'memcache') {
934+
$client = $adapter == 'memcached' ? new \Memcached() : new \Memcache();
935+
if (isset($poolConfig['url'])) {
936+
$urls = explode(';', $poolConfig['url']);
937+
if ($urls === false) {
938+
$urls = 'localhost:11211';
939+
}
940+
foreach ($urls as $url) {
941+
$parts = parse_url($url);
942+
$host = (isset($parts['host'])) ? $parts['host'] : 'localhost';
943+
$port = (isset($parts['port'])) ? $parts['port'] : 11211;
934944

935-
$client = new \Memcached();
936-
$client->addServer($host, $port);
937-
$pool = new MemcachedCachePool($client);
945+
$client->addServer($host, $port);
946+
}
947+
} else {
948+
$host = (isset($poolConfig['host'])) ? $poolConfig['host'] : 'localhost';
949+
$port = (isset($poolConfig['port'])) ? $poolConfig['port'] : 11211;
950+
951+
$client->addServer($host, $port);
952+
}
953+
$pool = $adapter == 'memcached' ? new MemcachedCachePool($client) : new MemcacheCachePool($client);
938954
}
939955

940956
if ($adapter == 'redis') {
@@ -963,12 +979,12 @@ protected function getSchemaAdapter()
963979
switch ($databaseName) {
964980
case 'MySQL':
965981
return new \Directus\Database\Schema\Sources\MySQLSchema($adapter);
966-
// case 'SQLServer':
967-
// return new SQLServerSchema($adapter);
968-
// case 'SQLite':
969-
// return new \Directus\Database\Schemas\Sources\SQLiteSchema($adapter);
970-
// case 'PostgreSQL':
971-
// return new PostgresSchema($adapter);
982+
// case 'SQLServer':
983+
// return new SQLServerSchema($adapter);
984+
// case 'SQLite':
985+
// return new \Directus\Database\Schemas\Sources\SQLiteSchema($adapter);
986+
// case 'PostgreSQL':
987+
// return new PostgresSchema($adapter);
972988
}
973989

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

0 commit comments

Comments
 (0)