Annotation of /branches/mambo5/app/controllers/installation_controller.php
Parent Directory
|
Revision Log
Revision 2 - (view) (download)
| 1 : | enjoyman | 2 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @author Mambo Foundation Inc see README.php | ||
| 5 : | * @copyright (C) 2000 - 2009 Mambo Foundation Inc. | ||
| 6 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 7 : | * @license GNU/GPL Version 2, see http://www.opensource.org/licenses/gpl-2.0.php | ||
| 8 : | * | ||
| 9 : | * Redistributions of files must retain the above copyright notice. | ||
| 10 : | * | ||
| 11 : | * Mambo is free software; you can redistribute it and/or | ||
| 12 : | * modify it under the terms of the GNU General Public License | ||
| 13 : | * as published by the Free Software Foundation; version 2 of the License. | ||
| 14 : | */ | ||
| 15 : | |||
| 16 : | /** | ||
| 17 : | * Used to perform the database portable installation of Mambo | ||
| 18 : | * | ||
| 19 : | */ | ||
| 20 : | |||
| 21 : | class InstallationController extends AppController { | ||
| 22 : | |||
| 23 : | public $name = 'Installation'; | ||
| 24 : | public $uses = array(); //No model | ||
| 25 : | //public $uses = null; works too | ||
| 26 : | public $helpers = array('Html', 'Form'); | ||
| 27 : | public $layout = 'installation'; | ||
| 28 : | |||
| 29 : | |||
| 30 : | /** @private string Internal variable to hold the db resource */ | ||
| 31 : | private $db=''; | ||
| 32 : | /** @private string Internal variable to hold the db platform type */ | ||
| 33 : | private $dbPlatform=''; | ||
| 34 : | /** @private string Internal variable to hold the db hostname (ex) localhost */ | ||
| 35 : | private $dbHostname=''; | ||
| 36 : | /** @private string Internal variable to hold the db username */ | ||
| 37 : | private $dbUsername=''; | ||
| 38 : | /** @private string Internal variable to hold the db password */ | ||
| 39 : | private $dbPassword=''; | ||
| 40 : | /** @private string Internal variable to hold the name of the db */ | ||
| 41 : | private $dbName=''; | ||
| 42 : | /** @private string Internal variable to hold the table prefix */ | ||
| 43 : | private $dbPrefix=''; | ||
| 44 : | /** @private string Internal variable to hold the table being acted on */ | ||
| 45 : | private $table=''; | ||
| 46 : | /** @private string Internal variable to hold the SQL statement to execute */ | ||
| 47 : | private $sql=''; | ||
| 48 : | /** @private string Internal variable to hold the data dictionary */ | ||
| 49 : | private $dict=''; | ||
| 50 : | |||
| 51 : | /** | ||
| 52 : | * Displays the initial pre-installation page | ||
| 53 : | * | ||
| 54 : | */ | ||
| 55 : | function index() { | ||
| 56 : | App::import('Vendor', 'phpgettext'.DS.'phpgettext.class'); | ||
| 57 : | } | ||
| 58 : | |||
| 59 : | /** | ||
| 60 : | * Displays and requires user to agree to license before installing | ||
| 61 : | * | ||
| 62 : | */ | ||
| 63 : | function license() { | ||
| 64 : | App::import('Vendor', 'phpgettext'.DS.'phpgettext.class'); | ||
| 65 : | |||
| 66 : | if (!empty($this->data)) { | ||
| 67 : | //Did they submit the first form with permission issues unresolved? | ||
| 68 : | if (@!file_exists(CONFIGS.'database.php') || @!is_writable( CONFIGS.'database.php' ) || | ||
| 69 : | @!file_exists(CONFIGS.'configuration.xml') || @!is_writable( CONFIGS.'configuration.xml' ) || | ||
| 70 : | @!file_exists(VENDORS.'mambo'.DS.'store') || @!is_writable( VENDORS.'mambo'.DS.'store' )) { | ||
| 71 : | $setup_error = __('You still have unresolved file or folder permission issues. You must correct these before moving on!'); | ||
| 72 : | $this->setError($setup_error, 'index'); | ||
| 73 : | } | ||
| 74 : | } | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | /** | ||
| 78 : | * Displays database configuration form | ||
| 79 : | * | ||
| 80 : | */ | ||
| 81 : | function install1() { | ||
| 82 : | App::import('Vendor', 'phpgettext'.DS.'phpgettext.class'); | ||
| 83 : | |||
| 84 : | //Check to see if valid form data has been submitted | ||
| 85 : | if (!empty($this->data)) { | ||
| 86 : | $cln_agreecheck = (int) $this->data['installation']['agreecheck']; | ||
| 87 : | if ($cln_agreecheck!=1) { | ||
| 88 : | $setup_error = __('You must read and accept the license to continue installation!'); | ||
| 89 : | $this->setError($setup_error, 'license'); | ||
| 90 : | } | ||
| 91 : | } | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | /** | ||
| 95 : | * Creates the Mambo database structure, loads the default data, loads sample data & backs up old tables when requested | ||
| 96 : | * | ||
| 97 : | */ | ||
| 98 : | function install2() { | ||
| 99 : | vendor('phpgettext'.DS.'phpgettext.class'); | ||
| 100 : | |||
| 101 : | //Check to see if valid form data has been submitted or we've been redirected due to an error | ||
| 102 : | if (!empty($this->data)) { | ||
| 103 : | |||
| 104 : | //Create a new Sanitize object: | ||
| 105 : | uses('sanitize'); | ||
| 106 : | $mrClean = new Sanitize(); | ||
| 107 : | $allowedChars = array('@', '.', '-', '_', '/', '\\', ':'); | ||
| 108 : | |||
| 109 : | //Clean and add certain data to the array for saving (not all fields are updated) | ||
| 110 : | $cln_dbHostname = $mrClean->paranoid($this->data['installation']['dbHostname'], $allowedChars); | ||
| 111 : | $cln_dbPlatform = $mrClean->paranoid($this->data['installation']['dbPlatform']); | ||
| 112 : | $cln_dbUsername = $mrClean->paranoid($this->data['installation']['dbUsername']); | ||
| 113 : | $cln_dbPassword = $this->data['installation']['dbPassword']; | ||
| 114 : | $cln_dbVerifyPassword = $this->data['installation']['dbVerifyPassword']; | ||
| 115 : | $cln_dbName = $mrClean->paranoid($this->data['installation']['dbName'], $allowedChars); | ||
| 116 : | $cln_dbPrefix = $mrClean->paranoid($this->data['installation']['dbPrefix'], $allowedChars); | ||
| 117 : | $cln_dbBackup = (int) $this->data['installation']['dbBackup']; | ||
| 118 : | $cln_dbSample = (int) $this->data['installation']['dbSample']; | ||
| 119 : | |||
| 120 : | $cln_dbPath = $mrClean->paranoid($this->data['installation']['dbPath'], $allowedChars); | ||
| 121 : | //Veryify the dbPath has the proper OS specific trailing slash before adding on the dbName | ||
| 122 : | if (substr($cln_dbPath, -1)!==DS) { | ||
| 123 : | $cln_dbPath = $cln_dbPath.DS; | ||
| 124 : | } | ||
| 125 : | |||
| 126 : | /* Now run through the form validations. In most cases it would be better to utilize cake's invalidate | ||
| 127 : | function, but this appears to require the use of a model which we do not have before the database is created. */ | ||
| 128 : | $form_check = ''; | ||
| 129 : | if (empty($cln_dbHostname)) { | ||
| 130 : | $form_check = 'dbHostname'; | ||
| 131 : | } else if (empty($cln_dbPlatform)) { | ||
| 132 : | $form_check = 'dbPlatform'; | ||
| 133 : | } else if (empty($cln_dbPath) && $cln_dbPlatform=='sqlite') { | ||
| 134 : | $form_check = 'dbPath'; | ||
| 135 : | } else if (empty($cln_dbUsername) && $cln_dbPlatform!='sqlite') { | ||
| 136 : | $form_check = 'dbUsername'; | ||
| 137 : | } else if (empty($cln_dbPassword) && $cln_dbPlatform!='sqlite') { | ||
| 138 : | $form_check = 'dbPassword'; | ||
| 139 : | } else if (($cln_dbPassword !== $cln_dbVerifyPassword) && $cln_dbPlatform!='sqlite') { | ||
| 140 : | $form_check = 'dbPasswordMismatch'; | ||
| 141 : | } else if (empty($cln_dbName)) { | ||
| 142 : | $form_check = 'dbName'; | ||
| 143 : | } else if (empty($cln_dbPrefix)) { | ||
| 144 : | $form_check = 'dbPrefix'; | ||
| 145 : | } else if ($cln_dbBackup==1 && $cln_dbPlatform=='sqlite') { | ||
| 146 : | $this->setError('Table backups are not supported for SQLite2', 'install2'); | ||
| 147 : | } | ||
| 148 : | |||
| 149 : | /* If errors store form data and redirect back to form. Clear passwords first so they don't end up | ||
| 150 : | in the session data. */ | ||
| 151 : | if ($form_check!='') { | ||
| 152 : | $this->data['installation']['dbPassword']=''; | ||
| 153 : | $this->data['installation']['dbVerifyPassword']=''; | ||
| 154 : | $this->Session->Write('form_data', $this->data['installation']); | ||
| 155 : | $this->Session->Write('form_check', $form_check); | ||
| 156 : | $this->redirect('/installation/install1'); | ||
| 157 : | exit; | ||
| 158 : | } | ||
| 159 : | |||
| 160 : | //Initialize instance variables | ||
| 161 : | $this->dbPlatform = $cln_dbPlatform; | ||
| 162 : | $this->dbHostname = $cln_dbHostname; | ||
| 163 : | $this->dbUsername = $cln_dbUsername; | ||
| 164 : | $this->dbPassword = $cln_dbPassword; | ||
| 165 : | $this->dbName = $cln_dbName; | ||
| 166 : | $this->dbPath = $cln_dbPath; | ||
| 167 : | $this->dbPrefix = $cln_dbPrefix; | ||
| 168 : | $this->dbBackup = $cln_dbBackup; | ||
| 169 : | $this->dbSample = $cln_dbSample; | ||
| 170 : | |||
| 171 : | //Get the database connection | ||
| 172 : | $db = $this->setupConnection(); | ||
| 173 : | $this->db = $db; | ||
| 174 : | |||
| 175 : | //Serialize the form data (needed later in install4) | ||
| 176 : | $s = serialize($this->data['installation']); | ||
| 177 : | $fp = fopen(VENDORS.DS.'mambo'.DS.'store', "w"); | ||
| 178 : | fwrite($fp, $s); | ||
| 179 : | fclose($fp); | ||
| 180 : | |||
| 181 : | //Configuration information: Define the schema filename, RDBMS platform, and database connection information here. | ||
| 182 : | $schemaFile = VENDORS.DS.'mambo'.DS.'mambo_structure.xml'; | ||
| 183 : | |||
| 184 : | //Use the database connection to create a new adoSchema object. | ||
| 185 : | $schema = new adoSchema($this->db); | ||
| 186 : | |||
| 187 : | //Set the database table prefix | ||
| 188 : | $schema->setPrefix($this->dbPrefix); | ||
| 189 : | //Create a data dictionary object | ||
| 190 : | $this->dict = NewDataDictionary($this->db); | ||
| 191 : | |||
| 192 : | //If previous tables exist then backup (if requested) and drop for fresh install | ||
| 193 : | /* Builds an array of table names to use in the drop table sequence. Note: Could use 'show tables' in | ||
| 194 : | MySQL to build the array, but that is not portable across other dbs. */ | ||
| 195 : | $tables = $this->db->MetaTables('TABLES'); | ||
| 196 : | $backupPrefix = 'old_'; | ||
| 197 : | if ($tables) { | ||
| 198 : | foreach ($tables as $table) { | ||
| 199 : | //Check for the existance of tables with the same prefix | ||
| 200 : | if (strpos($table, $this->dbPrefix) === 0) { | ||
| 201 : | //Check to see if the user requested a backup | ||
| 202 : | if ($this->dbBackup==1) { | ||
| 203 : | //If they requested a backup then replace the org table prefix with old_ | ||
| 204 : | $backupTable = str_replace($this->dbPrefix, $backupPrefix, $table); | ||
| 205 : | //If a prior backup table exists with the same name then drop it before the rename | ||
| 206 : | $this->dropTable($backupTable); | ||
| 207 : | //Drop db sequence | ||
| 208 : | $this->dropSequence($table); | ||
| 209 : | //Perform the actual table rename | ||
| 210 : | $this->renameTable($table, $backupTable); | ||
| 211 : | } else { | ||
| 212 : | $this->dropTable($table); | ||
| 213 : | //Drop db sequence | ||
| 214 : | $this->dropSequence($table); | ||
| 215 : | } | ||
| 216 : | } | ||
| 217 : | } //end foreach | ||
| 218 : | |||
| 219 : | $this->dropIndexes(); //Drop indexes as needed | ||
| 220 : | } //end if | ||
| 221 : | |||
| 222 : | //Build DML SQL statements | ||
| 223 : | $schema->ParseSchema($schemaFile); | ||
| 224 : | //Execute DML SQL statements | ||
| 225 : | $result = $schema->ExecuteSchema(); | ||
| 226 : | |||
| 227 : | if ($result) { | ||
| 228 : | //Load default data | ||
| 229 : | $this->loadSQLData('default'); | ||
| 230 : | |||
| 231 : | if ($this->dbSample) { | ||
| 232 : | //Load sample data if requested | ||
| 233 : | $this->loadSQLData('sample'); | ||
| 234 : | } | ||
| 235 : | } | ||
| 236 : | |||
| 237 : | //Write out the database configuration file in CakePHP's preferred format | ||
| 238 : | $this->writeDatabaseConfigFile(); | ||
| 239 : | } | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | /** | ||
| 243 : | * Collects the users specified Mambo site name | ||
| 244 : | * | ||
| 245 : | */ | ||
| 246 : | function install3() { | ||
| 247 : | vendor('phpgettext'.DS.'phpgettext.class'); | ||
| 248 : | |||
| 249 : | //Check to see if valid form data has been submitted | ||
| 250 : | if (!empty($this->data)) { | ||
| 251 : | |||
| 252 : | //Create a new Sanitize object: | ||
| 253 : | uses('sanitize'); | ||
| 254 : | $mrClean = new Sanitize(); | ||
| 255 : | $allowedChars = array('@', '.', '-', '_', '/', '\\', ':', '\'', ' '); | ||
| 256 : | |||
| 257 : | //Clean and add certain data to the array for saving (not all fields are updated) | ||
| 258 : | $cln_Sitename = $mrClean->paranoid($this->data['installation']['Sitename'], $allowedChars); | ||
| 259 : | |||
| 260 : | /* Now run through the form validations. In most cases it would be better to utilize cake's invalidate | ||
| 261 : | function, but this appears to require the use of a model which we do not have before the database is created. */ | ||
| 262 : | $form_check = ''; | ||
| 263 : | if (empty($cln_Sitename)) { | ||
| 264 : | $form_check = 'Sitename'; | ||
| 265 : | } | ||
| 266 : | |||
| 267 : | /* If errors store form data and redirect back to form. Clear passwords first so they don't end up | ||
| 268 : | in the session data. */ | ||
| 269 : | if ($form_check!='') { | ||
| 270 : | $this->Session->Write('form_data', $this->data['installation']); | ||
| 271 : | $this->Session->Write('form_check', $form_check); | ||
| 272 : | $this->redirect('/installation/install2'); | ||
| 273 : | exit; | ||
| 274 : | } | ||
| 275 : | |||
| 276 : | //Build the siteURL | ||
| 277 : | $root = $_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']!=80?':'.$_SERVER['SERVER_PORT']:'').$_SERVER['PHP_SELF']; | ||
| 278 : | $root = str_replace('/app/webroot/index.php','',$root); | ||
| 279 : | $siteURL = "http://".$root; | ||
| 280 : | |||
| 281 : | //Add some info to the session before moving to step 3 | ||
| 282 : | $this->Session->Write('Sitename', $cln_Sitename); | ||
| 283 : | $this->Session->Write('siteURL', $siteURL); | ||
| 284 : | $this->Session->Write('absolutePath', APP); | ||
| 285 : | |||
| 286 : | } | ||
| 287 : | |||
| 288 : | } | ||
| 289 : | |||
| 290 : | /** | ||
| 291 : | * Collects the Mambo admin information, lands the Mambo configuration file, and inserts the admin user | ||
| 292 : | * | ||
| 293 : | */ | ||
| 294 : | function install4() { | ||
| 295 : | |||
| 296 : | vendor('phpgettext'.DS.'phpgettext.class'); | ||
| 297 : | |||
| 298 : | //Check to see if valid form data has been submitted | ||
| 299 : | if (!empty($this->data)) { | ||
| 300 : | |||
| 301 : | //Create a new Sanitize object: | ||
| 302 : | uses('sanitize'); | ||
| 303 : | $mrClean = new Sanitize(); | ||
| 304 : | $allowedChars = array('@', '.', '-', '_', '/', '\\', ':', '\'', ' '); | ||
| 305 : | |||
| 306 : | //Clean and add certain data to the array for saving (not all fields are updated) | ||
| 307 : | $cln_siteUrl = $mrClean->paranoid($this->data['installation']['siteUrl'], $allowedChars); | ||
| 308 : | $cln_absolutePath = $mrClean->paranoid($this->data['installation']['absolutePath'], $allowedChars); | ||
| 309 : | $cln_adminEmail = $mrClean->paranoid($this->data['installation']['adminEmail'], $allowedChars); | ||
| 310 : | $cln_adminPassword = $this->data['installation']['adminPassword']; | ||
| 311 : | $cln_adminVerifyPassword = $this->data['installation']['adminVerifyPassword']; | ||
| 312 : | |||
| 313 : | //Fix for Windows | ||
| 314 : | $cln_absolutePath = str_replace("\\","/", $cln_absolutePath); | ||
| 315 : | $cln_absolutePath = str_replace("//","/", $cln_absolutePath); | ||
| 316 : | |||
| 317 : | /* Now run through the form validations. In most cases it would be better to utilize cake's invalidate | ||
| 318 : | function, but this appears to require the use of a model which we do not have before the database is created. */ | ||
| 319 : | $form_check = ''; | ||
| 320 : | if (empty($cln_siteUrl)) { | ||
| 321 : | $form_check = 'siteUrl'; | ||
| 322 : | } else if (empty($cln_absolutePath)) { | ||
| 323 : | $form_check = 'absolutePath'; | ||
| 324 : | } else if (empty($cln_adminEmail) || validEmail($cln_adminEmail)===false) { | ||
| 325 : | $form_check = 'adminEmail'; | ||
| 326 : | } else if (empty($cln_adminPassword)) { | ||
| 327 : | $form_check = 'adminPassword'; | ||
| 328 : | } else if ($cln_adminPassword!==$cln_adminVerifyPassword) { | ||
| 329 : | $form_check = 'adminVerifyPassword'; | ||
| 330 : | } | ||
| 331 : | |||
| 332 : | /* If errors store form data and redirect back to form. Clear passwords first so they don't end up | ||
| 333 : | in the session data. */ | ||
| 334 : | if ($form_check!='') { | ||
| 335 : | //Remove password so it does not end up in the session data | ||
| 336 : | $this->data['installation']['adminPassword']=''; | ||
| 337 : | $this->Session->Write('form_data', $this->data['installation']); | ||
| 338 : | $this->Session->Write('form_check', $form_check); | ||
| 339 : | $this->redirect('/installation/install3'); | ||
| 340 : | exit; | ||
| 341 : | } | ||
| 342 : | |||
| 343 : | if ($this->Session->check('Sitename')) { | ||
| 344 : | $Sitename = $this->Session->read('Sitename'); | ||
| 345 : | } | ||
| 346 : | |||
| 347 : | //Need to discuss with Andres and get his feedback (so this is just temp) | ||
| 348 : | $nameLang = 'English'; | ||
| 349 : | $lang = 'en'; | ||
| 350 : | //end temp | ||
| 351 : | |||
| 352 : | //Output the new CakePHP database.php config file | ||
| 353 : | $config_file = CONFIGS.'configuration.xml'; | ||
| 354 : | if(($handle = @fopen($config_file, 'w'))===false){ | ||
| 355 : | $errorMsg = sprintf(__('Failed to open the %s file for writing! '), $config_file); | ||
| 356 : | $errorMsg .= __('Please make sure the web server user has write permissions on this file until the installation is complete'); | ||
| 357 : | $this->setError($errorMsg, 'install3'); | ||
| 358 : | } else { | ||
| 359 : | |||
| 360 : | $configText = "<?xml version='1.0' standalone='yes'?>\n"; | ||
| 361 : | $configText .= "<options>\n"; | ||
| 362 : | $configText .= " <option>\n"; | ||
| 363 : | $configText .= " <name>mosConfig_offline</name>\n"; | ||
| 364 : | $configText .= " <setting>0</setting>\n"; | ||
| 365 : | $configText .= " </option>\n"; | ||
| 366 : | $configText .= " <option>\n"; | ||
| 367 : | $configText .= " <name>mosConfig_lang</name>\n"; | ||
| 368 : | $configText .= " <setting>{$nameLang}</setting>\n"; | ||
| 369 : | $configText .= " </option>\n"; | ||
| 370 : | $configText .= " <option>\n"; | ||
| 371 : | $configText .= " <name>mosConfig_absolute_path</name>\n"; | ||
| 372 : | $configText .= " <setting>{$cln_absolutePath}</setting>\n"; | ||
| 373 : | $configText .= " </option>\n"; | ||
| 374 : | $configText .= " <option>\n"; | ||
| 375 : | $configText .= " <name>mosConfig_live_site</name>\n"; | ||
| 376 : | $configText .= " <setting>{$cln_siteUrl}</setting>\n"; | ||
| 377 : | $configText .= " </option>\n"; | ||
| 378 : | $configText .= " <option>\n"; | ||
| 379 : | $configText .= " <name>mosConfig_sitename</name>\n"; | ||
| 380 : | $configText .= " <setting>{$Sitename}</setting>\n"; | ||
| 381 : | $configText .= " </option>\n"; | ||
| 382 : | $configText .= " <option>\n"; | ||
| 383 : | $configText .= " <name>mosConfig_shownoauth</name>\n"; | ||
| 384 : | $configText .= " <setting>0</setting>\n"; | ||
| 385 : | $configText .= " </option>\n"; | ||
| 386 : | $configText .= " <option>\n"; | ||
| 387 : | $configText .= " <name>mosConfig_useractivation</name>\n"; | ||
| 388 : | $configText .= " <setting>1</setting>\n"; | ||
| 389 : | $configText .= " </option>\n"; | ||
| 390 : | $configText .= " <option>\n"; | ||
| 391 : | $configText .= " <name>mosConfig_usecaptcha</name>\n"; | ||
| 392 : | $configText .= " <setting>0</setting>\n"; | ||
| 393 : | $configText .= " </option>\n"; | ||
| 394 : | $configText .= " <option>\n"; | ||
| 395 : | $configText .= " <name>mosConfig_uniquemail</name>\n"; | ||
| 396 : | $configText .= " <setting>1</setting>\n"; | ||
| 397 : | $configText .= " </option>\n"; | ||
| 398 : | $configText .= " <option>\n"; | ||
| 399 : | $configText .= " <name>mosConfig_offline_message</name>\n"; | ||
| 400 : | $configText .= " <setting>".__('This site is down for maintenance.<br /> Please check back again soon.')."</setting>\n"; | ||
| 401 : | $configText .= " </option>\n"; | ||
| 402 : | $configText .= " <option>\n"; | ||
| 403 : | $configText .= " <name>mosConfig_error_message</name>\n"; | ||
| 404 : | $configText .= " <setting>".__('This site is temporarily unavailable.<br /> Please notify the System Administrator')."</setting>\n"; | ||
| 405 : | $configText .= " </option>\n"; | ||
| 406 : | $configText .= " <option>\n"; | ||
| 407 : | $configText .= " <name>mosConfig_debug</name>\n"; | ||
| 408 : | $configText .= " <setting>0</setting>\n"; | ||
| 409 : | $configText .= " </option>\n"; | ||
| 410 : | $configText .= " <option>\n"; | ||
| 411 : | $configText .= " <name>mosConfig_lifetime</name>\n"; | ||
| 412 : | $configText .= " <setting>900</setting>\n"; | ||
| 413 : | $configText .= " </option>\n"; | ||
| 414 : | $configText .= " <option>\n"; | ||
| 415 : | $configText .= " <name>mosConfig_MetaDesc</name>\n"; | ||
| 416 : | $configText .= " <setting>".__('This site uses Mambo - the free, open source content management system')."</setting>\n"; | ||
| 417 : | $configText .= " </option>\n"; | ||
| 418 : | $configText .= " <option>\n"; | ||
| 419 : | $configText .= " <name>mosConfig_MetaKeys</name>\n"; | ||
| 420 : | $configText .= " <setting>mambo user, Mambo</setting>\n"; | ||
| 421 : | $configText .= " </option>\n"; | ||
| 422 : | $configText .= " <option>\n"; | ||
| 423 : | $configText .= " <name>mosConfig_MetaTitle</name>\n"; | ||
| 424 : | $configText .= " <setting>1</setting>\n"; | ||
| 425 : | $configText .= " </option>\n"; | ||
| 426 : | $configText .= " <option>\n"; | ||
| 427 : | $configText .= " <name>mosConfig_MetaAuthor</name>\n"; | ||
| 428 : | $configText .= " <setting>1</setting>\n"; | ||
| 429 : | $configText .= " </option>\n"; | ||
| 430 : | $configText .= " <option>\n"; | ||
| 431 : | $configText .= " <name>mosConfig_locale_debug</name>\n"; | ||
| 432 : | $configText .= " <setting>0</setting>\n"; | ||
| 433 : | $configText .= " </option>\n"; | ||
| 434 : | $configText .= " <option>\n"; | ||
| 435 : | $configText .= " <name>mosConfig_locale_use_gettext</name>\n"; | ||
| 436 : | $configText .= " <setting>0</setting>\n"; | ||
| 437 : | $configText .= " </option>\n"; | ||
| 438 : | $configText .= " <option>\n"; | ||
| 439 : | $configText .= " <name>mosConfig_locale</name>\n"; | ||
| 440 : | $configText .= " <setting>{$lang}</setting>\n"; | ||
| 441 : | $configText .= " </option>\n"; | ||
| 442 : | $configText .= " <option>\n"; | ||
| 443 : | $configText .= " <name>mosConfig_offset</name>\n"; | ||
| 444 : | $configText .= " <setting>0</setting>\n"; | ||
| 445 : | $configText .= " </option>\n"; | ||
| 446 : | $configText .= " <option>\n"; | ||
| 447 : | $configText .= " <name>mosConfig_hideAuthor</name>\n"; | ||
| 448 : | $configText .= " <setting>0</setting>\n"; | ||
| 449 : | $configText .= " </option>\n"; | ||
| 450 : | $configText .= " <option>\n"; | ||
| 451 : | $configText .= " <name>mosConfig_hideCreateDate</name>\n"; | ||
| 452 : | $configText .= " <setting>0</setting>\n"; | ||
| 453 : | $configText .= " </option>\n"; | ||
| 454 : | $configText .= " <option>\n"; | ||
| 455 : | $configText .= " <name>mosConfig_hideModifyDate</name>\n"; | ||
| 456 : | $configText .= " <setting>0</setting>\n"; | ||
| 457 : | $configText .= " </option>\n"; | ||
| 458 : | $configText .= " <option>\n"; | ||
| 459 : | $configText .= " <name>mosConfig_hidePdf</name>\n"; | ||
| 460 : | $configText .= " <setting>".intval( !is_writable( "{$cln_absolutePath}/media/" ) )."</setting>\n"; | ||
| 461 : | $configText .= " </option>\n"; | ||
| 462 : | $configText .= " <option>\n"; | ||
| 463 : | $configText .= " <name>mosConfig_hidePrint</name>\n"; | ||
| 464 : | $configText .= " <setting>0</setting>\n"; | ||
| 465 : | $configText .= " </option>\n"; | ||
| 466 : | $configText .= " <option>\n"; | ||
| 467 : | $configText .= " <name>mosConfig_hideEmail</name>\n"; | ||
| 468 : | $configText .= " <setting>0</setting>\n"; | ||
| 469 : | $configText .= " </option>\n"; | ||
| 470 : | $configText .= " <option>\n"; | ||
| 471 : | $configText .= " <name>mosConfig_enable_log_items</name>\n"; | ||
| 472 : | $configText .= " <setting>0</setting>\n"; | ||
| 473 : | $configText .= " </option>\n"; | ||
| 474 : | $configText .= " <option>\n"; | ||
| 475 : | $configText .= " <name>mosConfig_enable_log_searches</name>\n"; | ||
| 476 : | $configText .= " <setting>0</setting>\n"; | ||
| 477 : | $configText .= " </option>\n"; | ||
| 478 : | $configText .= " <option>\n"; | ||
| 479 : | $configText .= " <name>mosConfig_enable_stats</name>\n"; | ||
| 480 : | $configText .= " <setting>0</setting>\n"; | ||
| 481 : | $configText .= " </option>\n"; | ||
| 482 : | $configText .= " <option>\n"; | ||
| 483 : | $configText .= " <name>mosConfig_sef</name>\n"; | ||
| 484 : | $configText .= " <setting>0</setting>\n"; | ||
| 485 : | $configText .= " </option>\n"; | ||
| 486 : | $configText .= " <option>\n"; | ||
| 487 : | $configText .= " <name>mosConfig_vote</name>\n"; | ||
| 488 : | $configText .= " <setting>0</setting>\n"; | ||
| 489 : | $configText .= " </option>\n"; | ||
| 490 : | $configText .= " <option>\n"; | ||
| 491 : | $configText .= " <name>mosConfig_gzip</name>\n"; | ||
| 492 : | $configText .= " <setting>0</setting>\n"; | ||
| 493 : | $configText .= " </option>\n"; | ||
| 494 : | $configText .= " <option>\n"; | ||
| 495 : | $configText .= " <name>mosConfig_multipage_toc</name>\n"; | ||
| 496 : | $configText .= " <setting>1</setting>\n"; | ||
| 497 : | $configText .= " </option>\n"; | ||
| 498 : | $configText .= " <option>\n"; | ||
| 499 : | $configText .= " <name>mosConfig_allowUserRegistration</name>\n"; | ||
| 500 : | $configText .= " <setting>1</setting>\n"; | ||
| 501 : | $configText .= " </option>\n"; | ||
| 502 : | $configText .= " <option>\n"; | ||
| 503 : | $configText .= " <name>mosConfig_registration_disclaimer</name>\n"; | ||
| 504 : | $configText .= " <setting>0</setting>\n"; | ||
| 505 : | $configText .= " </option>\n"; | ||
| 506 : | $configText .= " <option>\n"; | ||
| 507 : | $configText .= " <name>mosConfig_registration_disclaimer_message</name>\n"; | ||
| 508 : | $configText .= " <setting>".__('Put your disclaimer here...')."</setting>\n"; | ||
| 509 : | $configText .= " </option>\n"; | ||
| 510 : | $configText .= " <option>\n"; | ||
| 511 : | $configText .= " <name>mosConfig_link_titles</name>\n"; | ||
| 512 : | $configText .= " <setting>0</setting>\n"; | ||
| 513 : | $configText .= " </option>\n"; | ||
| 514 : | $configText .= " <option>\n"; | ||
| 515 : | $configText .= " <name>mosConfig_error_reporting</name>\n"; | ||
| 516 : | $configText .= " <setting>-1</setting>\n"; | ||
| 517 : | $configText .= " </option>\n"; | ||
| 518 : | $configText .= " <option>\n"; | ||
| 519 : | $configText .= " <name>mosConfig_list_limit</name>\n"; | ||
| 520 : | $configText .= " <setting>50</setting>\n"; | ||
| 521 : | $configText .= " </option>\n"; | ||
| 522 : | $configText .= " <option>\n"; | ||
| 523 : | $configText .= " <name>mosConfig_mailer</name>\n"; | ||
| 524 : | $configText .= " <setting>mail</setting>\n"; | ||
| 525 : | $configText .= " </option>\n"; | ||
| 526 : | $configText .= " <option>\n"; | ||
| 527 : | $configText .= " <name>mosConfig_mailfrom</name>\n"; | ||
| 528 : | $configText .= " <setting>{$cln_adminEmail}</setting>\n"; | ||
| 529 : | $configText .= " </option>\n"; | ||
| 530 : | $configText .= " <option>\n"; | ||
| 531 : | $configText .= " <name>mosConfig_fromname</name>\n"; | ||
| 532 : | $configText .= " <setting>{$Sitename}</setting>\n"; | ||
| 533 : | $configText .= " </option>\n"; | ||
| 534 : | $configText .= " <option>\n"; | ||
| 535 : | $configText .= " <name>mosConfig_sendmail</name>\n"; | ||
| 536 : | $configText .= " <setting>/usr/sbin/sendmail</setting>\n"; | ||
| 537 : | $configText .= " </option>\n"; | ||
| 538 : | $configText .= " <option>\n"; | ||
| 539 : | $configText .= " <name>mosConfig_smtpauth</name>\n"; | ||
| 540 : | $configText .= " <setting>0</setting>\n"; | ||
| 541 : | $configText .= " </option>\n"; | ||
| 542 : | $configText .= " <option>\n"; | ||
| 543 : | $configText .= " <name>mosConfig_smtpuser</name>\n"; | ||
| 544 : | $configText .= " <setting></setting>\n"; | ||
| 545 : | $configText .= " </option>\n"; | ||
| 546 : | $configText .= " <option>\n"; | ||
| 547 : | $configText .= " <name>mosConfig_smtppass</name>\n"; | ||
| 548 : | $configText .= " <setting></setting>\n"; | ||
| 549 : | $configText .= " </option>\n"; | ||
| 550 : | $configText .= " <option>\n"; | ||
| 551 : | $configText .= " <name>mosConfig_smtphost</name>\n"; | ||
| 552 : | $configText .= " <setting>localhost</setting>\n"; | ||
| 553 : | $configText .= " </option>\n"; | ||
| 554 : | $configText .= " <option>\n"; | ||
| 555 : | $configText .= " <name>mosConfig_back_button</name>\n"; | ||
| 556 : | $configText .= " <setting>0</setting>\n"; | ||
| 557 : | $configText .= " </option>\n"; | ||
| 558 : | $configText .= " <option>\n"; | ||
| 559 : | $configText .= " <name>mosConfig_item_navigation</name>\n"; | ||
| 560 : | $configText .= " <setting>0</setting>\n"; | ||
| 561 : | $configText .= " </option>\n"; | ||
| 562 : | $configText .= " <option>\n"; | ||
| 563 : | $configText .= " <name>mosConfig_pagetitles</name>\n"; | ||
| 564 : | $configText .= " <setting>1</setting>\n"; | ||
| 565 : | $configText .= " </option>\n"; | ||
| 566 : | $configText .= " <option>\n"; | ||
| 567 : | $configText .= " <name>mosConfig_readmore</name>\n"; | ||
| 568 : | $configText .= " <setting>1</setting>\n"; | ||
| 569 : | $configText .= " </option>\n"; | ||
| 570 : | $configText .= " <option>\n"; | ||
| 571 : | $configText .= " <name>mosConfig_hits</name>\n"; | ||
| 572 : | $configText .= " <setting>1</setting>\n"; | ||
| 573 : | $configText .= " </option>\n"; | ||
| 574 : | $configText .= " <option>\n"; | ||
| 575 : | $configText .= " <name>mosConfig_icons</name>\n"; | ||
| 576 : | $configText .= " <setting>1</setting>\n"; | ||
| 577 : | $configText .= " </option>\n"; | ||
| 578 : | $configText .= " <option>\n"; | ||
| 579 : | $configText .= " <name>mosConfig_favicon</name>\n"; | ||
| 580 : | $configText .= " <setting>favicon.ico</setting>\n"; | ||
| 581 : | $configText .= " </option>\n"; | ||
| 582 : | $configText .= " <option>\n"; | ||
| 583 : | $configText .= " <name>mosConfig_helpurl</name>\n"; | ||
| 584 : | $configText .= " <setting>http://docs.mambo-foundation.org</setting>\n"; | ||
| 585 : | $configText .= " </option>\n"; | ||
| 586 : | $configText .= " <option>\n"; | ||
| 587 : | $configText .= " <name>mosConfig_mbf_content</name>\n"; | ||
| 588 : | $configText .= " <setting>0</setting>\n"; | ||
| 589 : | $configText .= " </option>\n"; | ||
| 590 : | $configText .= "</options>"; | ||
| 591 : | |||
| 592 : | if ($handle) { | ||
| 593 : | fwrite($handle, $configText); | ||
| 594 : | fclose($handle); | ||
| 595 : | } | ||
| 596 : | |||
| 597 : | //Unserialize the step 1 data for to insert the default admin user | ||
| 598 : | $filename = VENDORS.DS.'mambo'.DS.'store'; | ||
| 599 : | $handle = fopen($filename, "r"); | ||
| 600 : | $contents = fread($handle, filesize($filename)); | ||
| 601 : | fclose($handle); | ||
| 602 : | $unData = unserialize($contents); | ||
| 603 : | |||
| 604 : | //Refresh the database connection for the insert | ||
| 605 : | $this->dbHostname = $unData['dbHostname']; | ||
| 606 : | $this->dbPlatform = $unData['dbPlatform']; | ||
| 607 : | $this->dbPath = $unData['dbPath']; | ||
| 608 : | $this->dbUsername = $unData['dbUsername']; | ||
| 609 : | $this->dbPassword = $unData['dbPassword']; | ||
| 610 : | $this->dbName = $unData['dbName']; | ||
| 611 : | $this->dbPrefix = $unData['dbPrefix']; | ||
| 612 : | |||
| 613 : | $db = $this->setupConnection(); | ||
| 614 : | $this->db = $db; | ||
| 615 : | |||
| 616 : | //Using SHA1 for cross platform password encryption. Not perfectly secure, but a longer hash than provided by MD5. | ||
| 617 : | $cryptpass=sha1($cln_adminPassword); | ||
| 618 : | //Build cross-platform timestamp | ||
| 619 : | $currentDate = date("Y-m-d"); | ||
| 620 : | |||
| 621 : | $usersTable = $this->dbPrefix.'users'; | ||
| 622 : | $adminUserSQL = "INSERT INTO $usersTable | ||
| 623 : | (id, name, username, email, password, usertype, block, sendEmail, group_id, registerDate, lastvisitDate) | ||
| 624 : | VALUES (1, 'Administrator', 'admin', '$cln_adminEmail', '$cryptpass', 'Super Administrator', 0, 1, 25, '$currentDate', '$currentDate')"; | ||
| 625 : | |||
| 626 : | //Insert the admin user | ||
| 627 : | $this->executeInsert($adminUserSQL, 'install3'); | ||
| 628 : | |||
| 629 : | } | ||
| 630 : | |||
| 631 : | } | ||
| 632 : | } | ||
| 633 : | |||
| 634 : | /** | ||
| 635 : | * Presents/Sends survey installation information | ||
| 636 : | * | ||
| 637 : | */ | ||
| 638 : | function survey() { | ||
| 639 : | vendor('phpgettext'.DS.'phpgettext.class'); | ||
| 640 : | |||
| 641 : | //Check to see if valid form data has been submitted | ||
| 642 : | if (!empty($this->data)) { | ||
| 643 : | |||
| 644 : | //Create a new Sanitize object: | ||
| 645 : | uses('sanitize'); | ||
| 646 : | $mrClean = new Sanitize(); | ||
| 647 : | $allowedChars = array('@', '.', '-', '_', '/', '\\', ':', ',', ' '); | ||
| 648 : | |||
| 649 : | //Clean and add certain data to the array | ||
| 650 : | $cln_name = $mrClean->paranoid($this->data['installation']['name']); | ||
| 651 : | $cln_email = $mrClean->paranoid($this->data['installation']['email'], $allowedChars); | ||
| 652 : | $cln_company = $mrClean->paranoid($this->data['installation']['company'], $allowedChars); | ||
| 653 : | $cln_category = $mrClean->paranoid($this->data['installation']['category']); | ||
| 654 : | $cln_comments = $mrClean->paranoid($this->data['installation']['comments'], $allowedChars); | ||
| 655 : | |||
| 656 : | /* Now run through the form validations. In most cases it would be better to utilize cake's invalidate | ||
| 657 : | function, but this appears to require the use of a model which we do not have before the database is created. */ | ||
| 658 : | $form_check = ''; | ||
| 659 : | if (empty($cln_name)) { | ||
| 660 : | $form_check = 'name'; | ||
| 661 : | } else if (empty($cln_email) || validEmail($cln_email)===false) { | ||
| 662 : | $form_check = 'email'; | ||
| 663 : | } else if (empty($cln_category) && empty($cln_comments)) { | ||
| 664 : | $form_check = 'needmoreinfo'; | ||
| 665 : | } | ||
| 666 : | |||
| 667 : | /* If errors store form data and redirect back to form. Clear passwords first so they don't end up | ||
| 668 : | in the session data. */ | ||
| 669 : | if ($form_check!='') { | ||
| 670 : | $this->Session->Write('form_data', $this->data['installation']); | ||
| 671 : | $this->Session->Write('form_check', $form_check); | ||
| 672 : | $this->redirect('/installation/install4'); | ||
| 673 : | exit; | ||
| 674 : | } | ||
| 675 : | |||
| 676 : | //Build and send survey email | ||
| 677 : | $to = 'feedback@mambo-foundation.org'; | ||
| 678 : | $subject = 'Mambo Installation - User Comments'; | ||
| 679 : | $message = "$cln_name left some comments on the installation survey. "; | ||
| 680 : | $message .= "Here are the comments:\n"; | ||
| 681 : | $message .= "\n"; | ||
| 682 : | $message .= "Name: $cln_name\n"; | ||
| 683 : | $message .= "Email: $cln_email\n"; | ||
| 684 : | $message .= "Category: $cln_category\n"; | ||
| 685 : | $message .= "Company: $cln_company\n"; | ||
| 686 : | $message .= "Comments: $cln_comments"; | ||
| 687 : | $headers = "From: $cln_email" . "\r\n" . | ||
| 688 : | "Reply-To: $cln_email" . "\r\n" . | ||
| 689 : | 'X-Mailer: PHP/' . phpversion(); | ||
| 690 : | |||
| 691 : | //No error checking on the send since this is just a nice to have | ||
| 692 : | mail($to, $subject, $message, $headers); | ||
| 693 : | |||
| 694 : | $this->redirect('/main/index'); | ||
| 695 : | exit; | ||
| 696 : | } | ||
| 697 : | |||
| 698 : | } | ||
| 699 : | |||
| 700 : | /** | ||
| 701 : | * General error handling function to write form data to the session and redirect to the setup form | ||
| 702 : | * when errors occur. | ||
| 703 : | * | ||
| 704 : | * @param string $errorMsg | ||
| 705 : | * @param string $redirectPage | ||
| 706 : | * | ||
| 707 : | */ | ||
| 708 : | private function setError($errorMsg, $redirectPage) { | ||
| 709 : | $this->data['installation']['dbPassword']=''; | ||
| 710 : | $this->data['installation']['dbVerifyPassword']=''; | ||
| 711 : | $this->Session->Write('form_data', $this->data['installation']); | ||
| 712 : | $this->Session->Write('setup_error', $errorMsg); | ||
| 713 : | $this->redirect("/installation/$redirectPage"); | ||
| 714 : | exit; | ||
| 715 : | } | ||
| 716 : | |||
| 717 : | /** | ||
| 718 : | * Writes out a cakePHP formatted database file based on the given installation parameters | ||
| 719 : | * | ||
| 720 : | */ | ||
| 721 : | private function writeDatabaseConfigFile() { | ||
| 722 : | |||
| 723 : | $dbPlatform = $this->dbPlatform; | ||
| 724 : | $dbHostname = $this->dbHostname; | ||
| 725 : | $dbUsername = $this->dbUsername; | ||
| 726 : | $dbPassword = $this->dbPassword; | ||
| 727 : | $dbName = $this->dbName; | ||
| 728 : | $dbPrefix = $this->dbPrefix; | ||
| 729 : | $default = '$default'; | ||
| 730 : | |||
| 731 : | if ($this->dbPlatform=='mysql' || $this->dbPlatform=='postgres') { | ||
| 732 : | $dbConfigText = "<?php\n"; | ||
| 733 : | $dbConfigText.= "class DATABASE_CONFIG {\n"; | ||
| 734 : | $dbConfigText.= "\n"; | ||
| 735 : | $dbConfigText.= " var $default = array(\n"; | ||
| 736 : | $dbConfigText.= " 'driver' => '$dbPlatform',\n"; | ||
| 737 : | $dbConfigText.= " 'persistent' => false,\n"; | ||
| 738 : | $dbConfigText.= " 'host' => '$dbHostname',\n"; | ||
| 739 : | $dbConfigText.= " 'port' => '',\n"; | ||
| 740 : | $dbConfigText.= " 'login' => '$dbUsername',\n"; | ||
| 741 : | $dbConfigText.= " 'password' => '$dbPassword',\n"; | ||
| 742 : | $dbConfigText.= " 'database' => '$dbName',\n"; | ||
| 743 : | $dbConfigText.= " 'prefix' => '$dbPrefix'\n"; | ||
| 744 : | $dbConfigText.= " );\n"; | ||
| 745 : | $dbConfigText.= "\n"; | ||
| 746 : | $dbConfigText.= "}\n"; | ||
| 747 : | $dbConfigText.= "?>"; | ||
| 748 : | } else if ($this->dbPlatform=='sqlite') { | ||
| 749 : | //Build full database variable (i.e.) path/dbname | ||
| 750 : | $database = $this->dbPath.$this->dbName; | ||
| 751 : | |||
| 752 : | //No username or password needed & the database name is the full path | ||
| 753 : | $dbConfigText = "<?php\n"; | ||
| 754 : | $dbConfigText.= "class DATABASE_CONFIG {\n"; | ||
| 755 : | $dbConfigText.= "\n"; | ||
| 756 : | $dbConfigText.= " var $default = array(\n"; | ||
| 757 : | $dbConfigText.= " 'driver' => 'sqlite',\n"; | ||
| 758 : | $dbConfigText.= " 'persistent' => false,\n"; | ||
| 759 : | $dbConfigText.= " 'host' => '$dbHostname',\n"; | ||
| 760 : | $dbConfigText.= " 'port' => '',\n"; | ||
| 761 : | $dbConfigText.= " 'database' => '$database',\n"; | ||
| 762 : | $dbConfigText.= " 'prefix' => '$dbPrefix'\n"; | ||
| 763 : | $dbConfigText.= " );\n"; | ||
| 764 : | $dbConfigText.= "\n"; | ||
| 765 : | $dbConfigText.= "}\n"; | ||
| 766 : | $dbConfigText.= "?>"; | ||
| 767 : | } else { | ||
| 768 : | $this->setError('Invalid Database Platform', 'install1'); | ||
| 769 : | } | ||
| 770 : | |||
| 771 : | //Output the new CakePHP database.php config file | ||
| 772 : | $database_file = CONFIGS.'database.php'; | ||
| 773 : | if(($handle = @fopen($database_file, 'w'))===false){ | ||
| 774 : | $errorMsg = sprintf(__('Failed to open the %s file for writing! '), $database_file); | ||
| 775 : | $errorMsg .= __('Please make sure the web server user has write permissions on this file until the installation is complete'); | ||
| 776 : | $this->setError($errorMsg, 'install1'); | ||
| 777 : | } | ||
| 778 : | |||
| 779 : | if ($handle) { | ||
| 780 : | fwrite($handle, $dbConfigText); | ||
| 781 : | fclose($handle); | ||
| 782 : | } | ||
| 783 : | |||
| 784 : | } | ||
| 785 : | |||
| 786 : | |||
| 787 : | /** | ||
| 788 : | * Takes an incoming SQL statement and adds the user specificed table prefix | ||
| 789 : | * | ||
| 790 : | * @param string $sql | ||
| 791 : | * @return prepared_sql | ||
| 792 : | */ | ||
| 793 : | private function setPrefix($sql) { | ||
| 794 : | $generic_prefix_pattern = '/#__/'; | ||
| 795 : | $prepared_sql = preg_replace($generic_prefix_pattern, $this->dbPrefix, $sql); | ||
| 796 : | return $prepared_sql; | ||
| 797 : | } | ||
| 798 : | |||
| 799 : | /** | ||
| 800 : | * Used to load data from external SQL files | ||
| 801 : | * | ||
| 802 : | * @param string $type | ||
| 803 : | */ | ||
| 804 : | private function loadSQLData($type) { | ||
| 805 : | //Include the prepared SQL statements | ||
| 806 : | switch ($type) { | ||
| 807 : | case 'default': | ||
| 808 : | $data_file = VENDORS.'mambo'.DS.'default_data.sql'; | ||
| 809 : | break; | ||
| 810 : | case 'sample': | ||
| 811 : | $data_file = VENDORS.'mambo'.DS.'sample_data.sql'; | ||
| 812 : | break; | ||
| 813 : | default: | ||
| 814 : | echo __('Invalid type'); | ||
| 815 : | exit; | ||
| 816 : | } | ||
| 817 : | |||
| 818 : | if (($handle = @fopen($data_file, 'r'))===false) { | ||
| 819 : | $errorMsg = sprintf(__('Failed to open the %s file!'), $data_file); | ||
| 820 : | $this->setError($errorMsg, 'install1'); | ||
| 821 : | } | ||
| 822 : | |||
| 823 : | if ($handle) { | ||
| 824 : | $sql_statements = array(); | ||
| 825 : | $sql_statements = explode(PHP_EOL, fread($handle, filesize($data_file))); | ||
| 826 : | fclose($handle); | ||
| 827 : | } | ||
| 828 : | |||
| 829 : | //Build and execute the dynamic SQL | ||
| 830 : | $ac = count($sql_statements); | ||
| 831 : | for ($i = 1; $i < $ac; $i++) { | ||
| 832 : | /* Call to set MS SQL Server specific IDENTITY_INSERT value. In order to insert a specific value into the PK / AUTONUM | ||
| 833 : | columns. MS SQL Server requires fully expanded INSERT statement with columns named and the IDENTITY_INSERT On/Off | ||
| 834 : | attribute. Can only set for one table at a time. */ | ||
| 835 : | if (substr($sql_statements[$i],0,6)=="INSERT" || (substr($sql_statements[$i],0,3)=="SET" && $this->dbPlatform=='mssql')) { | ||
| 836 : | $prepared_sql = $this->setPrefix($sql_statements[$i]); | ||
| 837 : | $this->executeInsert($prepared_sql, 'install1'); | ||
| 838 : | } | ||
| 839 : | |||
| 840 : | } | ||
| 841 : | } | ||
| 842 : | |||
| 843 : | /** | ||
| 844 : | * Used to drop indexes after a table rename on platforms that need it | ||
| 845 : | * | ||
| 846 : | */ | ||
| 847 : | private function dropIndexes() { | ||
| 848 : | //Include the prepared SQL statements | ||
| 849 : | if ($this->dbPlatform=='postgres') { | ||
| 850 : | $drop_index = VENDORS.DS.'mambo'.DS.'drop_index.sql';; | ||
| 851 : | if (($handle = @fopen($drop_index, 'r'))===false) { | ||
| 852 : | $errorMsg = sprintf(__('Failed to open the %s file!'), $drop_index); | ||
| 853 : | $this->setError($errorMsg, 'install1'); | ||
| 854 : | } | ||
| 855 : | |||
| 856 : | if ($handle) { | ||
| 857 : | $sql_statements = array(); | ||
| 858 : | $sql_statements = explode(PHP_EOL, fread($handle, filesize($drop_index))); | ||
| 859 : | fclose($handle); | ||
| 860 : | } | ||
| 861 : | |||
| 862 : | //Build and execute the dynamic SQL | ||
| 863 : | $count = count($sql_statements); | ||
| 864 : | for ($i = 1; $i < $count; $i++) { | ||
| 865 : | /* Call to set MS SQL Server specific IDENTITY_INSERT value. In order to insert a specific value into the PK / AUTONUM | ||
| 866 : | columns. MS SQL Server requires fully expanded INSERT statement with columns named and the IDENTITY_INSERT On/Off | ||
| 867 : | attribute. Can only set for one table at a time. */ | ||
| 868 : | if (substr($sql_statements[$i],0,4)=="DROP") { | ||
| 869 : | $prepared_sql = $this->setPrefix($sql_statements[$i]); | ||
| 870 : | $this->executeInsert($prepared_sql, 'install1'); | ||
| 871 : | } | ||
| 872 : | } | ||
| 873 : | } | ||
| 874 : | |||
| 875 : | return; | ||
| 876 : | } | ||
| 877 : | |||
| 878 : | /** | ||
| 879 : | * Generic function used to execute and error check incoming SQL statments | ||
| 880 : | * | ||
| 881 : | * @param string $sql | ||
| 882 : | */ | ||
| 883 : | private function executeInsert($sql, $redirectPage) { | ||
| 884 : | if ($this->db->Execute($sql)===false) { | ||
| 885 : | $errors = $this->db->ErrorMsg().": Erroring SQL was: $sql"; | ||
| 886 : | $this->setError($errors, $redirectPage); | ||
| 887 : | } | ||
| 888 : | } | ||
| 889 : | |||
| 890 : | /** | ||
| 891 : | * Drops requested database tables | ||
| 892 : | * | ||
| 893 : | * @param string $table | ||
| 894 : | */ | ||
| 895 : | private function dropTable($table) { | ||
| 896 : | //Build the rename table SQL statement | ||
| 897 : | $sql = $this->dict->DropTableSQL($table); | ||
| 898 : | |||
| 899 : | if ($this->dict->executeSQLArray($sql)===false) { | ||
| 900 : | $errors = $this->db->ErrorMsg().": Erroring SQL was: $sql"; | ||
| 901 : | $this->setError($errors, 'install1'); | ||
| 902 : | } | ||
| 903 : | } | ||
| 904 : | |||
| 905 : | /** | ||
| 906 : | * If the select db platform is Oracle or Postgres we need to drop the table sequences as well. | ||
| 907 : | * They would drop if a drop table was done, but not with a rename so we need to drop manually before | ||
| 908 : | * we run the new CREATE TABLE. | ||
| 909 : | * | ||
| 910 : | * @param string $table | ||
| 911 : | */ | ||
| 912 : | private function dropSequence($table) { | ||
| 913 : | //Note: In reality only tables with a autoincrement column have a sequence | ||
| 914 : | if ($this->dbPlatform=='oracle') { | ||
| 915 : | $sequence = 'seq_' . $table; | ||
| 916 : | $sql="DROP SEQUENCE $sequence"; | ||
| 917 : | } else if ($this->dbPlatform=='postgres') { | ||
| 918 : | $sequence = $table.'_id_seq'; | ||
| 919 : | $sql="DROP SEQUENCE IF EXISTS $sequence CASCADE"; | ||
| 920 : | } else { | ||
| 921 : | return; | ||
| 922 : | } | ||
| 923 : | |||
| 924 : | //Execute the sql | ||
| 925 : | if ($this->db->Execute($sql)===false) { | ||
| 926 : | $errors = $this->db->ErrorMsg().": Erroring SQL was: $sql"; | ||
| 927 : | $this->setError($errors, 'install1'); | ||
| 928 : | } | ||
| 929 : | } | ||
| 930 : | |||
| 931 : | /** | ||
| 932 : | * Renames requested database tables | ||
| 933 : | * | ||
| 934 : | * @param string $table | ||
| 935 : | * @param string $newname | ||
| 936 : | */ | ||
| 937 : | private function renameTable($table, $newname) { | ||
| 938 : | //Build the rename table SQL statement | ||
| 939 : | $sql = $this->dict->RenameTableSQL($table,$newname); | ||
| 940 : | if ($this->dict->executeSQLArray($sql)===false) { | ||
| 941 : | $errors = $this->db->ErrorMsg().": Erroring SQL was: $sql"; | ||
| 942 : | $this->setError($errors, 'install1'); | ||
| 943 : | } | ||
| 944 : | } | ||
| 945 : | |||
| 946 : | /** | ||
| 947 : | * Creates the ADOdb database connection to the selected db platform | ||
| 948 : | * | ||
| 949 : | * @return db | ||
| 950 : | */ | ||
| 951 : | private function setupConnection() { | ||
| 952 : | /* Valid ADOdb platform options include: mysql, postgres, sqlite, oracle, firebird, db2, mssql | ||
| 953 : | Note: The setup process has been built with all of the platforms listed above in mind. Some testing has occurred in each | ||
| 954 : | and the setup code can actually be used to install on all except for db2 without major modifications. However, at the moment | ||
| 955 : | Mambo itself is only setup through CakePHP to work with Mysql 4/5, postgres, & sqlite3. More should be added in time... */ | ||
| 956 : | |||
| 957 : | //Include the ADOdb library files | ||
| 958 : | vendor('adodb'.DS.'adodb.inc'); | ||
| 959 : | vendor('adodb'.DS.'adodb-xmlschema.inc'); | ||
| 960 : | |||
| 961 : | /*///////////////////////////////////////////////////////////////////// | ||
| 962 : | MySQL / PostgreSQL connection Parameters | ||
| 963 : | *////////////////////////////////////////////////////////////////////// | ||
| 964 : | |||
| 965 : | if ($this->dbPlatform=='mysql' || $this->dbPlatform=='postgres') { | ||
| 966 : | |||
| 967 : | $db = ADONewConnection( $this->dbPlatform ); | ||
| 968 : | //Debug set to 1 for verbose output | ||
| 969 : | $db->debug = 0; | ||
| 970 : | // Start by creating a normal ADODB connection. | ||
| 971 : | if (!@$db->Connect($this->dbHostname, $this->dbUsername, $this->dbPassword, $this->dbName, $this->dbPath)) { | ||
| 972 : | $this->setError($db->ErrorMsg(), 'install1'); | ||
| 973 : | } | ||
| 974 : | |||
| 975 : | } | ||
| 976 : | |||
| 977 : | /*////////////////////////////////////////////////////////////////////// | ||
| 978 : | SQLite2 connection Parameters | ||
| 979 : | */////////////////////////////////////////////////////////////////////// | ||
| 980 : | |||
| 981 : | if ($this->dbPlatform=='sqlite') { | ||
| 982 : | //SQLite 3 not supported at this point | ||
| 983 : | |||
| 984 : | $db = ADONewConnection('sqlite'); | ||
| 985 : | //Debug set to 1 for verbose output | ||
| 986 : | $db->debug = 0; | ||
| 987 : | //Try to connect (the db will actually be created if it does not exist and OS file permissions allow it. | ||
| 988 : | if (!@$db->Connect($this->dbPath.$this->dbName)) { | ||
| 989 : | //The normal $db->ErrorMsg() method doesn't handle SQLite errors so well. Using basic default message. | ||
| 990 : | $this->setError('Error creating or connecting to the SQLite database!', 'install1'); | ||
| 991 : | } | ||
| 992 : | |||
| 993 : | } | ||
| 994 : | |||
| 995 : | /*////////////////////////////////////////////////////////////////////// | ||
| 996 : | Oracle connection Parameters | ||
| 997 : | */////////////////////////////////////////////////////////////////////// | ||
| 998 : | |||
| 999 : | //Note: Oracle support must have been compiled into PHP | ||
| 1000 : | |||
| 1001 : | if ($this->dbPlatform=='oracle') { | ||
| 1002 : | |||
| 1003 : | $db = ADONewConnection( 'oci8' ); | ||
| 1004 : | //Debug set to 1 for verbose output | ||
| 1005 : | $db->debug = 0; | ||
| 1006 : | if (!$db->Connect($this->dbHostname, $this->dbUsername, $this->dbPassword)) { | ||
| 1007 : | $this->setError($db->ErrorMsg(), 'install1'); | ||
| 1008 : | } else { | ||
| 1009 : | // Set Oracle date format for inserts | ||
| 1010 : | $set_date_format = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"; | ||
| 1011 : | $db->Execute($set_date_format); | ||
| 1012 : | } | ||
| 1013 : | |||
| 1014 : | /************************************************************************** | ||
| 1015 : | With oci8, you can connect in multiple ways. Note that oci8 works | ||
| 1016 : | fine with newer versions of the Oracle, eg. 9i and 10g. | ||
| 1017 : | |||
| 1018 : | a. PHP and Oracle reside on the same machine, use default SID. | ||
| 1019 : | $db->Connect(false, 'scott', 'tiger'); | ||
| 1020 : | |||
| 1021 : | b. TNS Name defined in tnsnames.ora (or ONAMES or HOSTNAMES), eg. 'myTNS' | ||
| 1022 : | $db->PConnect(false, 'scott', 'tiger', 'myTNS'); | ||
| 1023 : | or | ||
| 1024 : | $db->PConnect('myTNS', 'scott', 'tiger'); | ||
| 1025 : | |||
| 1026 : | c. Host Address and SID | ||
| 1027 : | $conn->connectSID = true; | ||
| 1028 : | $conn->Connect('192.168.0.1', 'scott', 'tiger', 'SID'); | ||
| 1029 : | |||
| 1030 : | d. Host Address and Service Name | ||
| 1031 : | $conn->Connect('192.168.0.1', 'scott', 'tiger', 'servicename'); | ||
| 1032 : | |||
| 1033 : | e. Oracle connection string: | ||
| 1034 : | $cstr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port)) | ||
| 1035 : | (CONNECT_DATA=(SID=$sid)))"; | ||
| 1036 : | $db->Connect($cstr, 'scott', 'tiger'); | ||
| 1037 : | **************************************************************************/ | ||
| 1038 : | |||
| 1039 : | } | ||
| 1040 : | |||
| 1041 : | /*////////////////////////////////////////////////////////////////////// | ||
| 1042 : | DB2 connection Parameters (Not yet working...) | ||
| 1043 : | */////////////////////////////////////////////////////////////////////// | ||
| 1044 : | |||
| 1045 : | if ($this->dbPlatform=='db2') { | ||
| 1046 : | |||
| 1047 : | $db = ADONewConnection( $this->dbPlatform ); | ||
| 1048 : | $dsn = "driver={IBM db2 odbc DRIVER};Database=$this->dbName;hostname=$this->dbHostname;port=50000;protocol=TCPIP;". | ||
| 1049 : | "uid=$this->dbUsername; pwd=$this->dbPassword"; | ||
| 1050 : | //Debug set to 1 for verbose output | ||
| 1051 : | $db->debug = 0; | ||
| 1052 : | if (!@$db->Connect($dsn)) { | ||
| 1053 : | $this->setError($db->ErrorMsg(), 'install1'); | ||
| 1054 : | } | ||
| 1055 : | |||
| 1056 : | } | ||
| 1057 : | |||
| 1058 : | /*////////////////////////////////////////////////////////////////////// | ||
| 1059 : | Firebird connection Parameters (Not supported yet...) | ||
| 1060 : | */////////////////////////////////////////////////////////////////////// | ||
| 1061 : | |||
| 1062 : | //Note: ibase support must have been compiled into PHP | ||
| 1063 : | |||
| 1064 : | if ($this->dbPlatform=='firebird') { | ||
| 1065 : | |||
| 1066 : | $db = ADONewConnection('ibase'); | ||
| 1067 : | //Debug set to 1 for verbose output | ||
| 1068 : | $db->debug = 0; | ||
| 1069 : | if (!@$db->Connect($this->dbPath,$this->dbUsername,$this->dbPassword)) { | ||
| 1070 : | $this->setError($db->ErrorMsg(), 'install1'); | ||
| 1071 : | } | ||
| 1072 : | |||
| 1073 : | } | ||
| 1074 : | |||
| 1075 : | /*////////////////////////////////////////////////////////////////////// | ||
| 1076 : | MS SQL Server connection Parameters (tested with 2000 & 2005) | ||
| 1077 : | */////////////////////////////////////////////////////////////////////// | ||
| 1078 : | |||
| 1079 : | if ($this->dbPlatform=='mssql') { | ||
| 1080 : | |||
| 1081 : | $db = ADONewConnection('odbc_mssql'); | ||
| 1082 : | //Note: if using sql server 2005 you might need servername\instance for the Server string | ||
| 1083 : | $dsn = "Provider=MSDASQL; Driver={SQL Server}; Server=$this->dbHostname; Database=$this->dbName;"; | ||
| 1084 : | //Debug set to 1 for verbose output | ||
| 1085 : | $db->debug = 0; | ||
| 1086 : | if (!@$db->Connect($dsn,$this->dbUsername,$this->dbPassword)) { | ||
| 1087 : | $this->setError($db->ErrorMsg(), 'install1'); | ||
| 1088 : | } | ||
| 1089 : | |||
| 1090 : | //Or if you prefer to use the mssql extension (which is limited to mssql 6.5 functionality): | ||
| 1091 : | /* | ||
| 1092 : | $db = ADONewConnection('mssql'); | ||
| 1093 : | $db->debug = 0; | ||
| 1094 : | $db->Execute('servername', 'user', 'password', 'database'); | ||
| 1095 : | */ | ||
| 1096 : | |||
| 1097 : | } | ||
| 1098 : | |||
| 1099 : | return $db; | ||
| 1100 : | } | ||
| 1101 : | |||
| 1102 : | } | ||
| 1103 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

