Project

General

Profile

« Previous | Next » 

Revision 1916

Added by Dietmar over 11 years ago

! /modules/droplets/ set to version 1.3.0
installing module with sql import
make upgrade.php compatible with upgrade-scrip.php

View differences:

branches/2.8.x/CHANGELOG
12 12
===============================================================================
13 13

  
14 14

  
15
07 Jun-2013 Build 1916 Dietmar Woellbrink (Luisehahne)
16
! /modules/droplets/ set to version 1.3.0
17
  installing module with sql import
18
  make upgrade.php compatible with upgrade-scrip.php
15 19
07 Jun-2013 Build 1915 Dietmar Woellbrink (Luisehahne)
16 20
! recoding /modules/code/add.php with exception
17 21
07 Jun-2013 Build 1914 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1915');
54
if(!defined('REVISION')) define('REVISION', '1916');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/modules/droplets/info.php
5 5
 * @package         droplet
6 6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7 7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
8
 * @copyright       2009-2013, Website Baker Org. e.V.
9
 * @link            http://www.websitebaker.org/
11 10
 * @license         http://www.gnu.org/licenses/gpl.html
12 11
 * @platform        WebsiteBaker 2.8.x
13 12
 * @requirements    PHP 5.2.2 and higher
14 13
 * @version         $Id$
15
 * @filesource		$HeadURL$
14
 * @filesource      $HeadURL$
16 15
 * @lastmodified    $Date$
17 16
 *
18 17
 */
......
28 27
$module_directory = 'droplets';
29 28
$module_name = 'Droplets';
30 29
$module_function = 'tool';
31
$module_version = '1.2.0';
30
$module_version = '1.3.0';
32 31
$module_platform = '2.8.x';
33 32
$module_author = 'Ruud and pcwacht';
34 33
$module_license = 'GNU General Public License';
branches/2.8.x/wb/modules/droplets/droplets.functions.php
1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         droplet
6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7
 * @author          WebsiteBaker Project
8
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
9
 * @link            http://www.websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: upgrade.php 1717 2012-08-29 14:09:09Z Luisehahne $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb_svn/wb280/branches/2.8.x/wb/modules/droplets/upgrade.php $
15
 * @lastmodified    $Date: 2012-08-29 16:09:09 +0200 (Mi, 29. Aug 2012) $
16
 *
17
 */
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(!defined('WB_PATH')) {
21

  
22
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
23
	throw new IllegalFileException();
24
}
25

  
26
/* -------------------------------------------------------- */
27

  
28
function prepareDropletToFile($aDroplet) {
29
	$retVal = '';
30
	$sDescription = '//:'.($aDroplet['description']!='') ? $aDroplet['description']: 'Desription';
31
	$sComments = '';
32
	$aComments = explode("\n",$aDroplet['comments']);
33
	$sCode = '';
34
	$aCode = explode("\n",$aDroplet['code']);
35
	if( (sizeof($aComments)) ){
36
		foreach($aComments AS $isComment) {
37
			$sComments .= '//:'.$isComment;
38
		}
39
	} else {
40
		$sComments .= '//:use [['.$aDroplet['name'].']]';
41
	}
42
	if( (sizeof($aCode)) ){
43
		foreach($aCode AS $isCode) {
44
			$sCode .= $isCode;
45
		}
46
	}
47
 
48
	$retVal = $sDescription."\n".$sComments."\n".$sCode;
49
	return $retVal;
50
}
51
// 
52
function backupDropletFromDatabase($sTmpDir) {
53
	$retVal = '';
54
	$database=WbDatabase::getInstance();
55
	$sql = 'SELECT `name`,`description`,`comments`,`code`  FROM `'.$database->TablePrefix.'mod_droplets` '
56
	     . 'ORDER BY `modified_when` DESC';
57
	if( $oRes = $database->query($sql) ) {
58
		while($aDroplet = $oRes->fetchRow(MYSQL_ASSOC)) {
59
			$sData = prepareDropletToFile($aDroplet);
60
			$sFileName = $sTmpDir.$aDroplet['name'].'.php';
61
			if(file_put_contents($sFileName,$sData)) {
62
				$retVal .= $sFileName.',';
63
			}
64
		}
65
		
66
	}
67
	return $retVal;
68
}
69

  
70

  
71
function insertDropletFile($aDropletFiles,&$msg,$bOverwriteDroplets,$admin)
72
{
73
	$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
74
	$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
75
	$database=WbDatabase::getInstance();
76
	foreach ($aDropletFiles as $sDropletFile) {
77
		$msgSql = '';
78
		$extraSql = '';
79
		$sDropletName = pathinfo ($sDropletFile, PATHINFO_FILENAME);
80
		$sql = 'SELECT `code` FROM `'.$database->TablePrefix.'mod_droplets` WHERE `name` LIKE "'.$sDropletName.'" ';
81
		if( !($database->get_one($sql)) ) {
82
			$sql = 'INSERT INTO `'.$database->TablePrefix.'mod_droplets`';
83
			$msgSql = 'INSERT Droplet `'.$sDropletName.'` INTO`'.$database->TablePrefix.'mod_droplets`'." $OK";
84
		} elseif ($bOverwriteDroplets) {
85
			$sql = 'UPDATE `'.$database->TablePrefix.'mod_droplets` ';
86
			$extraSql = 'WHERE `name` = \''.$sDropletName.'\' ';
87
			$msgSql = 'UPDATE Droplet `'.$sDropletName.'` INTO`'.$database->TablePrefix.'mod_droplets`'." $OK";
88
		}
89
// get description, comments and oode
90
		$sDropletFile = preg_replace('/^\xEF\xBB\xBF/', '', $sDropletFile);
91
		if( ($msgSql!='') && ($aFileData = file($sDropletFile)) ) {
92
			$bDescription = false;
93
			$bComments = false;
94
			$bCode = false;
95
			$sDescription = '';
96
			$sComments = '';
97
			$sCode = '';
98
			$sPattern = "#//:#im";
99
			while ( sizeof($aFileData) > 0 ) {
100
				$sSqlLine = trim(array_shift($aFileData));
101
				$isNotCode = (bool)preg_match($sPattern, $sSqlLine);
102
				if( $isNotCode==true ) {
103
// first step line is description
104
					if($bDescription==false) {
105
						$sDescription .= str_replace('//:','',$sSqlLine);
106
						$bDescription = true;
107
					} else {
108
// second step fill comments
109
						$sComments .= str_replace('//:','',$sSqlLine).PHP_EOL;
110
					}
111
				} else {
112
// third step fill code
113
					$sCode .= str_replace('//:','',$sSqlLine).PHP_EOL;
114
				}
115
			}
116
		$iModifiedWhen = time();
117
		$iModifiedBy = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
118
		$sql .= 'SET  `name` =\''.$sDropletName.'\','
119
		     .       '`description` =\''.$sDescription.'\','
120
		     .       '`comments` =\''.$sComments.'\','
121
		     .       '`code` =\''.$database->escapeString($sCode).'\','
122
		     .       '`modified_when` = '.$iModifiedWhen.','
123
		     .       '`modified_by` = '.$iModifiedBy.','
124
		     .       '`active` = 1'
125
		     .       $extraSql;
126
		}
127
		if( $database->query($sql) ) {
128
			if( $msgSql!='' ) { $msg[] = $msgSql; }
129
		} else {
130
			$msg[] = $database->get_error();
131
		}
132
	}
133
	return;
134
}
135
/* -------------------------------------------------------- */
136

  
137
function isDropletFile($sFileName)
138
{
139
	$bRetval = false;
140
	$matches = array();
141
	if(($sFileData = file_get_contents($sFileName)) !== false)
142
	{
143
//		$sPattern = "#(?://:)+[\w]*\w?#is";
144
//		$sPattern = "#//:[\w].+#imS";
145
		$sPattern = "#//:#im";
146
		$bRetval = (bool)preg_match_all($sPattern, $sFileData, $matches, PREG_SET_ORDER);
147
	}
148
	return $bRetval;
149
}
150

  
151
/* -------------------------------------------------------- */
152
	function getDropletFromFiles($sBaseDir)
153
	{
154
		$aRetval = array();
155
		$oIterator = new DirectoryIterator($sBaseDir);
156
		foreach ($oIterator as $fileInfo) {
157
		// iterate the directory
158
			if($fileInfo->isDot()) continue;
159
			$sFileName = rtrim(str_replace('\\', '/', $fileInfo->getPathname()), '/');
160
			if($fileInfo->isFile()) {
161
			// only droplets are interesting
162
				if((file_exists($sFileName) && isDropletFile($sFileName))) {
163
				// if dir has no corresponding accessfile remember it
164
					$aRetval[] = $sFileName;
165
				}
166
			}
167
		}
168
		return $aRetval;
169
	}
branches/2.8.x/wb/modules/droplets/install.php
5 5
 * @package         droplet
6 6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7 7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
8
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
9
 * @link            http://www.websitebaker.org/
11 10
 * @license         http://www.gnu.org/licenses/gpl.html
12 11
 * @platform        WebsiteBaker 2.8.x
13 12
 * @requirements    PHP 5.2.2 and higher
14 13
 * @version         $Id$
15
 * @filesource		$HeadURL$
14
 * @filesource      $HeadURL$
16 15
 * @lastmodified    $Date$
17 16
 *
18 17
 */
19 18
/* -------------------------------------------------------- */
20 19
// Must include code to stop this file being accessed directly
21 20
if(!defined('WB_PATH')) {
22

  
23 21
	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
24 22
	throw new IllegalFileException();
25
}
26
/* -------------------------------------------------------- */
27

  
28
	// global $admin;
29

  
23
} else {
24
	if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
25
	$database = WbDatabase::getInstance();
26
	$sError = '';
30 27
	$msg = array();
31
	$sql  = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
32
	if( !$database->query($sql) ) {
33
		$msg[] = $database->get_error();
28
	$sBaseDir = realpath(dirname(__FILE__).'/example/');
29
	$sBaseDir    = rtrim(str_replace('\\', '/', $sBaseDir), '/').'/';
30
	// Create table
31
	if($database->SqlImport(dirname(__FILE__).'/sql/mod_droplet.sql','',false)){
32
		$aDropletFiles = getDropletFromFiles($sBaseDir);
33
		$bOverwriteDroplets = true;
34
		insertDropletFile($aDropletFiles,$msg,$bOverwriteDroplets,$admin);
34 35
	}
35 36

  
36
	$sql  = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( ';
37
	$sql .= '`id` INT NOT NULL auto_increment, ';
38
	$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
39
	$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL , ';
40
	$sql .= '`description` TEXT  CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
41
	$sql .= '`modified_when` INT NOT NULL default \'0\', ';
42
	$sql .= '`modified_by` INT NOT NULL default \'0\', ';
43
	$sql .= '`active` INT NOT NULL default \'0\', ';
44
	$sql .= '`admin_edit` INT NOT NULL default \'0\', ';
45
	$sql .= '`admin_view` INT NOT NULL default \'0\', ';
46
	$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', ';
47
	$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
48
	$sql .= 'PRIMARY KEY ( `id` ) ';
49
	$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
50
	if( !$database->query($sql) ) {
51
		$msg[] = $database->get_error();
52
	}
53

  
54
	//add all droplets from the droplet subdirectory
55
	$folder=opendir(WB_PATH.'/modules/droplets/example/.');
56
	$names = array();
57
	while ($file = readdir($folder)) {
58
		$ext=strtolower(substr($file,-4));
59
		if ($ext==".php"){
60
			if ($file<>"index.php" ) {
61
				$names[count($names)] = $file;
62
			}
63
		}
64
	}
65
	closedir($folder);
66

  
67
	foreach ($names as $dropfile)
68
	{
69
		$droplet = addslashes(getDropletCodeFromFile($dropfile));
70
		if ($droplet != "")
71
		{
72
			$description = "Example Droplet";
73
			$comments = "Example Droplet";
74
			$cArray = explode("\n",$droplet);
75
			if (substr($cArray[0],0,3) == "//:") {
76
				$description = trim(substr($cArray[0],3));
77
				array_shift ( $cArray );
78
			}
79
			if (substr($cArray[0],0,3) == "//:") {
80
				$comments = trim(substr($cArray[0],3));
81
				array_shift ( $cArray );
82
			}
83
			$droplet = implode ( "\n", $cArray );
84
			$name = substr($dropfile,0,-4);
85
			$modified_when = time();
86
			$modified_by = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
87
			$sql  = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET ';
88
			$sql .= '`name` = \''.$name.'\', ';
89
			$sql .= '`code` = \''.$droplet.'\', ';
90
			$sql .= '`description` = \''.$description.'\', ';
91
			$sql .= '`comments` = \''.$comments.'\', ';
92
			$sql .= '`active` = 1, ';
93
			$sql .= '`modified_when` = '.$modified_when.', ';
94
			$sql .= '`modified_by` = '.$modified_by;
95
			if( !$database->query($sql) ) {
96
				$msg[] = $database->get_error();
97
			}
98
			// do not output anything if this script is called during fresh installation
99
			// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
100
		}
101
	}
102

  
103
	function getDropletCodeFromFile ( $dropletfile ) {
104
		$data = '';
105
		$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
106
		if (file_exists($filename)) {
107
			$filehandle = fopen ($filename, "r");
108
			$data = fread ($filehandle, filesize ($filename));
109
			fclose($filehandle);
110
			// unlink($filename); doesnt work in unix
111
		}
112
		return $data;
113
	}
37
}
branches/2.8.x/wb/modules/droplets/sql/mod_droplet.sql
1
-- phpMyAdmin SQL Dump
2
-- Erstellungszeit: 15. Mrz 2013 um 18:21
3
-- Server-Version: 5.5.27
4
--
5
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
6
-- --------------------------------------------------------
7
-- Database structure for WebsiteBaker core
8
--
9
-- Replacements: {TABLE_PREFIX}, {TABLE_ENGINE}, {TABLE_COLLATION}
10
--
11
-- --------------------------------------------------------
12
--
13
-- Tabellenstruktur für Tabelle `{TABLE_PREFIX}mod_droplets`
14
--
15
DROP TABLE IF EXISTS `{TABLE_PREFIX}mod_droplets`;
16
CREATE TABLE IF NOT EXISTS `{TABLE_PREFIX}mod_droplets` (
17
  `id` int(11) NOT NULL AUTO_INCREMENT,
18
  `name` varchar(32){TABLE_COLLATION} NOT NULL DEFAULT '',
19
  `code` longtext{TABLE_COLLATION} NOT NULL DEFAULT '',
20
  `description` text{TABLE_COLLATION} NOT NULL DEFAULT '',
21
  `modified_when` int(11) NOT NULL DEFAULT '0',
22
  `modified_by` int(11) NOT NULL DEFAULT '0',
23
  `active` int(11) NOT NULL DEFAULT '0',
24
  `admin_edit` int(11) NOT NULL DEFAULT '0',
25
  `admin_view` int(11) NOT NULL DEFAULT '0',
26
  `show_wysiwyg` int(11) NOT NULL DEFAULT '0',
27
  `comments` text{TABLE_COLLATION} NOT NULL DEFAULT '',
28
  PRIMARY KEY (`id`)
29
){TABLE_ENGINE};
30
-- EndOfFile
branches/2.8.x/wb/modules/droplets/backup_droplets.php
4 4
 * @category        module
5 5
 * @package         droplet
6 6
 * @author          Ruud Eisinga (Ruud) John (PCWacht), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker.org/
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 9
 * @license         http://www.gnu.org/licenses/gpl.html
10 10
 * @platform        WebsiteBaker 2.8.x
11 11
 * @requirements    PHP 5.2.2 and higher
12 12
 * @version         $Id$
13
 * @filesource		$HeadURL$
13
 * @filesource      $HeadURL$
14 14
 * @lastmodified    $Date$
15 15
 *
16 16
 */
......
20 20
// tool_edit.php
21 21
require_once('../../config.php');
22 22
require_once(WB_PATH.'/framework/class.admin.php');
23
if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
23 24

  
24 25
require_once(WB_PATH.'/framework/functions.php');
25 26
// create admin object depending on platform (admin tools were moved out of settings with WB 2.7)
......
46 47
$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
47 48
$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
48 49
$sBackupName = strftime('%Y%m%d_%H%M%S', time()+ TIMEZONE ).'_droplets.zip';
49
$temp_dir = '/temp/droplets/';
50
$temp_file = $temp_dir.$sBackupName;
51

  
52
if(is_writeable(dirname(WB_PATH.$temp_dir))) {
53
 	rm_full_dir ( WB_PATH.$temp_dir );
50
$tempDir = '/temp/droplets/';
51
$tempFile = $tempDir.$sBackupName;
52
// delete old backup
53
if(is_writeable(dirname(WB_PATH.$tempDir))) {
54
	rm_full_dir ( WB_PATH.$tempDir );
54 55
}
55 56

  
56
/*
57
// make the temporary working directory
58
if(!make_dir(WB_PATH.$temp_dir, octdec('0777') )){
59
//  $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE'], $module_edit_link);
60
}
61
*/
62

  
63
$msg = createFolderProtectFile(rtrim( WB_PATH.$temp_dir,'/') );
57
$msg = createFolderProtectFile(rtrim( WB_PATH.$tempDir,'/') );
64 58
if(sizeof($msg)) {
65 59
	print '<h4 class="warning">';
66 60
	echo implode('<br />',$msg).'<br />'.$MESSAGE['MEDIA_DIR_NOT_MADE'].'<br />';
67 61
	print '</h4>';
68 62
}
69

  
70
	$sFilesToZip = '';
71
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets`  ';
72
	$sql .= 'ORDER BY `modified_when` DESC';
73

  
74
	$query_droplets = $database->query($sql);
75
	while($droplet = $query_droplets->fetchRow()) {
76
		echo 'Saving: '.$droplet["name"].'.php';
77
		$sFile = $droplet["name"].'.php';
78
		if($fh = fopen(WB_PATH.$temp_dir.$sFile, 'w'))
79
		{
80
			fwrite($fh, '//:'.$droplet['description']."\n");
81
			fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
82
			fwrite($fh, $droplet['code']);
83
			fclose($fh);
84
			echo " $OK<br />";
85
		} else {
86
			echo " $FAIL<br />";		}
87
	$sFilesToZip .= WB_PATH.$temp_dir.$sFile.',';
88
	}
89

  
63
$sFilesToZip = backupDropletFromDatabase(WB_PATH.$tempDir);
64
// remove last comma
90 65
$sFilesToZip = rtrim($sFilesToZip,',');
91 66

  
92 67
echo '<br />Create archive: <strong>'.$sBackupName.'</strong><br />';
93 68

  
94
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
95
$archive = new PclZip(WB_PATH.$temp_file);
69
if( !class_exists('PclZip',false) ) { require(WB_PATH.'/include/pclzip/pclzip.lib.php'); }
70
$archive = new PclZip(WB_PATH.$tempFile);
96 71

  
97
$file_list = $archive->create($sFilesToZip , PCLZIP_OPT_REMOVE_ALL_PATH );
98
if ($file_list == 0){
72
$archiveList = $archive->create($sFilesToZip , PCLZIP_OPT_REMOVE_ALL_PATH );
73

  
74
if ($archiveList == 0){
99 75
	echo "Packaging error: '.$archive->errorInfo(true).'";
100 76
	die("Error : ".$archive->errorInfo(true));
101 77
}
102
elseif(is_readable(WB_PATH.$temp_file)) {
103
	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
78
elseif(is_readable(WB_PATH.$tempFile)) {
79
	echo '<br /><ol>';
80
	foreach($archiveList AS $key=>$aDroplet ) {
81
		echo '<li>Backup <strong> '.$aDroplet['stored_filename'].'</strong></li>';
82
	}
83
	echo '</ol><br /><br />Backup created - <a href="'.WB_URL.$tempFile.'">Download</a>';
104 84
}
105 85
else {
106 86
	echo '<br /><br />Backup not created - <a href="'.$module_edit_link.'">'.$TEXT['BACK'].'</a>';
branches/2.8.x/wb/modules/droplets/upgrade.php
5 5
 * @package         droplet
6 6
 * @author          Ruud Eisinga (Ruud) John (PCWacht)
7 7
 * @author          WebsiteBaker Project
8
 * @copyright       2004-2009, Ryan Djurovich
9
 * @copyright       2009-2011, Website Baker Org. e.V.
10
 * @link			http://www.websitebaker2.org/
8
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
9
 * @link            http://www.websitebaker.org/
11 10
 * @license         http://www.gnu.org/licenses/gpl.html
12 11
 * @platform        WebsiteBaker 2.8.x
13 12
 * @requirements    PHP 5.2.2 and higher
14 13
 * @version         $Id$
15
 * @filesource		$HeadURL$
14
 * @filesource      $HeadURL$
16 15
 * @lastmodified    $Date$
17 16
 *
18 17
 */
......
24 23
	throw new IllegalFileException();
25 24
}
26 25
/* -------------------------------------------------------- */
27
$database=WbDatabase::getInstance();
28
$table_name = TABLE_PREFIX .'mod_droplets';
29
$description = 'INT NOT NULL default 0 ';
30
$database->field_add($table_name,'show_wysiwyg',$description.'AFTER `active`' );
31
$database->field_add($table_name,'admin_view',$description.'AFTER `active`' );
32
$database->field_add($table_name,'admin_edit',$description.'AFTER `active`' );
26

  
27
if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
28

  
29
	function mod_droplets_upgrade($bDebug=false) {
30
		global $admin;
31
		$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
32
		$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
33
		$database=WbDatabase::getInstance();
34
		$msg = array();
35
		$callingScript = $_SERVER["SCRIPT_NAME"];
36
		// check if upgrade startet by upgrade-script to echo a message
37
		$tmp = 'upgrade-script.php';
38
		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
39
// check for missing tables, if true stop the upgrade
40
		$aTable = array('mod_droplets');
41
		$aPackage = UpgradeHelper::existsAllTables($aTable);
42
		if( sizeof($aPackage) > 0){
43
			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
44
			$msg[] = 'Droplets upgrade failed'." $FAIL";
45
			if($globalStarted) {
46
				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
47
			}
48
			return ( ($globalStarted==true ) ? $globalStarted : $msg);
49
		} else {
50
			for($x=0; $x<sizeof($aTable);$x++) {
51
				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
52
					if(('myisam' != strtolower($sOldType))) {
53
						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
54
							$msg[] = $database->get_error();
55
						} else{
56
							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
57
						}
58
					} else {
59
						$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
60
					}
61
				} else {
62
					$msg[] = $database->get_error();
63
				}
64
			}
65
			$table_name = $database->TablePrefix.'mod_droplets';
66
			$description = "INT NOT NULL DEFAULT '0' AFTER `active`";
67
			$field_name = 'show_wysiwyg';
68
			if(!$database->field_exists($table_name,$field_name)) {
69
				$database->field_add($table_name, $field_name, $description);
70
				$msg[] = 'Add field `show_wysiwyg` AFTER `active`';
71
			} else {
72
				$msg[] = 'Field `show_wysiwyg` already exists'." $OK";
73
			}
74
			$field_name = 'admin_view';
75
			if(!$database->field_exists($table_name,$field_name)) {
76
				$database->field_add($table_name, $field_name, $description);
77
				$msg[] = 'Add field `admin_view` AFTER `active`';
78
			} else {
79
				$msg[] = 'Field `admin_view` already exists'." $OK";
80
			}
81
			$field_name = 'admin_edit';
82
			if(!$database->field_exists($table_name,$field_name)) {
83
				$database->field_add($table_name, $field_name, $description);
84
				$msg[] = 'Add field `admin_edit` AFTER `active`';
85
			} else {
86
				$msg[] = 'Field `admin_edit` already exists'." $OK";
87
			}
88

  
89
			$sBaseDir = realpath(dirname(__FILE__).'/example/');
90
			$sBaseDir    = rtrim(str_replace('\\', '/', $sBaseDir), '/').'/';
91
			$aDropletFiles = getDropletFromFiles($sBaseDir);
92

  
93
			$bOverwriteDroplets = false;
94
			insertDropletFile($aDropletFiles,$msg,$bOverwriteDroplets,$admin);
95
// only for upgrade-script
96
			if($globalStarted) {
97
				if($bDebug) {
98
					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
99
				}
100
			}
101
		}
102
		$msg[] = 'Droplets upgrade successfull finished ';
103
		if($globalStarted) {
104
			echo "<strong>Droplets upgrade successfull finished $OK</strong><br />";
105
		}
106
		return ( ($globalStarted==true ) ? $globalStarted : $msg);
107
	}
108
// ------------------------------------
109

  
110
$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
111
if( is_array($msg = mod_droplets_upgrade($bDebugModus))) {
112
	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
113
}

Also available in: Unified diff