Revision 1765
Added by Luisehahne about 13 years ago
| upgrade.php | ||
|---|---|---|
| 1 | 1 | 
    <?php  | 
| 2 | 2 | 
    /**  | 
| 3 | 3 | 
    *  | 
| 4 | 
     * @category        WebsiteBaker
   | 
|
| 5 | 
     * @package         modules
   | 
|
| 6 | 
     * @subpackage      news
   | 
|
| 7 | 
     * @copyright       2009-2011, Website Baker Org. e.V.
   | 
|
| 4 | 
     * @category        modules
   | 
|
| 5 | 
     * @package         news
   | 
|
| 6 | 
     * @subpackage      upgrade
   | 
|
| 7 | 
     * @copyright       2009-2012, WebsiteBaker Org. e.V.
   | 
|
| 8 | 8 | 
    * @link http://www.websitebaker2.org/  | 
| 9 | 9 | 
    * @license http://www.gnu.org/licenses/gpl.html  | 
| 10 | 10 | 
    * @platform WebsiteBaker 2.8.x  | 
| ... | ... | |
| 25 | 25 | 
    {
   | 
| 26 | 26 | 
    function mod_news_Upgrade()  | 
| 27 | 27 | 
    	{
   | 
| 28 | 
    global $database, $msg, $admin, $MESSAGE;  | 
|
| 28 | 
    global $database, $admin, $MESSAGE,$bDebugModus;  | 
|
| 29 | 
    $msg = array();  | 
|
| 29 | 30 | 
    $callingScript = $_SERVER["SCRIPT_NAME"];  | 
| 31 | 
    // check if upgrade startet by upgrade-script to echo a message  | 
|
| 30 | 32 | 
    $tmp = 'upgrade-script.php';  | 
| 31 | 33 | 
    $globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;  | 
| 34 | 
    /**  | 
|
| 35 | 
    * check database engine  | 
|
| 36 | 
    */  | 
|
| 37 | 
        	$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
   | 
|
| 38 | 
             for($x=0; $x<sizeof($aTable);$x++) {
   | 
|
| 39 | 
            	if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
   | 
|
| 40 | 
            		if(('myisam' != strtolower($sOldType))) {
   | 
|
| 41 | 
            			if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
   | 
|
| 42 | 
    $msg[] = $database->get_error();  | 
|
| 43 | 
            			} else{
   | 
|
| 44 | 
    $msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` changed to Engine = \'MyISAM\'';  | 
|
| 45 | 
    }  | 
|
| 46 | 
            		} else {
   | 
|
| 47 | 
    $msg[] = 'TABLE `'.TABLE_PREFIX.$aTable[$x].'` has Engine = \'MyISAM\'';  | 
|
| 48 | 
    }  | 
|
| 49 | 
            	} else {
   | 
|
| 50 | 
    $msg[] = $database->get_error();  | 
|
| 51 | 
    }  | 
|
| 52 | 
    }  | 
|
| 32 | 53 | 
     | 
| 54 | 
     | 
|
| 33 | 55 | 
    $sPagesPath = WB_PATH.PAGES_DIRECTORY;  | 
| 34 | 56 | 
    $sPostsPath = $sPagesPath.'/posts';  | 
| 35 | 57 | 
    // create /posts/ - directory if not exists  | 
| 36 | 58 | 
    		if(!file_exists($sPostsPath)) {
   | 
| 37 | 59 | 
    			if(is_writable($sPagesPath)) {
   | 
| 38 | 60 | 
    make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');  | 
| 39 | 
    			}else {
   | 
|
| 61 | 
    			} else {
   | 
|
| 40 | 62 | 
    				if(!$globalStarted){
   | 
| 41 | 63 | 
    $msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);  | 
| 42 | 
    				}else {
   | 
|
| 43 | 
    $msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';  | 
|
| 64 | 
    // $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);  | 
|
| 65 | 
    return $msg;  | 
|
| 66 | 
    				} else {
   | 
|
| 67 | 
    echo ''.$MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'';  | 
|
| 44 | 68 | 
    return;  | 
| 45 | 69 | 
    }  | 
| 46 | 70 | 
    }  | 
| 47 | 
    			if($globalStarted) {echo 'directory "'.PAGES_DIRECTORY.'/posts/" created.<br />'; }
   | 
|
| 71 | 
    $msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" created</strong>';  | 
|
| 72 | 
    		} else {
   | 
|
| 73 | 
    $msg[] = '<strong>Directory "'.PAGES_DIRECTORY.'/posts/" already exists.</strong>';  | 
|
| 48 | 74 | 
    }  | 
| 49 | 75 | 
    // check if new fields must be added  | 
| 50 | 76 | 
    $doImportDate = true;  | 
| ... | ... | |
| 52 | 78 | 
    if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_when',  | 
| 53 | 79 | 
    			                        'INT NOT NULL DEFAULT \'0\' AFTER `commenting`')) {
   | 
| 54 | 80 | 
    				if($globalStarted){
   | 
| 55 | 
    					echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
   | 
|
| 81 | 
    					echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].'';
   | 
|
| 56 | 82 | 
    return;  | 
| 57 | 
    				}else {
   | 
|
| 58 | 
    $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);  | 
|
| 83 | 
    				} else {
   | 
|
| 84 | 
    // $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);  | 
|
| 85 | 
    $msg[] = $$MESSAGE['RECORD_MODIFIED_FAILED'];  | 
|
| 86 | 
    return $msg;  | 
|
| 59 | 87 | 
    }  | 
| 60 | 88 | 
    }  | 
| 61 | 
    			if($globalStarted) { echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />'; }
   | 
|
| 62 | 
    		}else { $doImportDate = false; }
   | 
|
| 89 | 
     | 
|
| 90 | 
            if($globalStarted) {
   | 
|
| 91 | 
    echo 'Datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_when` added.<br />';  | 
|
| 92 | 
    }  | 
|
| 93 | 
    		} else { $doImportDate = false; }
   | 
|
| 94 | 
     | 
|
| 63 | 95 | 
    		if(!$database->field_exists(TABLE_PREFIX.'mod_news_posts', 'created_by')) {
   | 
| 64 | 96 | 
    if(!$database->field_add(TABLE_PREFIX.'mod_news_posts', 'created_by',  | 
| 65 | 97 | 
    			                        'INT NOT NULL DEFAULT \'0\' AFTER `created_when`')) {
   | 
| 66 | 98 | 
    				if($globalStarted){
   | 
| 67 | 
    					echo $MESSAGE['RECORD_MODIFIED_FAILED'].'<br />';
   | 
|
| 99 | 
    					echo ''.$MESSAGE['RECORD_MODIFIED_FAILED'].'';
   | 
|
| 68 | 100 | 
    return;  | 
| 69 | 101 | 
    				}else {
   | 
| 70 | 
    $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);  | 
|
| 102 | 
    // $admin->print_error($MESSAGE['RECORD_MODIFIED_FAILED']);  | 
|
| 103 | 
    $msg[] = $$MESSAGE['RECORD_MODIFIED_FAILED'];  | 
|
| 104 | 
    return $msg;  | 
|
| 71 | 105 | 
    }  | 
| 72 | 106 | 
    }  | 
| 73 | 
    			if($globalStarted) {echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />'; }
   | 
|
| 107 | 
                if($globalStarted) {
   | 
|
| 108 | 
    echo 'datafield `'.TABLE_PREFIX.'mod_news_posts`.`created_by` added.<br />';  | 
|
| 109 | 
    }  | 
|
| 74 | 110 | 
    }  | 
| 75 | 111 | 
    // preset new fields `created_by` and `created_when` from existing values  | 
| 76 | 112 | 
    		if($doImportDate) {
   | 
| ... | ... | |
| 79 | 115 | 
    $database->query($sql);  | 
| 80 | 116 | 
    }  | 
| 81 | 117 | 
     | 
| 118 | 
    /**  | 
|
| 119 | 
    * rebuild news post folder  | 
|
| 120 | 
    */  | 
|
| 82 | 121 | 
    $array = rebuildFolderProtectFile($sPostsPath);  | 
| 83 | 122 | 
    // now iterate through all existing accessfiles,  | 
| 84 | 123 | 
    // write its creation date into database  | 
| ... | ... | |
| 106 | 145 | 
    }  | 
| 107 | 146 | 
    }  | 
| 108 | 147 | 
    unset($oDir);  | 
| 109 | 
    		if($globalStarted && $count > 0) {
   | 
|
| 110 | 
    $msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.<br />';  | 
|
| 148 | 
     | 
|
| 149 | 
    		if($count > 0) {
   | 
|
| 150 | 
    $msg[] = 'save date of creation from '.$count.' old accessfiles and delete these files.';  | 
|
| 111 | 151 | 
    }  | 
| 112 | 152 | 
    // ************************************************  | 
| 113 | 153 | 
    // Check the validity of 'create-file-timestamp' and balance against 'posted-timestamp'  | 
| ... | ... | |
| 150 | 190 | 
    // Chmod the file  | 
| 151 | 191 | 
    change_mode($file);  | 
| 152 | 192 | 
    				}else {
   | 
| 153 | 
    					if($globalStarted){
   | 
|
| 154 | 
    $msg[] = $MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].'<br />';  | 
|
| 155 | 
    return;  | 
|
| 156 | 
    					}else {
   | 
|
| 157 | 
    $msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);  | 
|
| 158 | 
    }  | 
|
| 193 | 
    $msg[] = ($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);  | 
|
| 159 | 194 | 
    }  | 
| 160 | 195 | 
    $count++;  | 
| 161 | 196 | 
    }  | 
| 197 | 
    $msg[] = '<strong>Number of new created access files: '.$count.'</strong>';  | 
|
| 162 | 198 | 
    }  | 
| 163 | 
    		if($globalStarted) { $msg[] = 'created '.$count.' new accessfiles.'; }
   | 
|
| 199 | 
    // only for upgrade-script  | 
|
| 200 | 
            if($globalStarted) {
   | 
|
| 201 | 
                if($bDebugModus) {
   | 
|
| 202 | 
                    foreach($msg as $title) {
   | 
|
| 203 | 
    echo '<strong>'.$title.'</strong><br />';  | 
|
| 204 | 
    }  | 
|
| 205 | 
    }  | 
|
| 206 | 
    }  | 
|
| 207 | 
    return $msg;  | 
|
| 164 | 208 | 
    }  | 
| 165 | 209 | 
    }  | 
| 210 | 
    // end mod_news_Upgrade  | 
|
| 166 | 211 | 
     | 
| 167 | 
    $msg = array();  | 
|
| 168 | 
    	$aTable = array('mod_news_posts','mod_news_groups','mod_news_comments','mod_news_settings');
   | 
|
| 169 | 
    	for($x=0; $x<sizeof($aTable);$x++) {
   | 
|
| 170 | 
    		if(($sOldType = $database->getTableEngine(TABLE_PREFIX.$aTable[$x]))) {
   | 
|
| 171 | 
    			if(('myisam' != strtolower($sOldType))) {
   | 
|
| 172 | 
    				if(!$database->query('ALTER TABLE `'.TABLE_PREFIX.$aTable[$x].'` Engine = \'MyISAM\' ')) {
   | 
|
| 173 | 
    $msg[] = $database->get_error();  | 
|
| 174 | 
    }  | 
|
| 175 | 
    }  | 
|
| 176 | 
    		} else {
   | 
|
| 177 | 
    $msg[] = $database->get_error();  | 
|
| 178 | 
    }  | 
|
| 179 | 
    }  | 
|
| 180 | 212 | 
    // ------------------------------------  | 
| 181 | 
    mod_news_Upgrade();  | 
|
| 213 | 
     | 
|
| 214 | 
    $msg = mod_news_Upgrade();  | 
|
| 215 | 
     | 
|
| 216 | 
     | 
|
| 182 | 217 | 
    /* **** END UPGRADE ********************************************************* */  | 
Also available in: Unified diff
! recoded module news,form,wysiwyg upgrade to work with upgrade-script