mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge remote-tracking branch 'origin/3.1' into 3.2
Conflicts: admin/code/LeftAndMain.php control/injector/SilverStripeServiceConfigurationLocator.php core/ClassInfo.php filesystem/File.php model/DataObject.php model/DataQuery.php search/filters/FulltextFilter.php search/filters/SearchFilter.php tests/core/ClassInfoTest.php tests/filesystem/FileTest.php tests/model/DataListTest.php
This commit is contained in:
commit
7ee444e08a
@ -7,10 +7,6 @@ addons:
|
|||||||
packages:
|
packages:
|
||||||
- tidy
|
- tidy
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.composer/cache
|
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.4
|
- 5.4
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
* @config
|
* @config
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $help_link = 'http://userhelp.silverstripe.org/en/3.2/';
|
private static $help_link = '//userhelp.silverstripe.org/framework/en/3.2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -1618,7 +1618,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
* @config
|
* @config
|
||||||
* @var String
|
* @var String
|
||||||
*/
|
*/
|
||||||
private static $application_link = 'http://www.silverstripe.org/';
|
private static $application_link = '//www.silverstripe.org/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the href for the anchor on the Silverstripe logo in the menu
|
* Sets the href for the anchor on the Silverstripe logo in the menu
|
||||||
|
@ -135,7 +135,7 @@ class LeftAndMainTest extends FunctionalTest {
|
|||||||
$link = $menuItem->Link;
|
$link = $menuItem->Link;
|
||||||
|
|
||||||
// don't test external links
|
// don't test external links
|
||||||
if(preg_match('/^https?:\/\//',$link)) continue;
|
if(preg_match('/^(https?:)?\/\//',$link)) continue;
|
||||||
|
|
||||||
$response = $this->get($link);
|
$response = $this->get($link);
|
||||||
|
|
||||||
|
@ -19,13 +19,14 @@ class SilverStripeServiceConfigurationLocator extends ServiceConfigurationLocato
|
|||||||
protected $configs = array();
|
protected $configs = array();
|
||||||
|
|
||||||
public function locateConfigFor($name) {
|
public function locateConfigFor($name) {
|
||||||
|
|
||||||
// Check direct or cached result
|
// Check direct or cached result
|
||||||
$config = $this->configFor($name);
|
$config = $this->configFor($name);
|
||||||
if($config !== null) return $config;
|
if($config !== null) return $config;
|
||||||
|
|
||||||
// do parent lookup if it's a class
|
// do parent lookup if it's a class
|
||||||
if (class_exists($name)) {
|
if (class_exists($name)) {
|
||||||
$parents = array_reverse(array_keys(ClassInfo::ancestry($name)));
|
$parents = array_reverse(array_values(ClassInfo::ancestry($name)));
|
||||||
array_shift($parents);
|
array_shift($parents);
|
||||||
|
|
||||||
foreach ($parents as $parent) {
|
foreach ($parents as $parent) {
|
||||||
|
@ -61,6 +61,7 @@ class ClassInfo {
|
|||||||
* @return array List of subclasses
|
* @return array List of subclasses
|
||||||
*/
|
*/
|
||||||
public static function getValidSubClasses($class = 'SiteTree', $includeUnbacked = false) {
|
public static function getValidSubClasses($class = 'SiteTree', $includeUnbacked = false) {
|
||||||
|
$class = self::class_name($class);
|
||||||
$classes = DB::get_schema()->enumValuesForField($class, 'ClassName');
|
$classes = DB::get_schema()->enumValuesForField($class, 'ClassName');
|
||||||
if (!$includeUnbacked) $classes = array_filter($classes, array('ClassInfo', 'exists'));
|
if (!$includeUnbacked) $classes = array_filter($classes, array('ClassInfo', 'exists'));
|
||||||
return $classes;
|
return $classes;
|
||||||
@ -77,9 +78,7 @@ class ClassInfo {
|
|||||||
public static function dataClassesFor($class) {
|
public static function dataClassesFor($class) {
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
if (is_object($class)) {
|
$class = self::class_name($class);
|
||||||
$class = get_class($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array_merge(
|
$classes = array_merge(
|
||||||
self::ancestry($class),
|
self::ancestry($class),
|
||||||
@ -101,7 +100,7 @@ class ClassInfo {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function baseDataClass($class) {
|
public static function baseDataClass($class) {
|
||||||
if (is_object($class)) $class = get_class($class);
|
$class = self::class_name($class);
|
||||||
|
|
||||||
if (!is_subclass_of($class, 'DataObject')) {
|
if (!is_subclass_of($class, 'DataObject')) {
|
||||||
throw new InvalidArgumentException("$class is not a subclass of DataObject");
|
throw new InvalidArgumentException("$class is not a subclass of DataObject");
|
||||||
@ -125,7 +124,7 @@ class ClassInfo {
|
|||||||
* <code>
|
* <code>
|
||||||
* ClassInfo::subclassesFor('BaseClass');
|
* ClassInfo::subclassesFor('BaseClass');
|
||||||
* array(
|
* array(
|
||||||
* 0 => 'BaseClass',
|
* 'BaseClass' => 'BaseClass',
|
||||||
* 'ChildClass' => 'ChildClass',
|
* 'ChildClass' => 'ChildClass',
|
||||||
* 'GrandChildClass' => 'GrandChildClass'
|
* 'GrandChildClass' => 'GrandChildClass'
|
||||||
* )
|
* )
|
||||||
@ -135,8 +134,10 @@ class ClassInfo {
|
|||||||
* @return array Names of all subclasses as an associative array.
|
* @return array Names of all subclasses as an associative array.
|
||||||
*/
|
*/
|
||||||
public static function subclassesFor($class) {
|
public static function subclassesFor($class) {
|
||||||
|
//normalise class case
|
||||||
|
$className = self::class_name($class);
|
||||||
$descendants = SS_ClassLoader::instance()->getManifest()->getDescendantsOf($class);
|
$descendants = SS_ClassLoader::instance()->getManifest()->getDescendantsOf($class);
|
||||||
$result = array($class => $class);
|
$result = array($className => $className);
|
||||||
|
|
||||||
if ($descendants) {
|
if ($descendants) {
|
||||||
return $result + ArrayLib::valuekey($descendants);
|
return $result + ArrayLib::valuekey($descendants);
|
||||||
@ -145,6 +146,23 @@ class ClassInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a class name in any case and return it as it was defined in PHP
|
||||||
|
*
|
||||||
|
* eg: self::class_name('dataobJEct'); //returns 'DataObject'
|
||||||
|
*
|
||||||
|
* @param string|object $nameOrObject The classname or object you want to normalise
|
||||||
|
*
|
||||||
|
* @return string The normalised class name
|
||||||
|
*/
|
||||||
|
public static function class_name($nameOrObject) {
|
||||||
|
if (is_object($nameOrObject)) {
|
||||||
|
return get_class($nameOrObject);
|
||||||
|
}
|
||||||
|
$reflection = new ReflectionClass($nameOrObject);
|
||||||
|
return $reflection->getName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the passed class name along with all its parent class names in an
|
* Returns the passed class name along with all its parent class names in an
|
||||||
* array, sorted with the root class first.
|
* array, sorted with the root class first.
|
||||||
@ -154,9 +172,11 @@ class ClassInfo {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function ancestry($class, $tablesOnly = false) {
|
public static function ancestry($class, $tablesOnly = false) {
|
||||||
if (!is_string($class)) $class = get_class($class);
|
$class = self::class_name($class);
|
||||||
|
|
||||||
$cacheKey = $class . '_' . (string)$tablesOnly;
|
$lClass = strtolower($class);
|
||||||
|
|
||||||
|
$cacheKey = $lClass . '_' . (string)$tablesOnly;
|
||||||
$parent = $class;
|
$parent = $class;
|
||||||
if(!isset(self::$_cache_ancestry[$cacheKey])) {
|
if(!isset(self::$_cache_ancestry[$cacheKey])) {
|
||||||
$ancestry = array();
|
$ancestry = array();
|
||||||
@ -183,7 +203,7 @@ class ClassInfo {
|
|||||||
* Returns true if the given class implements the given interface
|
* Returns true if the given class implements the given interface
|
||||||
*/
|
*/
|
||||||
public static function classImplements($className, $interfaceName) {
|
public static function classImplements($className, $interfaceName) {
|
||||||
return in_array($className, SS_ClassLoader::instance()->getManifest()->getImplementorsOf($interfaceName));
|
return in_array($className, self::implementorsOf($interfaceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,22 +252,26 @@ class ClassInfo {
|
|||||||
private static $method_from_cache = array();
|
private static $method_from_cache = array();
|
||||||
|
|
||||||
public static function has_method_from($class, $method, $compclass) {
|
public static function has_method_from($class, $method, $compclass) {
|
||||||
if (!isset(self::$method_from_cache[$class])) self::$method_from_cache[$class] = array();
|
$lClass = strtolower($class);
|
||||||
|
$lMethod = strtolower($method);
|
||||||
|
$lCompclass = strtolower($compclass);
|
||||||
|
if (!isset(self::$method_from_cache[$lClass])) self::$method_from_cache[$lClass] = array();
|
||||||
|
|
||||||
if (!array_key_exists($method, self::$method_from_cache[$class])) {
|
if (!array_key_exists($lMethod, self::$method_from_cache[$lClass])) {
|
||||||
self::$method_from_cache[$class][$method] = false;
|
self::$method_from_cache[$lClass][$lMethod] = false;
|
||||||
|
|
||||||
$classRef = new ReflectionClass($class);
|
$classRef = new ReflectionClass($class);
|
||||||
|
|
||||||
if ($classRef->hasMethod($method)) {
|
if ($classRef->hasMethod($method)) {
|
||||||
$methodRef = $classRef->getMethod($method);
|
$methodRef = $classRef->getMethod($method);
|
||||||
self::$method_from_cache[$class][$method] = $methodRef->getDeclaringClass()->getName();
|
self::$method_from_cache[$lClass][$lMethod] = $methodRef->getDeclaringClass()->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$method_from_cache[$class][$method] == $compclass;
|
return strtolower(self::$method_from_cache[$lClass][$lMethod]) == $lCompclass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the table name in the class hierarchy which contains a given
|
* Returns the table name in the class hierarchy which contains a given
|
||||||
* field column for a {@link DataObject}. If the field does not exist, this
|
* field column for a {@link DataObject}. If the field does not exist, this
|
||||||
@ -259,11 +283,14 @@ class ClassInfo {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function table_for_object_field($candidateClass, $fieldName) {
|
public static function table_for_object_field($candidateClass, $fieldName) {
|
||||||
if(!$candidateClass || !$fieldName) {
|
if(!$candidateClass || !$fieldName || !is_subclass_of($candidateClass, 'DataObject')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = class_exists($candidateClass);
|
//normalise class name
|
||||||
|
$candidateClass = self::class_name($candidateClass);
|
||||||
|
|
||||||
|
$exists = self::exists($candidateClass);
|
||||||
|
|
||||||
while($candidateClass && $candidateClass != 'DataObject' && $exists) {
|
while($candidateClass && $candidateClass != 'DataObject' && $exists) {
|
||||||
if(DataObject::has_own_table($candidateClass)) {
|
if(DataObject::has_own_table($candidateClass)) {
|
||||||
@ -275,7 +302,7 @@ class ClassInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$candidateClass = get_parent_class($candidateClass);
|
$candidateClass = get_parent_class($candidateClass);
|
||||||
$exists = class_exists($candidateClass);
|
$exists = $candidateClass && self::exists($candidateClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$candidateClass || !$exists) {
|
if(!$candidateClass || !$exists) {
|
||||||
|
@ -39,6 +39,43 @@ records and cannot easily be adapted to include custom `DataObject` instances. T
|
|||||||
default site search, have a look at those extensions and modify as required.
|
default site search, have a look at those extensions and modify as required.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Fulltext Filter
|
||||||
|
|
||||||
|
SilverStripe provides a `[api:FulltextFiler]` which you can use to perform custom fulltext searches on
|
||||||
|
`[api:DataList]`'s.
|
||||||
|
|
||||||
|
Example DataObject:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
class SearchableDataObject extends DataObject {
|
||||||
|
|
||||||
|
private static $db = array(
|
||||||
|
"Title" => "Varchar(255)",
|
||||||
|
"Content" => "HTMLText",
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $indexes = array(
|
||||||
|
'SearchFields' => array(
|
||||||
|
'type' => 'fulltext',
|
||||||
|
'name' => 'SearchFields',
|
||||||
|
'value' => '"Title", "Content"',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $create_table_options = array(
|
||||||
|
'MySQLDatabase' => 'ENGINE=MyISAM'
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Performing the search:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
SearchableDataObject::get()->filter('SearchFields:fulltext', 'search term');
|
||||||
|
|
||||||
|
If your search index is a single field size, then you may also specify the search filter by the name of the
|
||||||
|
field instead of the index.
|
||||||
|
|
||||||
## API Documentation
|
## API Documentation
|
||||||
|
|
||||||
* [api:FulltextSearchable]
|
* [api:FulltextSearchable]
|
@ -2,7 +2,7 @@ summary: Describes the process followed for "core" releases.
|
|||||||
|
|
||||||
# Release Process
|
# Release Process
|
||||||
|
|
||||||
Describes the process followed for "core" releases (mainly the `framework` and `cms` modules).
|
This page describes the process followed for "core" releases (mainly the `framework` and `cms` modules).
|
||||||
|
|
||||||
## Release Maintainer
|
## Release Maintainer
|
||||||
|
|
||||||
@ -19,13 +19,13 @@ Release dates are usually not published prior to the release, but you can get a
|
|||||||
reviewing the release milestone on github.com. Releases will be
|
reviewing the release milestone on github.com. Releases will be
|
||||||
announced on the [release announcements mailing list](http://groups.google.com/group/silverstripe-announce).
|
announced on the [release announcements mailing list](http://groups.google.com/group/silverstripe-announce).
|
||||||
|
|
||||||
Releases of the *cms* and *framework* modules are coupled at the moment, they follow the same numbering scheme.
|
Releases of the *cms* and *framework* modules are coupled at the moment, and they follow the same numbering scheme.
|
||||||
|
|
||||||
## Release Numbering
|
## Release Numbering
|
||||||
|
|
||||||
SilverStripe follows [Semantic Versioning](http://semver.org).
|
SilverStripe follows [Semantic Versioning](http://semver.org).
|
||||||
|
|
||||||
Note: Until November 2014, the project didn't adhere to Semantic Versioning. Instead. a "minor release" in semver terminology
|
Note: Until November 2014, the project didn't adhere to Semantic Versioning. Instead, a "minor release" in semver terminology
|
||||||
was treated as a "major release" in SilverStripe. For example, the *3.1.0* release contained API breaking changes, and
|
was treated as a "major release" in SilverStripe. For example, the *3.1.0* release contained API breaking changes, and
|
||||||
the *3.1.1* release contained new features rather than just bugfixes.
|
the *3.1.1* release contained new features rather than just bugfixes.
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ patch release
|
|||||||
## Deprecation
|
## Deprecation
|
||||||
|
|
||||||
Needs of developers (both on core framework and custom projects) can outgrow the capabilities
|
Needs of developers (both on core framework and custom projects) can outgrow the capabilities
|
||||||
of a certain API. Existing APIs might turn out to be hard to understand, maintain, test or stabilize.
|
of a certain API. Existing APIs might turn out to be hard to understand, maintain, test or stabilise.
|
||||||
In these cases, it is best practice to "refactor" these APIs into something more useful.
|
In these cases, it is best practice to "refactor" these APIs into something more useful.
|
||||||
SilverStripe acknowledges that developers have built a lot of code on top of existing APIs,
|
SilverStripe acknowledges that developers have built a lot of code on top of existing APIs,
|
||||||
so we strive for giving ample warning on any upcoming changes through a "deprecation cycle".
|
so we strive for giving ample warning on any upcoming changes through a "deprecation cycle".
|
||||||
@ -53,17 +53,15 @@ How to deprecate an API:
|
|||||||
* Add a `@deprecated` item to the docblock tag, with a `{@link <class>}` item pointing to the new API to use.
|
* Add a `@deprecated` item to the docblock tag, with a `{@link <class>}` item pointing to the new API to use.
|
||||||
* Update the deprecated code to throw a `[api:Deprecation::notice()]` error.
|
* Update the deprecated code to throw a `[api:Deprecation::notice()]` error.
|
||||||
* Both the docblock and error message should contain the **target version** where the functionality is removed.
|
* Both the docblock and error message should contain the **target version** where the functionality is removed.
|
||||||
So if you're committing the change to a *3.1* minor release, the target version will be *4.0*.
|
So, if you're committing the change to a *3.1* minor release, the target version will be *4.0*.
|
||||||
* Deprecations should not be committed to patch releases
|
* Deprecations should not be committed to patch releases
|
||||||
* Deprecations should just be committed to pre-release branches, ideally before they enter the "beta" phase.
|
* Deprecations should only be committed to pre-release branches, ideally before they enter the "beta" phase.
|
||||||
If deprecations are introduced after this point, their target version needs to be increased by one.
|
If deprecations are introduced after this point, their target version needs to be increased by one.
|
||||||
* Make sure that the old deprecated function works by calling the new function - don't have duplicated code!
|
* Make sure that the old deprecated function works by calling the new function - don't have duplicated code!
|
||||||
* The commit message should contain an `API` prefix (see ["commit message format"](code#commit-messages))
|
* The commit message should contain an `API` prefix (see ["commit message format"](code#commit-messages))
|
||||||
* Document the change in the [changelog](/changelogs) for the next release
|
* Document the change in the [changelog](/changelogs) for the next release
|
||||||
* Deprecated APIs can be removed after developers had a chance to react to the changes. As a rule of thumb, leave the
|
* Deprecated APIs can be removed only after developers have had sufficient time to react to the changes. Hence, deprecated APIs should be removed in MAJOR releases only. Between MAJOR releases, leave the code in place with a deprecation warning.
|
||||||
code with the deprecation warning in for at least three micro releases. Only remove code in a minor or major release.
|
* Exceptions to the deprecation cycle are APIs that have been moved into their own module, and continue to work with the new minor release. These changes can be performed in a single minor release without a deprecation period.
|
||||||
* Exceptions to the deprecation cycle are APIs that have been moved into their own module, and continue to work with the
|
|
||||||
new minor release. These changes can be performed in a single minor release without a deprecation period.
|
|
||||||
|
|
||||||
Here's an example for replacing `Director::isDev()` with a (theoretical) `Env::is_dev()`:
|
Here's an example for replacing `Director::isDev()` with a (theoretical) `Env::is_dev()`:
|
||||||
|
|
||||||
@ -77,8 +75,8 @@ Here's an example for replacing `Director::isDev()` with a (theoretical) `Env::i
|
|||||||
return Env::is_dev();
|
return Env::is_dev();
|
||||||
}
|
}
|
||||||
|
|
||||||
This change could be committed to a minor release like *3.2.0*, and stays deprecated in all following minor releases
|
This change could be committed to a minor release like *3.2.0*, and remains deprecated in all subsequent minor releases
|
||||||
(e.g. *3.3.0*, *3.4.0*), until a new major release (e.g. *4.0.0*) where it gets removed from the codebase.
|
(e.g. *3.3.0*, *3.4.0*), until a new major release (e.g. *4.0.0*), at which point it gets removed from the codebase.
|
||||||
|
|
||||||
Deprecation notices are enabled by default on dev environment, but can be
|
Deprecation notices are enabled by default on dev environment, but can be
|
||||||
turned off via either _ss_environment.php or in your _config.php. Deprecation
|
turned off via either _ss_environment.php or in your _config.php. Deprecation
|
||||||
@ -118,7 +116,7 @@ previous major release (if applicable).
|
|||||||
[new release](http://silverstripe.org/security-releases/) publically.
|
[new release](http://silverstripe.org/security-releases/) publically.
|
||||||
|
|
||||||
You can help us determine the problem and speed up responses by providing us with more information on how to reproduce
|
You can help us determine the problem and speed up responses by providing us with more information on how to reproduce
|
||||||
the issue: SilverStripe version (incl. any installed modules), PHP/webserver version and configuration, anonymized
|
the issue: SilverStripe version (incl. any installed modules), PHP/webserver version and configuration, anonymised
|
||||||
webserver access logs (if a hack is suspected), any other services and web packages running on the same server.
|
webserver access logs (if a hack is suspected), any other services and web packages running on the same server.
|
||||||
|
|
||||||
### Severity rating
|
### Severity rating
|
||||||
@ -128,7 +126,7 @@ each vulnerability. The rating indicates how important an update is:
|
|||||||
|
|
||||||
| Severity | Description |
|
| Severity | Description |
|
||||||
|---------------|-------------|
|
|---------------|-------------|
|
||||||
| **Critical** | Critical releases require immediate actions. Such vulnerabilities allow attackers to take control of your site and you should upgrade on the day of release. *Example: Directory traversal, privilege escalation* |
|
| **Critical** | Critical releases require immediate action. Such vulnerabilities allow attackers to take control of your site and you should upgrade on the day of release. *Example: Directory traversal, privilege escalation* |
|
||||||
| **Important** | Important releases should be evaluated immediately. These issues allow an attacker to compromise a site's data and should be fixed within days. *Example: SQL injection.* |
|
| **Important** | Important releases should be evaluated immediately. These issues allow an attacker to compromise a site's data and should be fixed within days. *Example: SQL injection.* |
|
||||||
| **Moderate** | Releases of moderate severity should be applied as soon as possible. They allow the unauthorized editing or creation of content. *Examples: Cross Site Scripting (XSS) in template helpers.* |
|
| **Moderate** | Releases of moderate severity should be applied as soon as possible. They allow the unauthorized editing or creation of content. *Examples: Cross Site Scripting (XSS) in template helpers.* |
|
||||||
| **Low** | Low risk releases fix information disclosure and read-only privilege escalation vulnerabilities. These updates should also be applied as soon as possible, but with an impact-dependent priority. *Example: Exposure of the core version number, Cross Site Scripting (XSS) limited to the admin interface.* |
|
| **Low** | Low risk releases fix information disclosure and read-only privilege escalation vulnerabilities. These updates should also be applied as soon as possible, but according to an impact-dependent priority. *Example: Exposure of the core version number, Cross Site Scripting (XSS) limited to the admin interface.* |
|
||||||
|
@ -841,7 +841,7 @@ class File extends DataObject {
|
|||||||
'htm' => _t('File.HtmlType', 'HTML file')
|
'htm' => _t('File.HtmlType', 'HTML file')
|
||||||
);
|
);
|
||||||
|
|
||||||
$ext = $this->getExtension();
|
$ext = strtolower($this->getExtension());
|
||||||
|
|
||||||
return isset($types[$ext]) ? $types[$ext] : 'unknown';
|
return isset($types[$ext]) ? $types[$ext] : 'unknown';
|
||||||
}
|
}
|
||||||
|
45
main.php
45
main.php
@ -67,37 +67,44 @@ if(!empty($_SERVER['HTTP_X_ORIGINAL_URL'])) {
|
|||||||
*/
|
*/
|
||||||
global $url;
|
global $url;
|
||||||
|
|
||||||
// PHP 5.4's built-in webserver uses this
|
// Helper to safely parse and load a querystring fragment
|
||||||
if (php_sapi_name() == 'cli-server') {
|
$parseQuery = function($query) {
|
||||||
$url = $_SERVER['REQUEST_URI'];
|
|
||||||
|
|
||||||
// Querystring args need to be explicitly parsed
|
|
||||||
if(strpos($url,'?') !== false) {
|
|
||||||
list($url, $query) = explode('?',$url,2);
|
|
||||||
parse_str($query, $_GET);
|
parse_str($query, $_GET);
|
||||||
if ($_GET) $_REQUEST = array_merge((array)$_REQUEST, (array)$_GET);
|
if ($_GET) $_REQUEST = array_merge((array)$_REQUEST, (array)$_GET);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apache rewrite rules and IIS use this
|
||||||
|
if (isset($_GET['url']) && php_sapi_name() !== 'cli-server') {
|
||||||
|
|
||||||
|
// Prevent injection of url= querystring argument by prioritising any leading url argument
|
||||||
|
if(isset($_SERVER['QUERY_STRING']) &&
|
||||||
|
preg_match('/^(?<url>url=[^&?]*)(?<query>.*[&?]url=.*)$/', $_SERVER['QUERY_STRING'], $results)
|
||||||
|
) {
|
||||||
|
$queryString = $results['query'].'&'.$results['url'];
|
||||||
|
$parseQuery($queryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass back to the webserver for files that exist
|
|
||||||
if(file_exists(BASE_PATH . $url) && is_file(BASE_PATH . $url)) return false;
|
|
||||||
|
|
||||||
// Apache rewrite rules use this
|
|
||||||
} else if (isset($_GET['url'])) {
|
|
||||||
$url = $_GET['url'];
|
$url = $_GET['url'];
|
||||||
|
|
||||||
// IIS includes get variables in url
|
// IIS includes get variables in url
|
||||||
$i = strpos($url, '?');
|
$i = strpos($url, '?');
|
||||||
if($i !== false) {
|
if($i !== false) {
|
||||||
$url = substr($url, 0, $i);
|
$url = substr($url, 0, $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lighttpd uses this
|
// Lighttpd and PHP 5.4's built-in webserver use this
|
||||||
} else {
|
} else {
|
||||||
if(strpos($_SERVER['REQUEST_URI'],'?') !== false) {
|
$url = $_SERVER['REQUEST_URI'];
|
||||||
list($url, $query) = explode('?', $_SERVER['REQUEST_URI'], 2);
|
|
||||||
parse_str($query, $_GET);
|
// Querystring args need to be explicitly parsed
|
||||||
if ($_GET) $_REQUEST = array_merge((array)$_REQUEST, (array)$_GET);
|
if(strpos($url,'?') !== false) {
|
||||||
} else {
|
list($url, $query) = explode('?',$url,2);
|
||||||
$url = $_SERVER["REQUEST_URI"];
|
$parseQuery($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass back to the webserver for files that exist
|
||||||
|
if(php_sapi_name() === 'cli-server' && file_exists(BASE_PATH . $url) && is_file(BASE_PATH . $url)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,6 +452,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$record = null;
|
$record = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(is_a($record, "stdClass")) {
|
||||||
|
$record = (array)$record;
|
||||||
|
}
|
||||||
|
|
||||||
// Set $this->record to $record, but ignore NULLs
|
// Set $this->record to $record, but ignore NULLs
|
||||||
$this->record = array();
|
$this->record = array();
|
||||||
foreach($record as $k => $v) {
|
foreach($record as $k => $v) {
|
||||||
@ -1263,6 +1267,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if database column doesn't correlate to a DBField instance...
|
// if database column doesn't correlate to a DBField instance...
|
||||||
$fieldObj = $this->dbObject($fieldName);
|
$fieldObj = $this->dbObject($fieldName);
|
||||||
if(!$fieldObj) {
|
if(!$fieldObj) {
|
||||||
@ -2742,6 +2747,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
public static function has_own_table($dataClass) {
|
public static function has_own_table($dataClass) {
|
||||||
if(!is_subclass_of($dataClass,'DataObject')) return false;
|
if(!is_subclass_of($dataClass,'DataObject')) return false;
|
||||||
|
|
||||||
|
$dataClass = ClassInfo::class_name($dataClass);
|
||||||
if(!isset(DataObject::$cache_has_own_table[$dataClass])) {
|
if(!isset(DataObject::$cache_has_own_table[$dataClass])) {
|
||||||
if(get_parent_class($dataClass) == 'DataObject') {
|
if(get_parent_class($dataClass) == 'DataObject') {
|
||||||
DataObject::$cache_has_own_table[$dataClass] = true;
|
DataObject::$cache_has_own_table[$dataClass] = true;
|
||||||
@ -3128,6 +3134,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the first item matching the given query.
|
* Return the first item matching the given query.
|
||||||
* All calls to get_one() are cached.
|
* All calls to get_one() are cached.
|
||||||
|
@ -196,7 +196,7 @@ class DataQuery {
|
|||||||
$tableClasses = $ancestorTables;
|
$tableClasses = $ancestorTables;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tableNames = array_keys($tableClasses);
|
$tableNames = array_values($tableClasses);
|
||||||
$baseClass = $tableNames[0];
|
$baseClass = $tableNames[0];
|
||||||
|
|
||||||
// Iterate over the tables and check what we need to select from them. If any selects are made (or the table is
|
// Iterate over the tables and check what we need to select from them. If any selects are made (or the table is
|
||||||
@ -828,7 +828,9 @@ class DataQuery {
|
|||||||
/**
|
/**
|
||||||
* Represents a subgroup inside a WHERE clause in a {@link DataQuery}
|
* Represents a subgroup inside a WHERE clause in a {@link DataQuery}
|
||||||
*
|
*
|
||||||
* Stores the clauses for the subgroup inside a specific {@link SQLQuery} object.
|
* Stores the clauses for the subgroup inside a specific {@link SQLQuery}
|
||||||
|
* object.
|
||||||
|
*
|
||||||
* All non-where methods call their DataQuery versions, which uses the base
|
* All non-where methods call their DataQuery versions, which uses the base
|
||||||
* query object.
|
* query object.
|
||||||
*
|
*
|
||||||
|
@ -84,7 +84,9 @@ abstract class StringField extends DBField {
|
|||||||
* @see core/model/fieldtypes/DBField#exists()
|
* @see core/model/fieldtypes/DBField#exists()
|
||||||
*/
|
*/
|
||||||
public function exists() {
|
public function exists() {
|
||||||
return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === '');
|
return $this->getValue() // All truthy values exist
|
||||||
|
|| (is_string($this->getValue()) && strlen($this->getValue())) // non-empty strings exist ('0' but not (int)0)
|
||||||
|
|| (!$this->getNullifyEmpty() && $this->getValue() === ''); // Remove this stupid exemption in 4.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
40
search/filters/FulltextFilter.php
Normal file → Executable file
40
search/filters/FulltextFilter.php
Normal file → Executable file
@ -17,22 +17,23 @@
|
|||||||
* database table, using the {$indexes} hash in your DataObject subclass:
|
* database table, using the {$indexes} hash in your DataObject subclass:
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* static $indexes = array(
|
* private static $indexes = array(
|
||||||
* 'SearchFields' => 'fulltext(Name, Title, Description)'
|
* 'SearchFields' => 'fulltext(Name, Title, Description)'
|
||||||
* );
|
* );
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @package framework
|
* @todo Add support for databases besides MySQL
|
||||||
* @subpackage search
|
|
||||||
*/
|
*/
|
||||||
class FulltextFilter extends SearchFilter {
|
class FulltextFilter extends SearchFilter {
|
||||||
|
|
||||||
protected function applyOne(DataQuery $query) {
|
protected function applyOne(DataQuery $query) {
|
||||||
|
$this->model = $query->applyRelation($this->relation);
|
||||||
$predicate = sprintf("MATCH (%s) AGAINST (?)", $this->getDbName());
|
$predicate = sprintf("MATCH (%s) AGAINST (?)", $this->getDbName());
|
||||||
return $query->where(array($predicate => $this->getValue()));
|
return $query->where(array($predicate => $this->getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function excludeOne(DataQuery $query) {
|
protected function excludeOne(DataQuery $query) {
|
||||||
|
$this->model = $query->applyRelation($this->relation);
|
||||||
$predicate = sprintf("NOT MATCH (%s) AGAINST (?)", $this->getDbName());
|
$predicate = sprintf("NOT MATCH (%s) AGAINST (?)", $this->getDbName());
|
||||||
return $query->where(array($predicate => $this->getValue()));
|
return $query->where(array($predicate => $this->getValue()));
|
||||||
}
|
}
|
||||||
@ -40,4 +41,37 @@ class FulltextFilter extends SearchFilter {
|
|||||||
public function isEmpty() {
|
public function isEmpty() {
|
||||||
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
return $this->getValue() === array() || $this->getValue() === null || $this->getValue() === '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This implementation allows for a list of columns to be passed into MATCH() instead of just one.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* <code>
|
||||||
|
* MyDataObject::get()->filter('SearchFields:fulltext', 'search term')
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDbName() {
|
||||||
|
$indexes = Config::inst()->get($this->model, "indexes");
|
||||||
|
if(is_array($indexes) && array_key_exists($this->getName(), $indexes)) {
|
||||||
|
$index = $indexes[$this->getName()];
|
||||||
|
if(is_array($index) && array_key_exists("value", $index)) {
|
||||||
|
return $index['value'];
|
||||||
|
} else {
|
||||||
|
// Parse a fulltext string (eg. fulltext ("ColumnA", "ColumnB")) to figure out which columns
|
||||||
|
// we need to search.
|
||||||
|
if(preg_match('/^fulltext\s+\((.+)\)$/i', $index, $matches)) {
|
||||||
|
return $matches[1];
|
||||||
|
} else {
|
||||||
|
throw new Exception("Invalid fulltext index format for '" . $this->getName()
|
||||||
|
. "' on '" . $this->model . "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getDbName();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,12 @@ abstract class SearchFilter extends Object {
|
|||||||
if($this->name == "NULL") {
|
if($this->name == "NULL") {
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
// Ensure that we're dealing with a DataObject.
|
||||||
|
if (!is_subclass_of($this->model, 'DataObject')) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
"Model supplied to " . get_class($this) . " should be an instance of DataObject."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$candidateClass = ClassInfo::table_for_object_field(
|
$candidateClass = ClassInfo::table_for_object_field(
|
||||||
$this->model,
|
$this->model,
|
||||||
@ -177,7 +183,7 @@ abstract class SearchFilter extends Object {
|
|||||||
return '"' . implode('"."', $parts) . '"';
|
return '"' . implode('"."', $parts) . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\"$candidateClass\".\"$this->name\"";
|
return sprintf('"%s"."%s"', $candidateClass, $this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,7 +200,6 @@ abstract class SearchFilter extends Object {
|
|||||||
return $dbField->RAW();
|
return $dbField->RAW();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply filter criteria to a SQL query.
|
* Apply filter criteria to a SQL query.
|
||||||
*
|
*
|
||||||
|
@ -14,10 +14,18 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
'ClassInfoTest_NoFields',
|
'ClassInfoTest_NoFields',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
}
|
||||||
|
|
||||||
public function testExists() {
|
public function testExists() {
|
||||||
$this->assertTrue(ClassInfo::exists('Object'));
|
$this->assertTrue(ClassInfo::exists('Object'));
|
||||||
|
$this->assertTrue(ClassInfo::exists('object'));
|
||||||
$this->assertTrue(ClassInfo::exists('ClassInfoTest'));
|
$this->assertTrue(ClassInfo::exists('ClassInfoTest'));
|
||||||
|
$this->assertTrue(ClassInfo::exists('CLASSINFOTEST'));
|
||||||
$this->assertTrue(ClassInfo::exists('stdClass'));
|
$this->assertTrue(ClassInfo::exists('stdClass'));
|
||||||
|
$this->assertTrue(ClassInfo::exists('stdCLASS'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubclassesFor() {
|
public function testSubclassesFor() {
|
||||||
@ -30,6 +38,16 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
),
|
),
|
||||||
'ClassInfo::subclassesFor() returns only direct subclasses and doesnt include base class'
|
'ClassInfo::subclassesFor() returns only direct subclasses and doesnt include base class'
|
||||||
);
|
);
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
$this->assertEquals(
|
||||||
|
ClassInfo::subclassesFor('classinfotest_baseclass'),
|
||||||
|
array(
|
||||||
|
'ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass',
|
||||||
|
'ClassInfoTest_ChildClass' => 'ClassInfoTest_ChildClass',
|
||||||
|
'ClassInfoTest_GrandChildClass' => 'ClassInfoTest_GrandChildClass'
|
||||||
|
),
|
||||||
|
'ClassInfo::subclassesFor() is acting in a case sensitive way when it should not'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClassesForFolder() {
|
public function testClassesForFolder() {
|
||||||
@ -42,11 +60,11 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
$classes,
|
$classes,
|
||||||
'ClassInfo::classes_for_folder() returns classes matching the filename'
|
'ClassInfo::classes_for_folder() returns classes matching the filename'
|
||||||
);
|
);
|
||||||
// $this->assertContains(
|
$this->assertContains(
|
||||||
// 'ClassInfoTest_BaseClass',
|
'classinfotest_baseclass',
|
||||||
// $classes,
|
$classes,
|
||||||
// 'ClassInfo::classes_for_folder() returns additional classes not matching the filename'
|
'ClassInfo::classes_for_folder() returns additional classes not matching the filename'
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,8 +72,11 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
*/
|
*/
|
||||||
public function testBaseDataClass() {
|
public function testBaseDataClass() {
|
||||||
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_BaseClass'));
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_BaseClass'));
|
||||||
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('classinfotest_baseclass'));
|
||||||
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_ChildClass'));
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_ChildClass'));
|
||||||
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('CLASSINFOTEST_CHILDCLASS'));
|
||||||
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_GrandChildClass'));
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_GrandChildClass'));
|
||||||
|
$this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_GRANDChildClass'));
|
||||||
|
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
ClassInfo::baseDataClass('DataObject');
|
ClassInfo::baseDataClass('DataObject');
|
||||||
@ -75,6 +96,13 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
));
|
));
|
||||||
$this->assertEquals($expect, $ancestry);
|
$this->assertEquals($expect, $ancestry);
|
||||||
|
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
$this->assertEquals($expect, ClassInfo::ancestry('classINFOTest_Childclass'));
|
||||||
|
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
$this->assertEquals($expect, ClassInfo::ancestry('classINFOTest_Childclass'));
|
||||||
|
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
$ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass', true);
|
$ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass', true);
|
||||||
$this->assertEquals(array('ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass'), $ancestry,
|
$this->assertEquals(array('ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass'), $ancestry,
|
||||||
'$tablesOnly option excludes memory-only inheritance classes'
|
'$tablesOnly option excludes memory-only inheritance classes'
|
||||||
@ -97,8 +125,11 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
'ClassInfoTest_HasFields',
|
'ClassInfoTest_HasFields',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[0]));
|
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[0]));
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
$this->assertEquals($expect, ClassInfo::dataClassesFor(strtoupper($classes[0])));
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[1]));
|
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[1]));
|
||||||
|
|
||||||
$expect = array(
|
$expect = array(
|
||||||
@ -106,7 +137,10 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
'ClassInfoTest_HasFields' => 'ClassInfoTest_HasFields',
|
'ClassInfoTest_HasFields' => 'ClassInfoTest_HasFields',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[2]));
|
$this->assertEquals($expect, ClassInfo::dataClassesFor($classes[2]));
|
||||||
|
ClassInfo::reset_db_cache();
|
||||||
|
$this->assertEquals($expect, ClassInfo::dataClassesFor(strtolower($classes[2])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTableForObjectField() {
|
public function testTableForObjectField() {
|
||||||
@ -114,6 +148,10 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
ClassInfo::table_for_object_field('ClassInfoTest_WithRelation', 'RelationID')
|
ClassInfo::table_for_object_field('ClassInfoTest_WithRelation', 'RelationID')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertEquals('ClassInfoTest_WithRelation',
|
||||||
|
ClassInfo::table_for_object_field('ClassInfoTest_withrelation', 'RelationID')
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals('ClassInfoTest_BaseDataClass',
|
$this->assertEquals('ClassInfoTest_BaseDataClass',
|
||||||
ClassInfo::table_for_object_field('ClassInfoTest_BaseDataClass', 'Title')
|
ClassInfo::table_for_object_field('ClassInfoTest_BaseDataClass', 'Title')
|
||||||
);
|
);
|
||||||
@ -126,6 +164,10 @@ class ClassInfoTest extends SapphireTest {
|
|||||||
ClassInfo::table_for_object_field('ClassInfoTest_NoFields', 'Title')
|
ClassInfo::table_for_object_field('ClassInfoTest_NoFields', 'Title')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertEquals('ClassInfoTest_BaseDataClass',
|
||||||
|
ClassInfo::table_for_object_field('classinfotest_nofields', 'Title')
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals('ClassInfoTest_HasFields',
|
$this->assertEquals('ClassInfoTest_HasFields',
|
||||||
ClassInfo::table_for_object_field('ClassInfoTest_HasFields', 'Description')
|
ClassInfo::table_for_object_field('ClassInfoTest_HasFields', 'Description')
|
||||||
);
|
);
|
||||||
|
@ -250,6 +250,9 @@ class FileTest extends SapphireTest {
|
|||||||
$file = $this->objFromFixture('File', 'pdf');
|
$file = $this->objFromFixture('File', 'pdf');
|
||||||
$this->assertEquals("Adobe Acrobat PDF file", $file->FileType);
|
$this->assertEquals("Adobe Acrobat PDF file", $file->FileType);
|
||||||
|
|
||||||
|
$file = $this->objFromFixture('File', 'gifupper');
|
||||||
|
$this->assertEquals("GIF image - good for diagrams", $file->FileType);
|
||||||
|
|
||||||
/* Only a few file types are given special descriptions; the rest are unknown */
|
/* Only a few file types are given special descriptions; the rest are unknown */
|
||||||
$file = $this->objFromFixture('File', 'asdf');
|
$file = $this->objFromFixture('File', 'asdf');
|
||||||
$this->assertEquals("unknown", $file->FileType);
|
$this->assertEquals("unknown", $file->FileType);
|
||||||
|
@ -13,6 +13,8 @@ File:
|
|||||||
Filename: assets/FileTest.txt
|
Filename: assets/FileTest.txt
|
||||||
gif:
|
gif:
|
||||||
Filename: assets/FileTest.gif
|
Filename: assets/FileTest.gif
|
||||||
|
gifupper:
|
||||||
|
Filename: assets/FileTest.GIF
|
||||||
pdf:
|
pdf:
|
||||||
Filename: assets/FileTest.pdf
|
Filename: assets/FileTest.pdf
|
||||||
setfromname:
|
setfromname:
|
||||||
|
@ -146,6 +146,11 @@ class DataListTest extends SapphireTest {
|
|||||||
$this->assertEquals('DataObjectTest_TeamComment',$list->dataClass());
|
$this->assertEquals('DataObjectTest_TeamComment',$list->dataClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDataClassCaseInsensitive() {
|
||||||
|
$list = DataList::create('dataobjecttest_teamcomment');
|
||||||
|
$this->assertTrue($list->exists());
|
||||||
|
}
|
||||||
|
|
||||||
public function testClone() {
|
public function testClone() {
|
||||||
$list = DataObjectTest_TeamComment::get();
|
$list = DataObjectTest_TeamComment::get();
|
||||||
$this->assertEquals($list, clone($list));
|
$this->assertEquals($list, clone($list));
|
||||||
|
@ -61,6 +61,30 @@ class DataObjectTest extends SapphireTest {
|
|||||||
$this->assertEquals('Comment', key($dbFields), 'DataObject::db returns fields in correct order');
|
$this->assertEquals('Comment', key($dbFields), 'DataObject::db returns fields in correct order');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructAcceptsValues() {
|
||||||
|
// Values can be an array...
|
||||||
|
$player = new DataObjectTest_Player(array(
|
||||||
|
'FirstName' => 'James',
|
||||||
|
'Surname' => 'Smith'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals('James', $player->FirstName);
|
||||||
|
$this->assertEquals('Smith', $player->Surname);
|
||||||
|
|
||||||
|
// ... or a stdClass inst
|
||||||
|
$data = new stdClass();
|
||||||
|
$data->FirstName = 'John';
|
||||||
|
$data->Surname = 'Doe';
|
||||||
|
$player = new DataObjectTest_Player($data);
|
||||||
|
|
||||||
|
$this->assertEquals('John', $player->FirstName);
|
||||||
|
$this->assertEquals('Doe', $player->Surname);
|
||||||
|
|
||||||
|
// IDs should be stored as integers, not strings
|
||||||
|
$player = new DataObjectTest_Player(array('ID' => '5'));
|
||||||
|
$this->assertSame(5, $player->ID);
|
||||||
|
}
|
||||||
|
|
||||||
public function testValidObjectsForBaseFields() {
|
public function testValidObjectsForBaseFields() {
|
||||||
$obj = new DataObjectTest_ValidatedObject();
|
$obj = new DataObjectTest_ValidatedObject();
|
||||||
|
|
||||||
|
@ -36,6 +36,22 @@ class StringFieldTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExists() {
|
||||||
|
// True exists
|
||||||
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', true)->exists());
|
||||||
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', '0')->exists());
|
||||||
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', '1')->exists());
|
||||||
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', 1)->exists());
|
||||||
|
$this->assertTrue(DBField::create_field('StringFieldTest_MyStringField', 1.1)->exists());
|
||||||
|
|
||||||
|
// false exists
|
||||||
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', false)->exists());
|
||||||
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', '')->exists());
|
||||||
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', null)->exists());
|
||||||
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', 0)->exists());
|
||||||
|
$this->assertFalse(DBField::create_field('StringFieldTest_MyStringField', 0.0)->exists());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringFieldTest_MyStringField extends StringField implements TestOnly {
|
class StringFieldTest_MyStringField extends StringField implements TestOnly {
|
||||||
|
105
tests/search/FulltextFilterTest.php
Executable file
105
tests/search/FulltextFilterTest.php
Executable file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class FulltextFilterTest extends SapphireTest {
|
||||||
|
|
||||||
|
protected $extraDataObjects = array(
|
||||||
|
'FulltextFilterTest_DataObject'
|
||||||
|
);
|
||||||
|
|
||||||
|
protected static $fixture_file = "FulltextFilterTest.yml";
|
||||||
|
|
||||||
|
public function testFilter() {
|
||||||
|
if(DB::getConn() instanceof MySQLDatabase) {
|
||||||
|
$baseQuery = FulltextFilterTest_DataObject::get();
|
||||||
|
$this->assertEquals(3, $baseQuery->count(), "FulltextFilterTest_DataObject count does not match.");
|
||||||
|
|
||||||
|
// First we'll text the 'SearchFields' which has been set using an array
|
||||||
|
$search = $baseQuery->filter("SearchFields:fulltext", 'SilverStripe');
|
||||||
|
$this->assertEquals(1, $search->count());
|
||||||
|
|
||||||
|
$search = $baseQuery->exclude("SearchFields:fulltext", "SilverStripe");
|
||||||
|
$this->assertEquals(2, $search->count());
|
||||||
|
|
||||||
|
// Now we'll run the same tests on 'OtherSearchFields' which should yield the same resutls
|
||||||
|
// but has been set using a string.
|
||||||
|
$search = $baseQuery->filter("OtherSearchFields:fulltext", 'SilverStripe');
|
||||||
|
$this->assertEquals(1, $search->count());
|
||||||
|
|
||||||
|
$search = $baseQuery->exclude("OtherSearchFields:fulltext", "SilverStripe");
|
||||||
|
$this->assertEquals(2, $search->count());
|
||||||
|
|
||||||
|
// Search on a single field
|
||||||
|
$search = $baseQuery->filter("ColumnE:fulltext", 'Dragons');
|
||||||
|
$this->assertEquals(1, $search->count());
|
||||||
|
|
||||||
|
$search = $baseQuery->exclude("ColumnE:fulltext", "Dragons");
|
||||||
|
$this->assertEquals(2, $search->count());
|
||||||
|
} else {
|
||||||
|
$this->markTestSkipped("FulltextFilter only supports MySQL syntax.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGenerateQuery() {
|
||||||
|
// Test SearchFields
|
||||||
|
$filter1 = new FulltextFilter('SearchFields', 'SilverStripe');
|
||||||
|
$filter1->setModel('FulltextFilterTest_DataObject');
|
||||||
|
$query1 = FulltextFilterTest_DataObject::get()->dataQuery();
|
||||||
|
$filter1->apply($query1);
|
||||||
|
$this->assertEquals('"ColumnA", "ColumnB"', $filter1->getDbName());
|
||||||
|
$this->assertEquals(
|
||||||
|
array("MATCH (\"ColumnA\", \"ColumnB\") AGAINST ('SilverStripe')"),
|
||||||
|
$query1->query()->getWhere()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Test Other searchfields
|
||||||
|
$filter2 = new FulltextFilter('OtherSearchFields', 'SilverStripe');
|
||||||
|
$filter2->setModel('FulltextFilterTest_DataObject');
|
||||||
|
$query2 = FulltextFilterTest_DataObject::get()->dataQuery();
|
||||||
|
$filter2->apply($query2);
|
||||||
|
$this->assertEquals('"ColumnC", "ColumnD"', $filter2->getDbName());
|
||||||
|
$this->assertEquals(
|
||||||
|
array("MATCH (\"ColumnC\", \"ColumnD\") AGAINST ('SilverStripe')"),
|
||||||
|
$query2->query()->getWhere()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test fallback to single field
|
||||||
|
$filter3 = new FulltextFilter('ColumnA', 'SilverStripe');
|
||||||
|
$filter3->setModel('FulltextFilterTest_DataObject');
|
||||||
|
$query3 = FulltextFilterTest_DataObject::get()->dataQuery();
|
||||||
|
$filter3->apply($query3);
|
||||||
|
$this->assertEquals('"FulltextFilterTest_DataObject"."ColumnA"', $filter3->getDbName());
|
||||||
|
$this->assertEquals(
|
||||||
|
array("MATCH (\"FulltextFilterTest_DataObject\".\"ColumnA\") AGAINST ('SilverStripe')"),
|
||||||
|
$query3->query()->getWhere()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class FulltextFilterTest_DataObject extends DataObject implements TestOnly {
|
||||||
|
|
||||||
|
private static $db = array(
|
||||||
|
"ColumnA" => "Varchar(255)",
|
||||||
|
"ColumnB" => "HTMLText",
|
||||||
|
"ColumnC" => "Varchar(255)",
|
||||||
|
"ColumnD" => "HTMLText",
|
||||||
|
"ColumnE" => 'Varchar(255)'
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $indexes = array(
|
||||||
|
'SearchFields' => array(
|
||||||
|
'type' => 'fulltext',
|
||||||
|
'name' => 'SearchFields',
|
||||||
|
'value' => '"ColumnA", "ColumnB"',
|
||||||
|
),
|
||||||
|
'OtherSearchFields' => 'fulltext ("ColumnC", "ColumnD")',
|
||||||
|
'SingleIndex' => 'fulltext ("ColumnE")'
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $create_table_options = array(
|
||||||
|
"MySQLDatabase" => "ENGINE=MyISAM",
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
19
tests/search/FulltextFilterTest.yml
Normal file
19
tests/search/FulltextFilterTest.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
FulltextFilterTest_DataObject:
|
||||||
|
object1:
|
||||||
|
ColumnA: 'SilverStripe'
|
||||||
|
CluumnB: '<p>Some content about SilverStripe.</p>'
|
||||||
|
ColumnC: 'SilverStripe'
|
||||||
|
ColumnD: '<p>Some content about SilverStripe.</p>'
|
||||||
|
ColumnE: 'Dragons be here'
|
||||||
|
object2:
|
||||||
|
ColumnA: 'Test Row'
|
||||||
|
ColumnB: '<p>Some information about this test row.</p>'
|
||||||
|
ColumnC: 'Test Row'
|
||||||
|
ColumnD: '<p>Some information about this test row.</p>'
|
||||||
|
ColumnE: 'No'
|
||||||
|
object3:
|
||||||
|
ColumnA: 'Fulltext Search'
|
||||||
|
ColumnB: '<p>Testing fulltext search.</p>'
|
||||||
|
ColumnC: 'Fulltext Search'
|
||||||
|
ColumnD: '<p>Testing fulltext search.</p>'
|
||||||
|
ColumnE: ''
|
@ -1 +1 @@
|
|||||||
$Title <% if ArgA %>- $ArgA <% end_if %>- <%if First %>First-<% end_if %><% if Last %>Last-<% end_if %><%if MultipleOf(2) %>EVEN<% else %>ODD<% end_if %> top:$Top.Title
|
<% if $Title %>$Title<% else %>Untitled<% end_if %> <% if $ArgA %>_ $ArgA <% end_if %>- <% if $First %>First-<% end_if %><% if $Last %>Last-<% end_if %><%if $MultipleOf(2) %>EVEN<% else %>ODD<% end_if %> top:$Top.Title
|
||||||
|
@ -52,18 +52,46 @@ class SSViewerTest extends SapphireTest {
|
|||||||
|
|
||||||
// reset results for the tests that include arguments (the title is passed as an arg)
|
// reset results for the tests that include arguments (the title is passed as an arg)
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Item 1 - Item 1 - First-ODD top:Item 1',
|
'Item 1 _ Item 1 - First-ODD top:Item 1',
|
||||||
'Item 2 - Item 2 - EVEN top:Item 2',
|
'Item 2 _ Item 2 - EVEN top:Item 2',
|
||||||
'Item 3 - Item 3 - ODD top:Item 3',
|
'Item 3 _ Item 3 - ODD top:Item 3',
|
||||||
'Item 4 - Item 4 - EVEN top:Item 4',
|
'Item 4 _ Item 4 - EVEN top:Item 4',
|
||||||
'Item 5 - Item 5 - ODD top:Item 5',
|
'Item 5 _ Item 5 - ODD top:Item 5',
|
||||||
'Item 6 - Item 6 - Last-EVEN top:Item 6',
|
'Item 6 _ Item 6 - Last-EVEN top:Item 6',
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
|
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
|
||||||
$this->assertExpectedStrings($result, $expected);
|
$this->assertExpectedStrings($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIncludeTruthyness() {
|
||||||
|
$data = new ArrayData(array(
|
||||||
|
'Title' => 'TruthyTest',
|
||||||
|
'Items' => new ArrayList(array(
|
||||||
|
new ArrayData(array('Title' => 'Item 1')),
|
||||||
|
new ArrayData(array('Title' => '')),
|
||||||
|
new ArrayData(array('Title' => true)),
|
||||||
|
new ArrayData(array('Title' => false)),
|
||||||
|
new ArrayData(array('Title' => null)),
|
||||||
|
new ArrayData(array('Title' => 0)),
|
||||||
|
new ArrayData(array('Title' => 7))
|
||||||
|
))
|
||||||
|
));
|
||||||
|
$result = $data->renderWith('SSViewerTestIncludeScopeInheritanceWithArgs');
|
||||||
|
|
||||||
|
// We should not end up with empty values appearing as empty
|
||||||
|
$expected = array(
|
||||||
|
'Item 1 _ Item 1 - First-ODD top:Item 1',
|
||||||
|
'Untitled - EVEN top:',
|
||||||
|
'1 _ 1 - ODD top:1',
|
||||||
|
'Untitled - EVEN top:',
|
||||||
|
'Untitled - ODD top:',
|
||||||
|
'Untitled - EVEN top:0',
|
||||||
|
'7 _ 7 - Last-ODD top:7'
|
||||||
|
);
|
||||||
|
$this->assertExpectedStrings($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
private function getScopeInheritanceTestData() {
|
private function getScopeInheritanceTestData() {
|
||||||
return new ArrayData(array(
|
return new ArrayData(array(
|
||||||
'Title' => 'TopTitleValue',
|
'Title' => 'TopTitleValue',
|
||||||
|
@ -441,6 +441,15 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the injected value
|
||||||
|
*
|
||||||
|
* @param string $property Name of property
|
||||||
|
* @param array $params
|
||||||
|
* @param bool $cast If true, an object is always returned even if not an object.
|
||||||
|
* @return array Result array with the keys 'value' for raw value, or 'obj' if contained in an object
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
public function getInjectedValue($property, $params, $cast = true) {
|
public function getInjectedValue($property, $params, $cast = true) {
|
||||||
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
$on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
||||||
|
|
||||||
@ -524,32 +533,25 @@ class SSViewer_DataPresenter extends SSViewer_Scope {
|
|||||||
if (isset($arguments[1]) && $arguments[1] != null) $params = $arguments[1];
|
if (isset($arguments[1]) && $arguments[1] != null) $params = $arguments[1];
|
||||||
else $params = array();
|
else $params = array();
|
||||||
|
|
||||||
$hasInjected = $res = null;
|
$val = $this->getInjectedValue($property, $params);
|
||||||
|
if ($val) {
|
||||||
if ($name == 'hasValue') {
|
|
||||||
if ($val = $this->getInjectedValue($property, $params, false)) {
|
|
||||||
$hasInjected = true; $res = (bool)$val['value'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { // XML_val
|
|
||||||
if ($val = $this->getInjectedValue($property, $params)) {
|
|
||||||
$hasInjected = true;
|
|
||||||
$obj = $val['obj'];
|
$obj = $val['obj'];
|
||||||
|
if ($name === 'hasValue') {
|
||||||
|
$res = $obj instanceof Object
|
||||||
|
? $obj->exists()
|
||||||
|
: (bool)$obj;
|
||||||
|
} else {
|
||||||
|
// XML_val
|
||||||
$res = $obj->forTemplate();
|
$res = $obj->forTemplate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($hasInjected) {
|
|
||||||
$this->resetLocalScope();
|
$this->resetLocalScope();
|
||||||
return $res;
|
return $res;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return parent::__call($name, $arguments);
|
return parent::__call($name, $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a template file with an *.ss file extension.
|
* Parses a template file with an *.ss file extension.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user