Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
// ...
function augmentSQL(SQLQuery &$query) {
// Get the content at a specific date
if($date = Versioned::current_archived_date()) {
foreach($query->from as $table => $dummy) {
if(!isset($baseTable)) {
$baseTable = $table;
}
// Only add the stage if the object is versioned
if( class_exists($table) && Object::has_extension($table, __CLASS__) ) {
$query->renameTable($table, $table . '_versions');
$query->replaceText("\"$table\".\"ID\"", "\"$table\".\"RecordID\"");
// Add all <basetable>_versions columns
foreach(self::$db_for_versions_table as $name => $type) {
$query->select[] = sprintf('"%s_versions"."%s"', $baseTable, $name);
}
$query->select[] = sprintf('"%s_versions"."%s" AS "ID"', $baseTable, 'RecordID');
if($table != $baseTable) {
$query->from[$table] .= " AND \"{$table}_versions\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
}
}
}
// Link to the version archived on that date
$archiveTable = $this->requireArchiveTempTable($baseTable, $date);
$query->from[$archiveTable] = "INNER JOIN \"$archiveTable\"
ON \"$archiveTable\".\"ID\" = \"{$baseTable}_versions\".\"RecordID\"
AND \"$archiveTable\".\"Version\" = \"{$baseTable}_versions\".\"Version\"";
// Get a specific stage
} else if(Versioned::current_stage() && Versioned::current_stage() != $this->defaultStage
&& array_search(Versioned::current_stage(), $this->stages) !== false) {
foreach($query->from as $table => $dummy) {
// Only add the stage if the object is versioned
if( class_exists($table) && Object::has_extension($table, __CLASS__) ) {
$query->renameTable($table, $table . '_' . Versioned::current_stage());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.