| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
     | 
  
  
    | 
      4
     | 
    
       *
 
     | 
  
  
    | 
      5
     | 
    
       * This program is free software: you can redistribute it and/or modify
 
     | 
  
  
    | 
      6
     | 
    
       * it under the terms of the GNU General Public License as published by
 
     | 
  
  
    | 
      7
     | 
    
       * the Free Software Foundation, either version 3 of the License, or
 
     | 
  
  
    | 
      8
     | 
    
       * (at your option) any later version.
 
     | 
  
  
    | 
      9
     | 
    
       *
 
     | 
  
  
    | 
      10
     | 
    
       * This program is distributed in the hope that it will be useful,
 
     | 
  
  
    | 
      11
     | 
    
       * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
     | 
  
  
    | 
      12
     | 
    
       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
     | 
  
  
    | 
      13
     | 
    
       * GNU General Public License for more details.
 
     | 
  
  
    | 
      14
     | 
    
       *
 
     | 
  
  
    | 
      15
     | 
    
       * You should have received a copy of the GNU General Public License
 
     | 
  
  
    | 
      16
     | 
    
       * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      /**
 
     | 
  
  
    | 
      20
     | 
    
       * upgrade.php
 
     | 
  
  
    | 
      21
     | 
    
       * 
 
     | 
  
  
    | 
      22
     | 
    
       * @category     Module
 
     | 
  
  
    | 
      23
     | 
    
       * @package      news
 
     | 
  
  
    | 
      24
     | 
    
       * @subpackage   upgrade
 
     | 
  
  
    | 
      25
     | 
    
       * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
 
     | 
  
  
    | 
      26
     | 
    
       * @author       Werner v.d.Decken <wkl@isteam.de>
 
     | 
  
  
    | 
      27
     | 
    
       * @copyright    Werner v.d.Decken <wkl@isteam.de>
 
     | 
  
  
    | 
      28
     | 
    
       * @license      http://www.gnu.org/licenses/gpl.html   GPL License
 
     | 
  
  
    | 
      29
     | 
    
       * @version      0.0.1
 
     | 
  
  
    | 
      30
     | 
    
       * @revision     $Revision: 1918 $
 
     | 
  
  
    | 
      31
     | 
    
       * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/upgrade.php $
 
     | 
  
  
    | 
      32
     | 
    
       * @lastmodified $Date: 2013-06-07 06:18:18 +0200 (Fri, 07 Jun 2013) $
 
     | 
  
  
    | 
      33
     | 
    
       * @since        File available since 17.01.2013
 
     | 
  
  
    | 
      34
     | 
    
       * @description  xyz
 
     | 
  
  
    | 
      35
     | 
    
       * 
 
     | 
  
  
    | 
      36
     | 
    
       */
 
     | 
  
  
    | 
      37
     | 
    
      
 
     | 
  
  
    | 
      38
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      39
     | 
    
      // Must include code to stop this file being accessed directly
 
     | 
  
  
    | 
      40
     | 
    
      if(!defined('WB_URL')) {
     | 
  
  
    | 
      41
     | 
    
      	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 
     | 
  
  
    | 
      42
     | 
    
      	throw new IllegalFileException();
 
     | 
  
  
    | 
      43
     | 
    
      }
 
     | 
  
  
    | 
      44
     | 
    
      
 
     | 
  
  
    | 
      45
     | 
    
      
 
     | 
  
  
    | 
      46
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      47
     | 
    
      /* **** START UPGRADE ******************************************************* */
 
     | 
  
  
    | 
      48
     | 
    
      //if(!function_exists('mod_news_Upgrade'))
     | 
  
  
    | 
      49
     | 
    
      //{
     | 
  
  
    | 
      50
     | 
    
      	function mod_news_Upgrade($bDebug=false)
 
     | 
  
  
    | 
      51
     | 
    
      	{
     | 
  
  
    | 
      52
     | 
    
      		global $OK ,$FAIL;
 
     | 
  
  
    | 
      53
     | 
    
      		$database=WbDatabase::getInstance();
 
     | 
  
  
    | 
      54
     | 
    
      		$mLang = Translate::getinstance();
 
     | 
  
  
    | 
      55
     | 
    
      		$sModName = basename(dirname(__FILE__));
 
     | 
  
  
    | 
      56
     | 
    
      		$mLang->enableAddon('modules\\'.$sModName);
     | 
  
  
    | 
      57
     | 
    
      		$msg    = array();
 
     | 
  
  
    | 
      58
     | 
    
      		$callingScript = $_SERVER["SCRIPT_NAME"];
 
     | 
  
  
    | 
      59
     | 
    
      // check if upgrade startet by upgrade-script to echo a message
 
     | 
  
  
    | 
      60
     | 
    
      		$tmp = 'upgrade-script.php';
 
     | 
  
  
    | 
      61
     | 
    
      		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
 
     | 
  
  
    | 
      62
     | 
    
      // check for missing tables, if true stop the upgrade
 
     | 
  
  
    | 
      63
     | 
    
      		$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
     | 
  
  
    | 
      64
     | 
    
      		$aPackage = UpgradeHelper::existsAllTables($aTable);
 
     | 
  
  
    | 
      65
     | 
    
      		if( sizeof($aPackage) > 0){
     | 
  
  
    | 
      66
     | 
    
      			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
     | 
  
  
    | 
      67
     | 
    
      			$msg[] = "WYSIWYG upgrade failed $FAIL";
 
     | 
  
  
    | 
      68
     | 
    
      			if($globalStarted) {
     | 
  
  
    | 
      69
     | 
    
      				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
     | 
  
  
    | 
      70
     | 
    
      			}
 
     | 
  
  
    | 
      71
     | 
    
      			$mLang->disableAddon();
 
     | 
  
  
    | 
      72
     | 
    
      			return ( ($globalStarted==true ) ? $globalStarted : $msg);
 
     | 
  
  
    | 
      73
     | 
    
      		} else {
     | 
  
  
    | 
      74
     | 
    
      			/**
 
     | 
  
  
    | 
      75
     | 
    
      			 * check database engine
 
     | 
  
  
    | 
      76
     | 
    
      			 */
 
     | 
  
  
    | 
      77
     | 
    
      			 for($x=0; $x<sizeof($aTable);$x++) {
     | 
  
  
    | 
      78
     | 
    
      				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
     | 
  
  
    | 
      79
     | 
    
      					if(('myisam' != strtolower($sOldType))) {
     | 
  
  
    | 
      80
     | 
    
      						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
     | 
  
  
    | 
      81
     | 
    
      							$msg[] = $database->get_error()." $FAIL";
 
     | 
  
  
    | 
      82
     | 
    
      						} else{
     | 
  
  
    | 
      83
     | 
    
      							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
 
     | 
  
  
    | 
      84
     | 
    
      						}
 
     | 
  
  
    | 
      85
     | 
    
      					} else {
     | 
  
  
    | 
      86
     | 
    
      						 $msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
 
     | 
  
  
    | 
      87
     | 
    
      					}
 
     | 
  
  
    | 
      88
     | 
    
      				} else {
     | 
  
  
    | 
      89
     | 
    
      					$msg[] = $database->get_error()." $FAIL";
 
     | 
  
  
    | 
      90
     | 
    
      				}
 
     | 
  
  
    | 
      91
     | 
    
      			}
 
     | 
  
  
    | 
      92
     | 
    
      
 
     | 
  
  
    | 
      93
     | 
    
      			$sPagesPath = WB_PATH.PAGES_DIRECTORY;
 
     | 
  
  
    | 
      94
     | 
    
      			$sPostsPath = $sPagesPath.'/posts';
 
     | 
  
  
    | 
      95
     | 
    
      // create /posts/ - directory if not exists
 
     | 
  
  
    | 
      96
     | 
    
      			if(is_writable($sPagesPath)) {
     | 
  
  
    | 
      97
     | 
    
      				if(!($bRetval = is_dir($sPostsPath))) {
     | 
  
  
    | 
      98
     | 
    
      					$iOldUmask = umask(0) ;
 
     | 
  
  
    | 
      99
     | 
    
      					// sanitize directory mode to 'o+rwx/g+x/u+x' and create path
 
     | 
  
  
    | 
      100
     | 
    
      					$bRetval = mkdir($sPostsPath, (OCTAL_DIR_MODE |0711), true); 
 
     | 
  
  
    | 
      101
     | 
    
      					umask($iOldUmask);
 
     | 
  
  
    | 
      102
     | 
    
      				}
 
     | 
  
  
    | 
      103
     | 
    
      				if($bRetval) {
     | 
  
  
    | 
      104
     | 
    
      					$msg[] = 'Directory "'.PAGES_DIRECTORY.'/posts/" already exists or created.'." $OK";
 
     | 
  
  
    | 
      105
     | 
    
      				}else {
     | 
  
  
    | 
      106
     | 
    
      					$msg[] = ($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE)." $FAIL";
 
     | 
  
  
    | 
      107
     | 
    
      				}
 
     | 
  
  
    | 
      108
     | 
    
      			}else {
     | 
  
  
    | 
      109
     | 
    
      					$msg[] = ($mLang->MESSAGE_PAGES_CANNOT_CREATE_ACCESS_FILE)." $FAIL";
 
     | 
  
  
    | 
      110
     | 
    
      			}
 
     | 
  
  
    | 
      111
     | 
    
      	// check if new fields must be added
 
     | 
  
  
    | 
      112
     | 
    
      			$doImportDate = true;
 
     | 
  
  
    | 
      113
     | 
    
      			if(!$database->field_exists($database->TablePrefix.'mod_news_posts', 'created_when')) {
     | 
  
  
    | 
      114
     | 
    
      				if(!$database->field_add($database->TablePrefix.'mod_news_posts', 'created_when',
 
     | 
  
  
    | 
      115
     | 
    
      				                        'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
     | 
  
  
    | 
      116
     | 
    
      					$msg[] = $mLang->MESSAGE_RECORD_MODIFIED_FAILED." $FAIL";
 
     | 
  
  
    | 
      117
     | 
    
      				} else {
     | 
  
  
    | 
      118
     | 
    
      					$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_when` added.'." $OK";
 
     | 
  
  
    | 
      119
     | 
    
      				}
 
     | 
  
  
    | 
      120
     | 
    
      			} else { 
     | 
  
  
    | 
      121
     | 
    
      				$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_when` already exists.'." $OK";
 
     | 
  
  
    | 
      122
     | 
    
      				$doImportDate = false; 
 
     | 
  
  
    | 
      123
     | 
    
      			}
 
     | 
  
  
    | 
      124
     | 
    
      
 
     | 
  
  
    | 
      125
     | 
    
      			if(!$database->field_exists($database->TablePrefix.'mod_news_posts', 'created_by')) {
     | 
  
  
    | 
      126
     | 
    
      				if(!$database->field_add($database->TablePrefix.'mod_news_posts', 'created_by',
 
     | 
  
  
    | 
      127
     | 
    
      				                        'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
     | 
  
  
    | 
      128
     | 
    
      					$msg[] = $mLang->MESSAGE_RECORD_MODIFIED_FAILED." $FAIL";
 
     | 
  
  
    | 
      129
     | 
    
      				} else {
     | 
  
  
    | 
      130
     | 
    
      					$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_by` added.'." $OK";
 
     | 
  
  
    | 
      131
     | 
    
      				}
 
     | 
  
  
    | 
      132
     | 
    
      			} else { 
     | 
  
  
    | 
      133
     | 
    
      				$msg[] = 'TABLE `'.$database->TablePrefix.'mod_news_posts` Datafield `created_by` already exists.'." $OK";
 
     | 
  
  
    | 
      134
     | 
    
      				$doImportDate = false; 
 
     | 
  
  
    | 
      135
     | 
    
      			}
 
     | 
  
  
    | 
      136
     | 
    
      // preset new fields `created_by` and `created_by` from existing values
 
     | 
  
  
    | 
      137
     | 
    
      			if($doImportDate) {
     | 
  
  
    | 
      138
     | 
    
      				$sql  = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
 
     | 
  
  
    | 
      139
     | 
    
      				$sql .= 'SET `created_by`=`posted_by`, `created_when`=`posted_when`';
 
     | 
  
  
    | 
      140
     | 
    
      				$database->query($sql);
 
     | 
  
  
    | 
      141
     | 
    
      			}
 
     | 
  
  
    | 
      142
     | 
    
      	if($doImportDate) {
     | 
  
  
    | 
      143
     | 
    
      	/**
 
     | 
  
  
    | 
      144
     | 
    
      	 * rebuild news post folder
 
     | 
  
  
    | 
      145
     | 
    
      	 */
 
     | 
  
  
    | 
      146
     | 
    
      //	$array = rebuildFolderProtectFile($sPostsPath);
 
     | 
  
  
    | 
      147
     | 
    
      		// now iterate through all existing accessfiles,
 
     | 
  
  
    | 
      148
     | 
    
      		// write its creation date into database
 
     | 
  
  
    | 
      149
     | 
    
      			if(is_writable($sPostsPath)) {
     | 
  
  
    | 
      150
     | 
    
      				$oDir = new DirectoryIterator($sPostsPath);
 
     | 
  
  
    | 
      151
     | 
    
      				$count = 0;
 
     | 
  
  
    | 
      152
     | 
    
      				foreach ($oDir as $fileinfo)
 
     | 
  
  
    | 
      153
     | 
    
      				{
     | 
  
  
    | 
      154
     | 
    
      					$fileName = $fileinfo->getFilename();
 
     | 
  
  
    | 
      155
     | 
    
      					if((!$fileinfo->isDot()) &&
 
     | 
  
  
    | 
      156
     | 
    
      					   ($fileName != 'index.php') &&
 
     | 
  
  
    | 
      157
     | 
    
      					   (substr_compare($fileName,PAGE_EXTENSION,(0-strlen(PAGE_EXTENSION)),strlen(PAGE_EXTENSION)) === 0)
 
     | 
  
  
    | 
      158
     | 
    
      					  )
 
     | 
  
  
    | 
      159
     | 
    
      					{
     | 
  
  
    | 
      160
     | 
    
      					// save creation date from old accessfile
 
     | 
  
  
    | 
      161
     | 
    
      						if($doImportDate) {
     | 
  
  
    | 
      162
     | 
    
      							$link = '/posts/'.preg_replace('/'.preg_quote(PAGE_EXTENSION).'$/i', '', $fileinfo->getFilename());
     | 
  
  
    | 
      163
     | 
    
      							$sql  = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
 
     | 
  
  
    | 
      164
     | 
    
      							$sql .= 'SET `created_when`='.$fileinfo->getMTime().' ';
 
     | 
  
  
    | 
      165
     | 
    
      							$sql .= 'WHERE `link`=\''.$link.'\'';
 
     | 
  
  
    | 
      166
     | 
    
      							if($database->query($sql)) {
     | 
  
  
    | 
      167
     | 
    
      								// delete old access file
 
     | 
  
  
    | 
      168
     | 
    
      								unlink($fileinfo->getPathname());
 
     | 
  
  
    | 
      169
     | 
    
      								$count++;
 
     | 
  
  
    | 
      170
     | 
    
      							}
 
     | 
  
  
    | 
      171
     | 
    
      						}
 
     | 
  
  
    | 
      172
     | 
    
      					}
 
     | 
  
  
    | 
      173
     | 
    
      				}
 
     | 
  
  
    | 
      174
     | 
    
      				unset($oDir);
 
     | 
  
  
    | 
      175
     | 
    
      			}
 
     | 
  
  
    | 
      176
     | 
    
      			if($count > 0) {
     | 
  
  
    | 
      177
     | 
    
      				$msg[] = 'Save date of creation from '.$count.' old accessfiles and delete these files.'." $OK";
 
     | 
  
  
    | 
      178
     | 
    
      			}
 
     | 
  
  
    | 
      179
     | 
    
      	}
 
     | 
  
  
    | 
      180
     | 
    
      // ************************************************
 
     | 
  
  
    | 
      181
     | 
    
      // Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'
 
     | 
  
  
    | 
      182
     | 
    
      			$sql  = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
 
     | 
  
  
    | 
      183
     | 
    
      			$sql .= 'SET `created_when`=`published_when` ';
 
     | 
  
  
    | 
      184
     | 
    
      			$sql .= 'WHERE `published_when`<`created_when`';
 
     | 
  
  
    | 
      185
     | 
    
      			$database->query($sql);
 
     | 
  
  
    | 
      186
     | 
    
      			$sql  = 'UPDATE `'.$database->TablePrefix.'mod_news_posts` ';
 
     | 
  
  
    | 
      187
     | 
    
      			$sql .= 'SET `created_when`=`posted_when` ';
 
     | 
  
  
    | 
      188
     | 
    
      			$sql .= 'WHERE `published_when`=0 OR `published_when`>`posted_when`';
 
     | 
  
  
    | 
      189
     | 
    
      			$database->query($sql);
 
     | 
  
  
    | 
      190
     | 
    
      // ************************************************
 
     | 
  
  
    | 
      191
     | 
    
      
 
     | 
  
  
    | 
      192
     | 
    
      			// only for upgrade-script
 
     | 
  
  
    | 
      193
     | 
    
      			if($globalStarted) {
     | 
  
  
    | 
      194
     | 
    
      				if($bDebug) {
     | 
  
  
    | 
      195
     | 
    
      					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
     | 
  
  
    | 
      196
     | 
    
      				}
 
     | 
  
  
    | 
      197
     | 
    
      			} 
 
     | 
  
  
    | 
      198
     | 
    
      		}
 
     | 
  
  
    | 
      199
     | 
    
      		$msg[] = "News upgrade successfull finished $OK";
 
     | 
  
  
    | 
      200
     | 
    
      		if($globalStarted) {
     | 
  
  
    | 
      201
     | 
    
      			echo "<strong>News upgrade successfull finished $OK</strong><br />";
 
     | 
  
  
    | 
      202
     | 
    
      		}
 
     | 
  
  
    | 
      203
     | 
    
      		$mLang->disableAddon();
 
     | 
  
  
    | 
      204
     | 
    
      		return ( ($globalStarted==true ) ? $globalStarted : $msg);
 
     | 
  
  
    | 
      205
     | 
    
      	}
 
     | 
  
  
    | 
      206
     | 
    
      //}
 
     | 
  
  
    | 
      207
     | 
    
      // end mod_news_Upgrade
 
     | 
  
  
    | 
      208
     | 
    
      
 
     | 
  
  
    | 
      209
     | 
    
      // ------------------------------------
 
     | 
  
  
    | 
      210
     | 
    
      // only show if manuell upgrade
 
     | 
  
  
    | 
      211
     | 
    
      $bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
 
     | 
  
  
    | 
      212
     | 
    
      // Don't show the messages twice
 
     | 
  
  
    | 
      213
     | 
    
      if( is_array($msg = mod_news_Upgrade($bDebugModus)) ) {
     | 
  
  
    | 
      214
     | 
    
      	$sModulReorg = 'm_news_Reorg';
 
     | 
  
  
    | 
      215
     | 
    
      	if(class_exists($sModulReorg)) {
     | 
  
  
    | 
      216
     | 
    
      		$oReorg = new $sModulReorg();
 
     | 
  
  
    | 
      217
     | 
    
      		$msg = array_merge($msg, $oReorg->execute() ); // show details
 
     | 
  
  
    | 
      218
     | 
    
      	}
 
     | 
  
  
    | 
      219
     | 
    
      	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
     | 
  
  
    | 
      220
     | 
    
      }
 
     | 
  
  
    | 
      221
     | 
    
      /* **** END UPGRADE ********************************************************* */
 
     |