Project

General

Profile

Feature #23919 ยป 0016225.patch

Administrator Admin, 2010-11-02 21:12

View differences:

typo3/sysext/install/mod/class.tx_install.php (Arbeitskopie)
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_statictemplates.php');
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_t3skin.php');
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_compressionlevel.php');
require_once(t3lib_extMgm::extPath('install') . 'updates/class.tx_coreupdates_migrateworkspaces.php');
/**
* Install Tool module
typo3/sysext/install/updates/class.tx_coreupdates_migrateworkspaces.php (Revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Tolleiv Nietsch <info@tolleiv.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Migrates workspaces from TYPO3 versions below 4.5.
*
* @author Tolleiv Nietsch <info@tolleiv.de>
* @version $Id$
*/
class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
public $versionNumber; // version number coming from t3lib_div::int_from_ver()
/**
* parent object
*
* @var tx_install
*/
public $pObj;
public $userInput; // user input
public $sqlQueries;
/**
* Checks if an update is needed
*
* @param string &$description: The description for the update
* @return boolean whether an update is needed (true) or not (false)
*/
public function checkForUpdate(&$description) {
$result = false;
$description = 'Migrates the old hardcoded draft workspace to be a real workspace element';
if ($this->versionNumber >= 4005000) {
$this->includeTCA();
$result = $this->isDraftWorkspaceUsed();
}
return $result;
}
/**
* @param string $inputPrefix
* @return void
*/
public function getUserInput($inputPrefix) {
return;
}
/**
* Performs the database update. Changes existing workspaces to use the new custom workspaces
*
* @param array &$dbQueries: queries done in this update
* @param mixed &$customMessages: custom messages
* @return boolean whether it worked (true) or not (false)
*/
public function performUpdate(&$dbQueries, &$customMessages) {
$result = TRUE;
if($this->versionNumber < 4005000) {
return FALSE;
}
// There's no TCA available yet
$this->includeTCA();
// install version extension (especially when updating from very old TYPO3 versions
$this->installExtensions(array('version'));
// create a new dedicated "Draft" workspace and move all records to that new workspace
if ($this->isDraftWorkspaceUsed()) {
$draftWsId = $this->createWorkspace();
if (is_integer($draftWsId)) {
$this->migrateDraftWorkspaceRecordsToWorkspace($draftWsId);
}
}
if (is_array($this->sqlQueries) && is_array($dbQueries)) {
$dbQueries = array_merge($dbQueries, $this->sqlQueries);
}
return $result;
}
/**
* Install a extensions
*
* @param string The extension key
* @return boolean Determines whether this was successful or not
*/
protected function installExtensions($extArr) {
if (!is_array($extArr)) {
return false;
}
$extList = $this->addExtToList($extArr);
if ($extList) {
$this->writeNewExtensionList($extList);
$result = true;
}
return $result;
}
/**
* Check if any table contains draft-workspace records
*
* @params void
* @return bool
*/
protected function isDraftWorkspaceUsed() {
$foundDraftRecords = FALSE;
$tables = array_keys($GLOBALS['TCA']);
foreach($tables as $table) {
$versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
if ($versioningVer > 0) {
if ($this->hasElementsOnWorkspace($table, -1)) {
$foundDraftRecords = TRUE;
break;
}
}
}
return $foundDraftRecords;
}
/**
* Create a real workspace named "Draft"
*
* @param void
* @return integer
*/
protected function createWorkspace() {
// @todo who are the reviewers and owners for this workspace?
// In previous versions this was defined in be_groups/be_users with the setting "Edit in Draft"
$data = array(
'title' => 'Draft'
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_workspace', $data);
$this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
return $GLOBALS['TYPO3_DB']->sql_insert_id();
}
/**
* Migrates all elements from the old draft workspace to the new one.
*
* @param integer $wsId
* @return void
*/
protected function migrateDraftWorkspaceRecordsToWorkspace($wsId) {
$tables = array_keys($GLOBALS['TCA']);
$where = 't3ver_wsid=-1 AND deleted=0';
$values = array(
't3ver_wsid' => intval($wsId)
);
foreach($tables as $table) {
$versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
if ($versioningVer > 0 && $this->hasElementsOnWorkspace($table, -1)) {
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $values);
$this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
}
}
}
/**
* Includes the TCA definition of installed extensions.
*
* @return void
*/
protected function includeTCA() {
global $TCA; // this is relevant because it's used within the included ext_tables.php files - do NOT remove it
include_once(TYPO3_tables_script ? PATH_typo3conf . TYPO3_tables_script : PATH_t3lib . 'stddb/tables.php');
// Extension additions
if ($GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']) {
include_once(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_tables.php');
} else {
include_once(PATH_t3lib . 'stddb/load_ext_tables.php');
}
}
/**
* Determines whether a table has elements in a particular workspace.
*
* @param string $table Name of the table
* @param integer $workspaceId Id of the workspace
* @return boolean
*/
protected function hasElementsOnWorkspace($table, $workspaceId) {
$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'uid',
$table,
'deleted=0 AND t3ver_wsid=' . intval($workspaceId)
);
$this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
return ($count > 0);
}
}
?>
typo3/sysext/install/ext_localconf.php (Arbeitskopie)
// Version 4.4: warn for set CompressionLevel and warn user to update his .htaccess
$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['checkForCompressionLevel'] = 'tx_coreupdates_compressionlevel';
// Version 4.5: migrate workspaces to use custom stages and install the required extensions
$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['migrateWorkspaces'] = 'tx_coreupdates_migrateworkspaces';
?>
    (1-1/1)