Skip to content

Commit

Permalink
Add update tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
olafgleba committed Dec 5, 2011
1 parent 373bbb7 commit b26aecf
Show file tree
Hide file tree
Showing 2 changed files with 745 additions and 0 deletions.
147 changes: 147 additions & 0 deletions welcompose/update/tasks/0001-012.php
@@ -0,0 +1,147 @@
<?php

/**
* Project: Welcompose
* File: 0001-012.php
*
* Copyright (c) 2009 creatics
*
* Project owner:
* creatics, Olaf Gleba
* 50939 Köln, Germany
* http://www.creatics.de
*
* This file is licensed under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE v3
* http://www.opensource.org/licenses/agpl-v3.html
*
* $Id$
*
* @copyright 2011 creatics, Olaf Gleba
* @author Olaf Gleba
* @package Welcompose
* @license http://www.opensource.org/licenses/agpl-v3.html GNU AFFERO GENERAL PUBLIC LICENSE v3
*/

// get loader
$path_parts = array(
dirname(__FILE__),
'..',
'..',
'core',
'loader.php'
);
$loader_path = implode(DIRECTORY_SEPARATOR, $path_parts);
require($loader_path);

// start base
/* @var $BASE base */
$BASE = load('base:base');

// deregister globals
$deregister_globals_path = dirname(__FILE__).'/../../core/includes/deregister_globals.inc.php';
require(Base_Compat::fixDirectorySeparator($deregister_globals_path));

try {
// start output buffering
@ob_start();

// load smarty
$smarty_update_conf = dirname(__FILE__).'/../smarty.inc.php';
$BASE->utility->loadSmarty(Base_Compat::fixDirectorySeparator($smarty_update_conf), true);

// load gettext
$gettext_path = dirname(__FILE__).'/../../core/includes/gettext.inc.php';
include(Base_Compat::fixDirectorySeparator($gettext_path));
gettextInitSoftware($BASE->_conf['locales']['all']);

// start Base_Session
/* @var $SESSION session */
$SESSION = load('base:session');

// connect to database
$BASE->loadClass('database');

// define major/minor task number
define('TASK_MAJOR', '0001');
define('TASK_MINOR', '012');

// get schema version from database
$sql = "
SELECT
`schema_version`
FROM
".WCOM_DB_APPLICATION_INFO."
LIMIT
1
";
$version = $BASE->db->select($sql, 'field');
list($major, $minor) = explode('-', $version);

/*
* References
* ----------
*
* Commit: 351bf87b80fd3dbc5ae32ee50b159580c2487cce
* Ticket: 15
*
* Changes to be applied
* ---------------------
*
* - Add new field to table 'content_pages'
* `exclude` enum ('0','1')
*/
if ($major < TASK_MAJOR || ($major == TASK_MAJOR && $minor < TASK_MINOR)) {
try {
// begin transaction
$BASE->db->begin();

// add new fields
$sql = "
ALTER TABLE
".WCOM_DB_CONTENT_PAGES."
ADD
`exclude`
ENUM
('0', '1') NULL DEFAULT '0'
AFTER `draft`
";

$BASE->db->execute($sql);

// update schema version
$sqlData = array(
'schema_version' => TASK_MAJOR.'-'.TASK_MINOR
);

$BASE->db->update(WCOM_DB_APPLICATION_INFO, $sqlData);

// commit
$BASE->db->commit();
} catch (Exception $e) {
// do rollback
$BASE->db->rollback();

// re-throw exception
throw $e;
}
}

// flush the buffer
@ob_end_flush();

exit;
} catch (Exception $e) {
// clean the buffer
if (!$BASE->debug_enabled()) {
@ob_end_clean();
}

// raise error
$BASE->error->displayException($e, $BASE->utility->smarty);
$BASE->error->triggerException($e);

// exit
exit;
}

?>

0 comments on commit b26aecf

Please sign in to comment.