Skip to content

Commit

Permalink
Media -> Files
Browse files Browse the repository at this point in the history
  • Loading branch information
jel-massih committed Jun 12, 2014
1 parent aa9090a commit 4d187bc
Show file tree
Hide file tree
Showing 58 changed files with 345 additions and 349 deletions.
4 changes: 2 additions & 2 deletions .htaccess
Expand Up @@ -16,13 +16,13 @@ AddType font/woff .woff
RewriteRule ^listviews/([^/]+)/assets - [L,NC]
RewriteRule ^listviews/([^/]+)/ListView.js - [L,NC]

# Media Proxy
# Files Proxy
# - Only define one of the URL segments /.../ here so that the request format
# can be more flexibly maintained in the PHP/Slim router
RewriteCond %{REQUEST_URI} media_auth_proxy/([^/]+)/(.+)$
RewriteRule ^ /media_auth_proxy/index.php [L]

# Media Thumbnails
# Files Thumbnails
# - Cached thumbnail exists
#RewriteCond %{REQUEST_URI} ^/thumbnail/(.+)$
#RewriteCond %{DOCUMENT_ROOT}/images/cached/%1 -f
Expand Down
28 changes: 14 additions & 14 deletions api/api.php
Expand Up @@ -51,8 +51,8 @@
//use Directus\Db\TableGateway\RelationalTableGateway as TableGateway;
use Directus\Db\TableGateway\RelationalTableGatewayWithConditions as TableGateway;
use Directus\Db\TableSchema;
use Directus\Media;
use Directus\Media\Upload;
use Directus\Files;
use Directus\Files\Upload;
use Directus\MemcacheProvider;
use Directus\Util;
use Directus\View\JsonView;
Expand Down Expand Up @@ -631,15 +631,15 @@
});

/**
* MEDIA COLLECTION
* FILES COLLECTION
*/

$app->map("/$v/media(/:id)/?", function ($id = null) use ($app, $db, $ZendDb, $acl, $params, $requestPayload) {
$app->map("/$v/files(/:id)/?", function ($id = null) use ($app, $db, $ZendDb, $acl, $params, $requestPayload) {

if(!is_null($id))
$params['id'] = $id;

$table = "directus_media";
$table = "directus_files";
$currentUser = Auth::getUserInfo();
$TableGateway = new TableGateway($acl, $table, $ZendDb);
$activityLoggingEnabled = !(isset($_GET['skip_activity_log']) && (1 == $_GET['skip_activity_log']));
Expand All @@ -660,12 +660,12 @@
$TableGateway->manageRecordUpdate($table, $requestPayload, $activityMode);
break;
}
$db->set_media($requestPayload);
$db->set_files($requestPayload);
break;
}

$Media = new TableGateway($acl, $table, $ZendDb);
$get_new = $Media->getEntries($params);
$Files = new TableGateway($acl, $table, $ZendDb);
$get_new = $Files->getEntries($params);

if (array_key_exists('rows', $get_new)) {
foreach ($get_new['rows'] as &$row) {
Expand Down Expand Up @@ -825,8 +825,8 @@
*/

$app->post("/$v/upload/?", function () use ($db, $params, $requestPayload, $app, $acl, $ZendDb) {
// $Transfer = new Media\Transfer();
$Storage = new Media\Storage\Storage();
// $Transfer = new Files\Transfer();
$Storage = new Files\Storage\Storage();
$result = array();
foreach ($_FILES as $file) {
// $fileData = $Transfer->acceptFile($file['tmp_name'], $file['name']);
Expand All @@ -851,8 +851,8 @@
});

$app->post("/$v/upload/link/?", function () use ($db, $params, $requestPayload, $app, $acl, $ZendDb) {
// $Transfer = new Media\Transfer();
$Storage = new Media\Storage\Storage();
// $Transfer = new Files\Transfer();
$Storage = new Files\Storage\Storage();
$result = array();
if(isset($_POST['link'])) {
// $fileData = $Transfer->acceptFile($file['tmp_name'], $file['name']);
Expand Down Expand Up @@ -1005,9 +1005,9 @@
* EXCEPTION LOG
*/
$app->post("/$v/exception/?", function () use ($db, $params, $requestPayload, $app, $acl, $ZendDb) {
// $Transfer = new Media\Transfer();
// $Transfer = new Files\Transfer();

print_r($requestPayload);die();
print_r($requestPayload);die();
$data = array(
'server_addr' =>$_SERVER['SERVER_ADDR'],
'server_port' =>$_SERVER['SERVER_PORT'],
Expand Down
4 changes: 2 additions & 2 deletions api/core/Directus/Acl/Acl.php
Expand Up @@ -24,7 +24,7 @@ class Acl {
const ROW_OWNER_COLUMN = "directus_user";

public static $cms_owner_columns_by_table = array(
'directus_media' => 'user',
'directus_files' => 'user',
'directus_users' => 'id'
);

Expand All @@ -48,7 +48,7 @@ class Acl {
// value: array of column names
'*' => array('id','active'),
'directus_activity' => array('user'),
'directus_media' => array('user')
'directus_files' => array('user')
);

protected $groupPrivileges;
Expand Down
Expand Up @@ -6,7 +6,7 @@
use Directus\Bootstrap;
use Zend\Db\RowGateway\RowGateway;

class DirectusMediaRowGateway extends AclAwareRowGateway {
class DirectusFilesRowGateway extends AclAwareRowGateway {

public function preSaveDataHook(array $rowData, $rowExistsInDatabase = false)
{
Expand Down
24 changes: 12 additions & 12 deletions api/core/Directus/Db/TableGateway/AclAwareTableGateway.php
Expand Up @@ -221,25 +221,25 @@ public function addOrUpdateRecordByArray(array $recordData, $tableName = null) {
// Post-update hook
Hooks::runHook('postUpdate', array($TableGateway, $recordData, $this->adapter, $this->acl));
} else {
//If we are adding a new directus_media Item, We need to do that logic
if($tableName == "directus_media") {
$Storage = new \Directus\Media\Storage\Storage();
//If we are adding a new directus_files Item, We need to do that logic
if($tableName == "directus_files") {
$Storage = new \Directus\Files\Storage\Storage();

//If trying to save to temp, force to default
if((!isset($recordData['storage_adapter']) || $recordData['storage_adapter'] == '') || $Storage->storageAdaptersByRole['TEMP']['id'] == $recordData['storage_adapter']) {
$recordData['storage_adapter'] = $Storage->storageAdaptersByRole['DEFAULT']['id'];
}

//Save Temp Thumbnail name for use after media record save
//Save Temp Thumbnail name for use after files record save
$info = pathinfo($recordData['name']);
if( in_array($info['extension'], $this->imagickExtensions)) {
$thumbnailName = "THUMB_".$info['filename'].'.jpg';
} else {
$thumbnailName = "THUMB_".$recordData['name'];
}

//If we are using Media ID, Dont save until after insert
if($Storage->getMediaSettings()['media_file_naming'] != "media_id") {
//If we are using files ID, Dont save until after insert
if($Storage->getFilesSettings()['file_file_naming'] != "file_id") {
//Save the file in TEMP Storage Adapter to Designated StorageAdapter
$recordData['name'] = $Storage->saveFile($recordData['name'], $recordData['storage_adapter']);
}
Expand All @@ -248,18 +248,18 @@ public function addOrUpdateRecordByArray(array $recordData, $tableName = null) {
$TableGateway->insert($recordData);
$recordData['id'] = $TableGateway->getLastInsertValue();

if($tableName == "directus_media") {
if($tableName == "directus_files") {
$ext = pathinfo($recordData['name'], PATHINFO_EXTENSION);
$updateArray = array();
//If using MediaId saving, then update record and set name to id
if($Storage->getMediaSettings()['media_file_naming'] == "media_id") {
//If using file_id saving, then update record and set name to id
if($Storage->getFilesSettings()['file_file_naming'] == "file_id") {
$newName = $Storage->saveFile($recordData['name'], $recordData['storage_adapter'], str_pad($recordData['id'],11,"0", STR_PAD_LEFT).'.'.$ext);
$updateArray['name'] = str_pad($recordData['id'],11,"0", STR_PAD_LEFT).'.'.$ext;
$recordData['name'] = $updateArray['name'];
}

//If we are using media_id titles, then set title to id
if($Storage->getMediaSettings()['media_title_naming'] == "media_id") {
//If we are using file_id titles, then set title to id
if($Storage->getFilesSettings()['file_title_naming'] == "file_id") {
$updateArray['title'] = str_pad($recordData['id'],11,"0", STR_PAD_LEFT);
$recordData['title'] = $updateArray['title'];
}
Expand All @@ -271,7 +271,7 @@ public function addOrUpdateRecordByArray(array $recordData, $tableName = null) {
$TableGateway->updateWith($Update);
}

//Save Temp Thumbnail to Thumbnail SA using media id: $params['id']
//Save Temp Thumbnail to Thumbnail SA using file id: $params['id']
$tempLocation = $Storage->storageAdaptersByRole['TEMP']['destination'];
if(file_exists($tempLocation.$thumbnailName)) {
$thumbnailDestination = $Storage->storageAdaptersByRole['THUMBNAIL']['destination'];
Expand Down
Expand Up @@ -16,7 +16,7 @@ class DirectusActivityTableGateway extends RelationalTableGateway {

// Populates directus_activity.type
const TYPE_ENTRY = "ENTRY";
const TYPE_MEDIA = "MEDIA";
const TYPE_FILES = "FILES";
const TYPE_SETTINGS = "SETTINGS";
const TYPE_UI = "UI";
const TYPE_LOGIN = "LOGIN";
Expand All @@ -37,8 +37,8 @@ public static function makeLogTypeFromTableName($table) {
return self::TYPE_UI;
case 'directus_settings':
return self::TYPE_SETTINGS;
case "directus_media":
return self::TYPE_MEDIA;
case "directus_files":
return self::TYPE_FILES;
default:
return self::TYPE_ENTRY;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public function fetchFeed($params = null) {
->nest
->isNull('parent_id')
->OR
->equalTo('type', 'MEDIA')
->equalTo('type', 'FILES')
->unnest;

$select = $this->applyParamsToTableEntriesSelect($params, $select, $tableSchemaArray, $hasActiveColumn);
Expand All @@ -85,7 +85,7 @@ public function fetchFeed($params = null) {
$countTotalWhere
->isNull('parent_id')
->OR
->equalTo('type', 'MEDIA');
->equalTo('type', 'FILES');
$activityTotal = $this->countTotal($countTotalWhere);

return array(
Expand Down
Expand Up @@ -28,7 +28,7 @@ public function __construct(Acl $acl, AdapterInterface $adapter) {
);

public static $defaultPreferencesValuesByTable = array(
"directus_media" => array(
"directus_files" => array(
"sort" => "date_uploaded",
"sort_order" => "DESC",
"columns_visible" => "name,title,caption,type,size,user,date_uploaded"
Expand Down
Expand Up @@ -70,9 +70,9 @@ public function fetchByCollectionAndName($collection, $name) {
public function setValues($collection, $data) {

$whiteList = array(
'media' => array(
'media_file_naming',
'media_title_naming',
'files' => array(
'file_file_naming',
'file_title_naming',
'allowed_thumbnails',
'thumbnail_quality',
'thumbnail_crop_enabled'
Expand All @@ -87,7 +87,7 @@ public function setValues($collection, $data) {
)
);

if ($collection !== 'media' && $collection !== 'global') {
if ($collection !== 'files' && $collection !== 'global') {
throw new \Exception("The settings collection $collection is not supported");
}

Expand Down
6 changes: 3 additions & 3 deletions api/core/Directus/Db/TableGateway/RelationalTableGateway.php
Expand Up @@ -317,8 +317,8 @@ public function addOrUpdateManyToOneRelationships($schema, $parentRow, &$childLo
$foreignRow = $foreignDataSet;
$foreignTableName = null;

// if("single_media" === $colUiType)
// $foreignTableName = "directus_media";
// if("single_file" === $colUiType)
// $foreignTableName = "directus_files";
// else {
// /**
// * Transitional workaround, pending bugfix to many to one uis.
Expand Down Expand Up @@ -782,7 +782,7 @@ public function loadManyToOneRelationships($schemaArray, $table_entries) {
$foreign_table_name = $col['relationship']['table_related'];

} else {
$message = 'Non single_media Many-to-One relationship lacks `table_related` value.';
$message = 'Non single_file Many-to-One relationship lacks `table_related` value.';
if(array_key_exists('column_name', $col)) {
$message .= " Column: " . $col['column_name'];
}
Expand Down
4 changes: 2 additions & 2 deletions api/core/Directus/Db/TableSchema.php
Expand Up @@ -11,7 +11,7 @@

class TableSchema {

public static $many_to_one_uis = array('many_to_one', 'single_media');
public static $many_to_one_uis = array('many_to_one', 'single_files');

// These columns types are aliases for "associations". They don't have
// real, corresponding columns in the DB.
Expand Down Expand Up @@ -217,7 +217,7 @@ public static function getTables($userGroupId, $versionHash) {
S.TABLE_SCHEMA = :schema AND
(S.TABLE_NAME NOT LIKE "directus\_%" OR
S.TABLE_NAME = "directus_activity" OR
S.TABLE_NAME = "directus_media" OR
S.TABLE_NAME = "directus_files" OR
S.TABLE_NAME = "directus_messages" OR
S.TABLE_NAME = "directus_groups" OR
S.TABLE_NAME = "directus_users" OR
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Directus\Media;
namespace Directus\Files;

/**
* Credit: Phil Brown
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Directus\Media\Storage\Adapter;
namespace Directus\Files\Storage\Adapter;

abstract class Adapter {

Expand Down Expand Up @@ -95,7 +95,7 @@ public function acceptFile($localFile, $targetFileName, $destination) {
$uploadInfo = $this->getUploadInfo($localFile);
// Refused disallowed formats
if(!in_array($uploadInfo['type'], $this->allowedFormats)) {
// @todo use Directus\Media\Upload\Exception
// @todo use Directus\Files\Upload\Exception
// @todo the filters are currently turned off, please turned on again at some point
// throw new \Exception("The type is not supported!");
}
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Directus\Media\Storage\Adapter;
namespace Directus\Files\Storage\Adapter;

use Aws\S3\S3Client;
use Aws\S3\Enum\CannedAcl;
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Directus\Media\Storage\Adapter;
namespace Directus\Files\Storage\Adapter;

class FileSystemAdapter extends Adapter {

Expand Down
@@ -1,13 +1,13 @@
<?php

namespace Directus\Media\Storage\Adapter;
namespace Directus\Files\Storage\Adapter;

use OpenCloud\Rackspace;

class RackspaceOpenCloudAdapter extends Adapter {

protected static $requiredClasses = array("\\OpenCloud\\Rackspace");

protected static $requiredParams = array('api_user','api_key','region','endpoint');

/**
Expand Down

0 comments on commit 4d187bc

Please sign in to comment.