Skip to content

Commit

Permalink
API Enforce default_cast for all field usages
Browse files Browse the repository at this point in the history
API Introduce HTMLFragment as casting helper for HTMLText with shortcodes disabled
API Introduce DBField::CDATA for XML file value encoding
API RSSFeed now casts from the underlying model rather than by override
API Introduce CustomMethods::getExtraMethodConfig() to allow metadata to be queried
BUG Remove _call hack from VirtualPage
API Remove FormField::$dontEscape
API Introduce HTMLReadonlyField for non-editable readonly HTML
API FormField::Field() now returns string in many cases rather than DBField instance.
API Remove redundant *_val methods from ViewableData
API ViewableData::obj() no longer has a $forceReturnObject parameter as it always returns an object
BUG  Fix issue with ViewableData caching incorrect field values after being modified.
API Remove deprecated DB class methods
API Enforce plain text left/right formfield titles
  • Loading branch information
Damian Mooyman committed Jul 12, 2016
1 parent 1174385 commit e3afabe
Show file tree
Hide file tree
Showing 70 changed files with 1,447 additions and 1,283 deletions.
40 changes: 22 additions & 18 deletions ORM/Connect/DBSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Object;
use Director;
use SilverStripe\ORM\FieldType\DBPrimaryKey;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBPrimaryKey;


/**
* Represents and handles all schema management for a database
Expand Down Expand Up @@ -110,8 +113,7 @@ public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR) {
/**
* Initiates a schema update within a single callback
*
* @var callable $callback
* @throws Exception
* @param callable $callback
*/
public function schemaUpdate($callback) {
// Begin schema update
Expand Down Expand Up @@ -153,15 +155,10 @@ public function schemaUpdate($callback) {
break;
}
}
} catch(Exception $ex) {
$error = $ex;
}
// finally {
} finally {
$this->schemaUpdateTransaction = null;
$this->schemaIsUpdating = false;
// }

if($error) throw $error;
}
}

/**
Expand Down Expand Up @@ -303,7 +300,7 @@ protected function transInitTable($table) {
* - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full
* control over the index.
* @param boolean $hasAutoIncPK A flag indicating that the primary key on this table is an autoincrement type
* @param string|array $options SQL statement to append to the CREATE TABLE call.
* @param array $options Create table options (ENGINE, etc.)
* @param array|bool $extensions List of extensions
*/
public function requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK = true,
Expand All @@ -314,7 +311,7 @@ public function requireTable($table, $fieldSchema = null, $indexSchema = null, $
$this->alterationMessage("Table $table: created", "created");
} else {
if (Config::inst()->get('SilverStripe\ORM\Connect\DBSchemaManager', 'check_and_repair_on_build')) {
$this->checkAndRepairTable($table, $options);
$this->checkAndRepairTable($table);
}

// Check if options changed
Expand Down Expand Up @@ -353,12 +350,14 @@ public function requireTable($table, $fieldSchema = null, $indexSchema = null, $
$fieldSpec = substr($fieldSpec, 0, $pos);
}

/** @var DBField $fieldObj */
$fieldObj = Object::create_from_string($fieldSpec, $fieldName);
$fieldObj->arrayValue = $arrayValue;
$fieldObj->setArrayValue($arrayValue);

$fieldObj->setTable($table);

if($fieldObj instanceof DBPrimaryKey) {
/** @var DBPrimaryKey $fieldObj */
$fieldObj->setAutoIncrement($hasAutoIncPK);
}

Expand All @@ -383,7 +382,7 @@ public function dontRequireTable($table) {
$suffix = '';
while (isset($this->tableList[strtolower("_obsolete_{$table}$suffix")])) {
$suffix = $suffix
? ($suffix + 1)
? ((int)$suffix + 1)
: 2;
}
$this->renameTable($table, "_obsolete_{$table}$suffix");
Expand Down Expand Up @@ -414,6 +413,8 @@ public function requireIndex($table, $index, $spec) {
$specString = $this->convertIndexSpec($spec);

// Check existing index
$oldSpecString = null;
$indexKey = null;
if (!$newTable) {
$indexKey = $this->indexKey($table, $index, $spec);
$indexList = $this->indexList($table);
Expand Down Expand Up @@ -502,6 +503,7 @@ protected function determineIndexType($spec) {
* Converts an array or string index spec into a universally useful array
*
* @see convertIndexSpec() for approximate inverse
* @param string $name Index name
* @param string|array $spec
* @return array The resulting spec array with the required fields name, type, and value
*/
Expand Down Expand Up @@ -544,7 +546,9 @@ protected function parseIndexSpec($name, $spec) {
*/
protected function convertIndexSpec($indexSpec) {
// Return already converted spec
if (!is_array($indexSpec)) return $indexSpec;
if (!is_array($indexSpec)) {
return $indexSpec;
}

// Combine elements into standard string format
return "{$indexSpec['type']} ({$indexSpec['value']})";
Expand Down Expand Up @@ -647,7 +651,7 @@ public function requireField($table, $field, $spec) {
$new = preg_split("/'\s*,\s*'/", $newStr);

$oldStr = preg_replace("/(^$enumtype\s*\(')|('$\).*)/i", "", $fieldValue);
$old = preg_split("/'\s*,\s*'/", $newStr);
$old = preg_split("/'\s*,\s*'/", $oldStr);

$holder = array();
foreach ($old as $check) {
Expand Down Expand Up @@ -690,7 +694,7 @@ public function dontRequireField($table, $fieldName) {
$suffix = '';
while (isset($fieldList[strtolower("_obsolete_{$fieldName}$suffix")])) {
$suffix = $suffix
? ($suffix + 1)
? ((int)$suffix + 1)
: 2;
}
$this->renameField($table, $fieldName, "_obsolete_{$fieldName}$suffix");
Expand Down Expand Up @@ -942,10 +946,10 @@ abstract public function fieldList($table);
* This allows the cached values for a table's field list to be erased.
* If $tablename is empty, then the whole cache is erased.
*
* @param string|bool $tableName
* @param string $tableName
* @return boolean
*/
public function clearCachedFieldlist($tableName = false) {
public function clearCachedFieldlist($tableName = null) {
return true;
}

Expand Down
Loading

0 comments on commit e3afabe

Please sign in to comment.