Skip to content

Commit

Permalink
API Namespace all classes
Browse files Browse the repository at this point in the history
Namespace all templates
Move difflib and BBCodeParser2 to thirdparty
Remove deprecated API marked for removal in 4.0
  • Loading branch information
Damian Mooyman committed Sep 7, 2016
1 parent 918fb94 commit 8dd644d
Show file tree
Hide file tree
Showing 871 changed files with 19,942 additions and 17,360 deletions.
321 changes: 320 additions & 1 deletion .upgrade.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SilverStripe\Filesystem;
namespace SilverStripe\Assets;

use Injector;
use SilverStripe\Filesystem\Storage\AssetStore;
use SilverStripe\Filesystem\Storage\DBFile;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\DataExtension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Filesystem;
namespace SilverStripe\Assets;

/**
* Provides a mechanism for determining the effective visibility of a set of assets (identified by
Expand Down
104 changes: 66 additions & 38 deletions filesystem/File.php → Assets/File.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
<?php

use SilverStripe\Filesystem\Storage\DBFile;
use SilverStripe\Filesystem\Thumbnail;
use SilverStripe\Filesystem\ImageManipulation;
use SilverStripe\Filesystem\Storage\AssetContainer;
namespace SilverStripe\Assets;

use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\CMSPreviewable;
use SilverStripe\Assets\Storage\DBFile;
use SilverStripe\Assets\Storage\AssetContainer;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Convert;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\HTMLReadonlyField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Admin\AdminRootController;
use SilverStripe\Admin\CMSPreviewable;



use SilverStripe\View\Parsers\ShortcodeHandler;
use SilverStripe\View\Parsers\ShortcodeParser;
use InvalidArgumentException;

/**
* This class handles the representation of a file on the filesystem within the framework.
Expand Down Expand Up @@ -61,9 +74,6 @@
* "Filename". A ParentID=0 value points to the "assets/" folder, not the webroot.
* -"ShowInSearch": True if this file is searchable
*
* @package framework
* @subpackage filesystem
*
* @property string $Name Basename of the file
* @property string $Title Title of the file
* @property DBFile $File asset stored behind this File record
Expand All @@ -84,6 +94,10 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb

private static $default_sort = "\"Name\"";

/**
* @config
* @var string
*/
private static $singular_name = "File";

private static $plural_name = "Files";
Expand All @@ -105,7 +119,7 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
);

private static $has_one = array(
"Parent" => "File",
"Parent" => "SilverStripe\\Assets\\File",
"Owner" => "SilverStripe\\Security\\Member"
);

Expand All @@ -122,6 +136,8 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
'TreeTitle' => 'HTMLFragment'
);

private static $table_name = 'File';

/**
* @config
* @var array List of allowed file extensions, enforced through {@link validate()}.
Expand Down Expand Up @@ -183,11 +199,11 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer, Thumb
* @var
*/
private static $class_for_file_extension = array(
'*' => 'File',
'jpg' => 'Image',
'jpeg' => 'Image',
'png' => 'Image',
'gif' => 'Image',
'*' => 'SilverStripe\\Assets\\File',
'jpg' => 'SilverStripe\\Assets\\Image',
'jpeg' => 'SilverStripe\\Assets\\Image',
'png' => 'SilverStripe\\Assets\\Image',
'gif' => 'SilverStripe\\Assets\\Image',
);

/**
Expand Down Expand Up @@ -270,6 +286,7 @@ public static function find_shortcode_record($args, &$errorCode = null) {
}

// Check if the file is found
/** @var File $file */
$file = File::get()->byID($args['id']);
if (!$file) {
$errorCode = 404;
Expand Down Expand Up @@ -323,6 +340,7 @@ public static function find($filename) {
// Split to folders and the actual filename, and traverse the structure.
$parts = explode("/", $filename);
$parentID = 0;
/** @var File $item */
$item = null;
foreach($parts as $part) {
$item = File::get()->filter(array(
Expand Down Expand Up @@ -472,14 +490,14 @@ public function getCMSFields() {
sprintf('%spx, %s', $this->getDimensions(), $this->getSize())
));
$fields->push(HTMLReadonlyField::create(
'ClickableURL',
_t('AssetTableField.URL','URL'),
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->Link())
'ClickableURL',
_t('AssetTableField.URL','URL'),
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->Link())
));
}
$fields->push(HiddenField::create('ID', $this->ID));

$fields->insertBefore(TextField::create("Title", $this->fieldLabel('Title')), 'Name');
$fields->insertBefore('Name', TextField::create("Title", $this->fieldLabel('Title')));
$fields->push(DatetimeField::create(
"LastEdited",
_t('AssetTableField.LASTEDIT', 'Last changed')
Expand All @@ -501,7 +519,7 @@ public function getCMSFields() {
*/
public static function get_app_category($ext) {
$ext = strtolower($ext);
foreach(Config::inst()->get('File', 'app_categories') as $category => $exts) {
foreach(static::config()->app_categories as $category => $exts) {
if(in_array($ext, $exts)) return $category;
}
return false;
Expand Down Expand Up @@ -549,7 +567,7 @@ public static function get_category_extensions($categories) {
*/
public function appCategory() {
return self::get_app_category($this->getExtension());
}
}


/**
Expand Down Expand Up @@ -638,6 +656,7 @@ public function collateDescendants($condition, &$collator) {
}
return true;
}
return null;
}

/**
Expand Down Expand Up @@ -708,6 +727,7 @@ public function getAbsoluteURL() {
if($url) {
return Director::absoluteURL($url);
}
return null;
}

/**
Expand All @@ -721,6 +741,7 @@ public function getURL($grant = true) {
if($this->File->exists()) {
return $this->File->getURL($grant);
}
return null;
}

/**
Expand All @@ -733,6 +754,7 @@ public function getSourceURL($grant = true) {
if($this->File->exists()) {
return $this->File->getSourceURL($grant);
}
return null;
}

/**
Expand Down Expand Up @@ -1008,9 +1030,11 @@ public static function get_class_for_file_extension($ext) {
* @param String
*/
public static function set_class_for_file_extension($exts, $class) {
if(!is_array($exts)) $exts = array($exts);
if(!is_array($exts)) {
$exts = array($exts);
}
foreach($exts as $ext) {
if(!is_subclass_of($class, 'File')) {
if(!is_subclass_of($class, 'SilverStripe\\Assets\\File')) {
throw new InvalidArgumentException(
sprintf('Class "%s" (for extension "%s") is not a valid subclass of File', $class, $ext)
);
Expand All @@ -1020,27 +1044,31 @@ public static function set_class_for_file_extension($exts, $class) {
}

public function getMetaData() {
if($this->File->exists()) {
if (!$this->File->exists()) {
return null;
}
return $this->File->getMetaData();
}
}

public function getMimeType() {
if($this->File->exists()) {
if(!$this->File->exists()) {
return null;
}
return $this->File->getMimeType();
}
}

public function getStream() {
if($this->File->exists()) {
return $this->File->getStream();
if(!$this->File->exists()) {
return null;
}
return $this->File->getStream();
}

public function getString() {
if($this->File->exists()) {
return $this->File->getString();
if(!$this->File->exists()) {
return null;
}
return $this->File->getString();
}

public function setFromLocalFile($path, $filename = null, $hash = null, $variant = null, $config = array()) {
Expand Down Expand Up @@ -1134,7 +1162,7 @@ public function requireDefaultRecords() {
* @param string $part,... Parts
* @return string
*/
public static function join_paths() {
public static function join_paths($part = null) {
$args = func_get_args();
if(count($args) === 1 && is_array($args[0])) {
$args = $args[0];
Expand Down
15 changes: 12 additions & 3 deletions filesystem/FileFinder.php → Assets/FileFinder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php

namespace SilverStripe\Assets;

use SilverStripe\Core\Object;
use InvalidArgumentException;

/**
* A utility class that finds any files matching a set of rules that are
* present within a directory tree.
Expand All @@ -23,9 +29,6 @@
* are defined in {@link SS_FileFInder::$vcs_dirs}.
* - max_depth (int): The maxmium depth to traverse down the folder tree,
* default to unlimited.
*
* @package framework
* @subpackage filesystem
*/
class SS_FileFinder {

Expand Down Expand Up @@ -170,6 +173,9 @@ public function find($base) {
* Returns TRUE if the directory should be traversed. This can be overloaded
* to customise functionality, or extended with callbacks.
*
* @param string $basename
* @param string $pathname
* @param int $depth
* @return bool
*/
protected function acceptDir($basename, $pathname, $depth) {
Expand Down Expand Up @@ -200,6 +206,9 @@ protected function acceptDir($basename, $pathname, $depth) {
* Returns TRUE if the file should be included in the results. This can be
* overloaded to customise functionality, or extended via callbacks.
*
* @param string $basename
* @param string $pathname
* @param int $depth
* @return bool
*/
protected function acceptFile($basename, $pathname, $depth) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

use SilverStripe\Filesystem\Storage\AssetStore;
namespace SilverStripe\Assets;

use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Core\Object;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Versioning\Versioned;


/**
* Service to help migrate File dataobjects to the new APL.
*
* This service does not alter these records in such a way that prevents downgrading back to 3.x
*
* @package framework
* @subpackage filesystem
*/
class FileMigrationHelper extends Object {

Expand All @@ -27,6 +27,7 @@ public function run($base = null) {
}
// Check if the File dataobject has a "Filename" field.
// If not, cannot migrate
/** @skipUpgrade */
if(!DB::get_schema()->hasField('File', 'Filename')) {
return 0;
}
Expand Down Expand Up @@ -93,8 +94,9 @@ protected function migrateFile($base, File $file, $legacyFilename) {
*/
protected function getFileQuery() {
// Select all records which have a Filename value, but not FileFilename.
/** @skipUpgrade */
return File::get()
->exclude('ClassName', 'Folder')
->exclude('ClassName', ['SilverStripe\\Assets\\Folder', 'Folder'])
->filter('FileFilename', array('', null))
->where('"File"."Filename" IS NOT NULL AND "File"."Filename" != \'\''); // Non-orm field
}
Expand All @@ -106,6 +108,7 @@ protected function getFileQuery() {
*/
protected function getFilenameArray() {
// Convert original query, ensuring the legacy "Filename" is included in the result
/** @skipUpgrade */
return $this
->getFileQuery()
->dataQuery()
Expand Down
Loading

0 comments on commit 8dd644d

Please sign in to comment.