Extended silverstripe fluent module. Locales data are be stored in seperate tables.
This module is extended from Fluent.
Fluent module is awesome and easy to use. However, all extra locale columns are stored in the same data object table. It could cause MYSQL problems if there are too many columns defined in one table. For example, Row size too large error.
This module extends Fluent feature and locale data are stored in separated table with locale name suffix.
composer require internetrix/silverstripe-fluent-extra-table:1.0.0
Put code below for tranlsateable versioned data objects.
Fluent:
VersionedFluentDataObjects:
- <DataObject Name>
Need to implement function allVersions() as below in Page.php to avoid error when clicking history on a page.
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "") {
// Make sure the table names are not postfixed (e.g. _Live)
$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage('Stage');
$list = DataObject::get(get_class($this), $filter, $sort, $join, $limit);
if($having) $having = $list->having($having);
$query = $list->dataQuery()->query();
foreach($query->getFrom() as $table => $tableJoin) {
if(is_string($tableJoin) && $tableJoin[0] == '"') {
$baseTable = str_replace('"','',$tableJoin);
} elseif(is_string($tableJoin) && substr($tableJoin,0,5) != 'INNER') {
$query->setFrom(array(
$table => "LEFT JOIN \"$table\" ON \"$table\".\"RecordID\"=\"{$baseTable}_versions\".\"RecordID\""
. " AND \"$table\".\"Version\" = \"{$baseTable}_versions\".\"Version\""
));
}
// fix locale table names
$locale = Fluent::current_locale();
$default = Fluent::default_locale();
if(strpos($table, $locale) !== false){
$table = str_replace('_' . $locale,'',$table);
$query->renameTable($table, $table . '_versions' . '_' . $locale);
} else if (strpos($table, $default) !== false){
$table = str_replace('_' . $default,'',$table);
$query->renameTable($table, $table . '_versions' . '_' . $default);
} else {
$query->renameTable($table, $table . '_versions');
}
}
// Add all <basetable>_versions columns
foreach(Config::inst()->get('Versioned', 'db_for_versions_table') as $name => $type) {
$query->selectField(sprintf('"%s_versions"."%s"', $baseTable, $name), $name);
}
$query->addWhere(array(
"\"{$baseTable}_versions\".\"RecordID\" = ?" => $this->ID
));
$query->setOrderBy(($sort) ? $sort
: "\"{$baseTable}_versions\".\"LastEdited\" DESC, \"{$baseTable}_versions\".\"Version\" DESC");
$records = $query->execute();
$versions = new ArrayList();
foreach($records as $record) {
$versions->push(new Versioned_Version($record));
}
Versioned::set_reading_mode($oldMode);
return $versions;
}
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem