Example #1
0
 /**
  * Execute environment checks
  *
  * @access public
  * @param void
  * @return boolean
  */
 function execute()
 {
     $all_ok = true;
     // Check PHP version
     if (version_compare(PHP_VERSION, '5.0.2', 'ge')) {
         $this->addToChecklist('PHP version is ' . PHP_VERSION, true);
     } else {
         $this->addToChecklist('You PHP version is ' . PHP_VERSION . '. PHP 5.0.2 or newer is required', false);
         $all_ok = false;
     }
     // if
     foreach ($this->check_extensions as $extension_name) {
         if (extension_loaded($extension_name)) {
             $this->addToChecklist("'{$extension_name}' extension is loaded", true);
         } else {
             $this->addToChecklist("'{$extension_name}' extension is not loaded", false);
             $all_ok = false;
         }
         // if
     }
     // if
     if (is_array($this->check_is_writable)) {
         foreach ($this->check_is_writable as $relative_folder_path) {
             $check_this = INSTALLATION_PATH . $relative_folder_path;
             $is_writable = false;
             if (is_file($check_this)) {
                 $is_writable = file_is_writable($check_this);
             } elseif (is_dir($check_this)) {
                 $is_writable = folder_is_writable($check_this);
             }
             // if
             if ($is_writable) {
                 $this->addToChecklist("{$relative_folder_path} is writable", true);
             } else {
                 $this->addToChecklist("{$relative_folder_path} is not writable", false);
                 $all_ok = false;
             }
             // if
         }
         // foreach
     }
     // if
     $this->setContentFromTemplate('checks.php');
     if (ini_get('zend.ze1_compatibility_mode')) {
         $this->addToChecklist('zend.ze1_compatibility_mode is set to On. This can cause some strange problems. It is strongly suggested to turn this value to Off (in your php.ini file)', false);
     }
     // if
     if ($all_ok) {
         return $this->isSubmited();
     }
     // if
     $this->setNextDisabled(true);
     return false;
 }
Example #2
0
 /**
 * Update content of specific repository file (update $update_file with content from $source)
 *
 * @param string $source Source file
 * @param string $update_file File that need to be updated
 * @return boolean
 */
 static function updateFile($source, $update_file) {
   $destination = self::getFilePath($update_file);
   
   if(!is_readable($source)) {
     return false;
   } // if
   if(!file_is_writable($destination)) {
     return false;
   } // if
   
   return copy($source, $destination);
 } // updateFile
 /**
  * Function that opens zip file for writing
  *
  * @param string $zip_filename
  */
 function open($zip_filename)
 {
     $this->zip_filename = $zip_filename;
     if (!$this->fail_safe_method) {
         return $this->zip_file->open($zip_filename, ZIPARCHIVE::OVERWRITE);
     } else {
         if (is_file($zip_filename)) {
             return file_is_writable($zip_filename);
         } else {
             return folder_is_writable(dirname($zip_filename));
         }
         // if
     }
     // if
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     define('ROOT', realpath(dirname(__FILE__) . '/../../../'));
     // ---------------------------------------------------
     //  Load config
     // ---------------------------------------------------
     $config_is_set = (require_once INSTALLATION_PATH . '/config/config.php');
     if (!$config_is_set) {
         $this->printMessage('Valid config file was not found!', true);
         return false;
     } else {
         $this->printMessage('Config file found and loaded.');
     }
     // if
     // ---------------------------------------------------
     //  Check for version match (pre-0.7.0 had no version?)
     // ---------------------------------------------------
     if (defined('PRODUCT_VERSION') && PRODUCT_VERSION !== '0.6') {
         $this->printMessage('This upgrade script can be used only to upgrade 0.6 to 0.7', true);
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Check if files and folders are writable
     // ---------------------------------------------------
     foreach ($this->check_is_writable as $relative_path) {
         $path = ROOT . $relative_path;
         if (is_file($path)) {
             if (file_is_writable($path)) {
                 $this->printMessage("File '{$relative_path}' exists and is writable");
             } else {
                 $this->printMessage("File '{$relative_path}' is not writable", true);
                 return false;
             }
             // if
         } elseif (is_dir($path)) {
             if (folder_is_writable($path)) {
                 $this->printMessage("Folder '{$relative_path}' exists and is writable");
             } else {
                 $this->printMessage("Folder '{$relative_path}' is not writable", true);
                 return false;
             }
             // if
         } else {
             $this->printMessage("'{$relative_path}' does not exists on the system", true);
             return false;
         }
         // if
     }
     // foreach
     // ---------------------------------------------------
     //  Check if extensions are loaded
     // ---------------------------------------------------
     foreach ($this->check_extensions as $extension_name) {
         if (extension_loaded($extension_name)) {
             $this->printMessage("Extension '{$extension_name}' is loaded");
         } else {
             $this->printMessage("Extension '{$extension_name}' is not loaded", true);
             return false;
         }
         // if
     }
     // foreach
     // ---------------------------------------------------
     //  Connect to database
     // ---------------------------------------------------
     if ($this->database_connection = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
         if (mysql_select_db(DB_NAME, $this->database_connection)) {
             $this->printMessage('Upgrade script has connected to the database.');
         } else {
             $this->printMessage('Failed to select database ' . DB_NAME);
             return false;
         }
         // if
     } else {
         $this->printMessage('Failed to connect to database');
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Check MySQL version
     // ---------------------------------------------------
     $mysql_version = mysql_get_server_info($this->database_connection);
     if ($mysql_version && version_compare($mysql_version, '4.1', '>=')) {
         $constants['DB_CHARSET'] = 'utf8';
         @mysql_query("SET NAMES 'utf8'", $this->database_connection);
         tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
         tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
     } else {
         tpl_assign('default_collation', $default_collation = '');
         tpl_assign('default_charset', $default_charset = '');
     }
     // if
     tpl_assign('table_prefix', TABLE_PREFIX);
     // ---------------------------------------------------
     //  Check test query
     // ---------------------------------------------------
     $test_table_name = TABLE_PREFIX . 'test_table';
     $test_table_sql = "CREATE TABLE `{$test_table_name}` (\n        `id` int(10) unsigned NOT NULL auto_increment,\n        `name` varchar(50) {$default_collation} NOT NULL default '',\n        PRIMARY KEY  (`id`)\n      ) ENGINE=InnoDB {$default_charset};";
     if (@mysql_query($test_table_sql, $this->database_connection)) {
         $this->printMessage('Test query has been executed. Its safe to proceed with database migration.');
         @mysql_query("DROP TABLE `{$test_table_name}`", $this->database_connection);
     } else {
         $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($this->database_connection), true);
         return false;
     }
     // if
     //return ;
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = tpl_fetch(get_template_path('db_migration/onion'));
     if ($this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     } else {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     // if
     if (!$this->importMessageComments()) {
         return false;
     }
     // if
     if (!$this->importProjectDocuments()) {
         return false;
     }
     // if
     $this->cleanApplicationLogs();
     $this->fixConfigFile();
     $this->printMessage('ProjectPier has been upgraded. You are now running ProjectPier 0.7. Enjoy!');
 }
 /**
 * Set log_file value
 *
 * @param string $value
 * @return null
 * @throws FileNotWriableError If file exists and is not writable
 * @throws DirDnxError If file does not exists and parent directory does not exists
 * @throws DirNotWritableError If file does not exists, but parent exists and is not writable
 */
 function setLogFile($value) {
   $file_path = $value;
   if(is_file($file_path)) {
     if(!file_is_writable($file_path)) {
       throw new FileNotWriableError($file_path);
     } // if
   } else {
     $folder_path = dirname($file_path);
     if(!is_dir($folder_path)) {
       throw new DirDnxError($folder_path);
     } // if
     if(!folder_is_writable($folder_path)) {
       throw new DirNotWritableError($folder_path);
     } // if
   } // if
   $this->log_file = $value;
 } // setLogFile
 /**
  * Execute upgrade script that is responsible for upgrade process from installed version to target version
  *
  * @param string $version_from
  * @param string $to_version
  * @return null
  */
 function upgrade($version_from, $version_to)
 {
     $scripts = $this->getScripts();
     // check if version_to exists and there's a path from current version to version_to.
     if (is_array($scripts)) {
         // scripts are sorted according to the "to" upgrade version
         $exists = false;
         $current = $version_from;
         foreach ($scripts as $script) {
             if ($script->worksFor($current)) {
                 $current = $script->getVersionTo();
                 if (version_compare($current, $version_to) == 0) {
                     $exists = true;
                     break;
                 }
             }
         }
         // foreach
         if (!$exists) {
             $this->printMessage("There is no upgrade path from version {$version_from} to {$version_to}.");
             return;
         }
         // include config file
         $config_is_set = @(include_once INSTALLATION_PATH . '/config/config.php');
         if (!$config_is_set) {
             $this->printMessage('Valid config file was not found!', true);
             return false;
         } else {
             $this->printMessage('Config file found and loaded.');
         }
         // if
         // check preconditions
         $write_checks = array();
         $ext_checks = array();
         foreach ($scripts as $script) {
             if (version_compare($script->getVersionTo(), $version_from) > 0 && version_compare($script->getVersionTo(), $version_to) <= 0) {
                 $write_checks = array_merge($write_checks, $script->getCheckIsWritable());
                 $ext_checks = array_merge($ext_checks, $script->getCheckExtensions());
             }
             // if
         }
         // foreach
         $write_checks = array_unique($write_checks);
         $ext_checks = array_unique($ext_checks);
         // check for writable files and folders
         foreach ($write_checks as $relative_path) {
             $path = INSTALLATION_PATH . $relative_path;
             if (is_file($path)) {
                 if (file_is_writable($path)) {
                     $this->printMessage("File '{$relative_path}' exists and is writable");
                 } else {
                     $this->printMessage("File '{$relative_path}' is not writable", true);
                     return false;
                 }
                 // if
             } else {
                 if (is_dir($path)) {
                     if (folder_is_writable($path)) {
                         $this->printMessage("Folder '{$relative_path}' exists and is writable");
                     } else {
                         $this->printMessage("Folder '{$relative_path}' is not writable", true);
                         return false;
                     }
                     // if
                 } else {
                     $this->printMessage("'{$relative_path}' does not exists on the system", true);
                     return false;
                 }
             }
             // if
         }
         // foreach
         // check for loaded extensions
         foreach ($ext_checks as $extension_name) {
             if (extension_loaded($extension_name)) {
                 $this->printMessage("Extension '{$extension_name}' is loaded");
             } else {
                 $this->printMessage("Extension '{$extension_name}' is not loaded", true);
                 return false;
             }
             // if
         }
         // foreach
         // connect to database
         if ($dbc = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
             if (mysql_select_db(DB_NAME, $dbc)) {
                 $this->printMessage('Upgrade script has connected to the database.');
             } else {
                 $this->printMessage('Failed to select database ' . DB_NAME);
                 return false;
             }
             // if
         } else {
             $this->printMessage('Failed to connect to database');
             return false;
         }
         // if
         // check MySQL version
         $mysql_version = mysql_get_server_info($dbc);
         if ($mysql_version && version_compare($mysql_version, "4.1", '>=')) {
             $constants['DB_CHARSET'] = 'utf8';
             @mysql_query("SET NAMES 'utf8'", $dbc);
             tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
             tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
         } else {
             tpl_assign('default_collation', $default_collation = '');
             tpl_assign('default_charset', $default_charset = '');
         }
         // if
         tpl_assign('table_prefix', TABLE_PREFIX);
         if (defined('DB_ENGINE')) {
             tpl_assign('engine', DB_ENGINE);
         } else {
             tpl_assign('engine', 'InnoDB');
         }
         // check test query
         $test_table_name = TABLE_PREFIX . 'test_table';
         $test_table_sql = "CREATE TABLE `{$test_table_name}` (\n\t\t\t\t`id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t\t`name` varchar(50) {$default_collation} NOT NULL default '',\n\t\t\t\tPRIMARY KEY  (`id`)\n\t\t\t\t) ENGINE=InnoDB {$default_charset};";
         if (@mysql_query($test_table_sql, $dbc)) {
             $this->printMessage('Test query has been executed. Its safe to proceed with database migration.');
             @mysql_query("DROP TABLE `{$test_table_name}`", $dbc);
         } else {
             $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($dbc), true);
             return false;
         }
         // if
         // execute scripts
         foreach ($scripts as $script) {
             if (version_compare($script->getVersionTo(), $version_from) > 0 && version_compare($script->getVersionTo(), $version_to) <= 0) {
                 $script->setDatabaseConnection($dbc);
                 if ($script->execute() === false) {
                     $this->printMessage("Error upgrading to version " . $script->getVersionTo());
                     break;
                 }
                 $last_correct_version = $script->getVersionTo();
                 tpl_assign('version', $last_correct_version);
                 file_put_contents(INSTALLATION_PATH . '/config/installed_version.php', tpl_fetch(get_template_path('installed_version')));
             }
             // if
         }
         // foreach
         if (isset($last_correct_version)) {
             @mysql_query("UPDATE `" . TABLE_PREFIX . "config_options` SET `value` = 0 WHERE `name` = 'upgrade_last_check_new_version'");
             tpl_assign('version', $last_correct_version);
             return file_put_contents(INSTALLATION_PATH . '/config/installed_version.php', tpl_fetch(get_template_path('installed_version')));
         }
     }
     // if
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     define('ROOT', realpath(dirname(__FILE__) . '/../../../'));
     // ---------------------------------------------------
     //  Load config
     // ---------------------------------------------------
     $config_is_set = (require_once INSTALLATION_PATH . '/config/config.php');
     if (!$config_is_set) {
         $this->printMessage('Valid config files was not found!', true);
         return false;
     } else {
         $this->printMessage('Config file found and loaded.');
     }
     // if
     if (PRODUCT_VERSION == '0.8.6') {
         $this->printMessage('You are already running ProjectPier 0.8.6');
         return true;
     }
     // if
     if (PRODUCT_VERSION !== '0.8.0.3') {
         $this->printMessage('This upgrade script can be used only to upgrade 0.8.0.3 to 0.8.6', true);
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Connect to database
     // ---------------------------------------------------
     if ($this->database_connection = mysql_connect(DB_HOST, DB_USER, DB_PASS)) {
         $this->printMessage('Upgrade script has connected to database ' . DB_NAME);
         if (mysql_select_db(DB_NAME, $this->database_connection)) {
             $this->printMessage('Upgrade selected database ' . DB_NAME);
         } else {
             $this->printMessage('Failed to select database ' . DB_NAME);
             return false;
         }
         // if
     } else {
         $this->printMessage('Failed to connect to database ' . DB_HOST);
         return false;
     }
     // if
     // ---------------------------------------------------
     //  Check MySQL version
     // ---------------------------------------------------
     $mysql_version = mysql_get_server_info($this->database_connection);
     if ($mysql_version && version_compare($mysql_version, '4.1', '>=')) {
         $constants['DB_CHARSET'] = 'utf8';
         mysql_query("SET NAMES 'utf8'", $this->database_connection);
         tpl_assign('default_collation', $this->default_collation = 'collate utf8_unicode_ci');
         tpl_assign('default_charset', $this->default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
     } else {
         tpl_assign('default_collation', $this->default_collation = '');
         tpl_assign('default_charset', $this->default_charset = '');
     }
     // if
     tpl_assign('table_prefix', TABLE_PREFIX);
     // ---------------------------------------------------
     //  Check test query
     // ---------------------------------------------------
     $test_table_name = TABLE_PREFIX . 'test_table';
     $test_table_sql = "CREATE TABLE `{$test_table_name}` (\n        `id` int(10) unsigned NOT NULL auto_increment,\n        `name` varchar(50) {$this->default_collation} NOT NULL default '',\n        PRIMARY KEY  (`id`)\n      ) ENGINE=InnoDB {$this->default_charset};";
     if (mysql_query($test_table_sql, $this->database_connection)) {
         $this->printMessage('Test query has been executed. It is safe to proceed with database migration.');
         mysql_query("DROP TABLE `{$test_table_name}`", $this->database_connection);
     } else {
         $this->printMessage('Failed to executed test query. MySQL said: ' . mysql_error($this->database_connection), true);
         return false;
     }
     // if
     if (!file_is_writable(INSTALLATION_PATH . '/config/config.php')) {
         $this->printMessage('Configuration file is not writable.', true);
         return false;
     }
     // if
     $this->printMessage('Configuration file is writable.');
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     mysql_query('BEGIN WORK');
     if ($this->upgradePermissions() === false) {
         mysql_query('ROLLBACK');
         $this->printMessage('Upgrade process failed!', true);
         return false;
     }
     // if
     if ($this->addPluginsTable() === false) {
         mysql_query('ROLLBACK');
         $this->printMessage('Upgrade process failed!', true);
         return false;
     }
     // if
     if ($this->fixConfigFile() === false) {
         mysql_query('ROLLBACK');
         $this->printMessage('Upgrade process failed!', true);
         return false;
     }
     // if
     if (mysql_query('COMMIT')) {
         $this->printMessage('ProjectPier has been upgraded. You are now running ProjectPier 0.8.6. Enjoy!');
         return true;
     } else {
         $this->printMessage('Failed to commit updates. Upgrade process failed!', true);
         return false;
     }
     // if
 }
 /**
  * This function is used for saving files that are loaded to file in case 
  * you transformed the resource and want to save it back to the file. If 
  * this file is new or you want to change its type use saveAs() function
  *
  * @param void
  * @return boolean
  * @throws ImageTypeNotSupportedError
  * @throws FileNotWritableError
  */
 function save()
 {
     if (!$this->isLoaded() || !is_file($this->getSource())) {
         throw new Error('This image was not loaded from the file. Use saveAs() function instead of save() - there you\'ll be able to specify output file and type');
     }
     // if
     if (!file_is_writable($this->getSource())) {
         throw new FileNotWritableError($this->getSource());
     }
     // if
     switch ($this->getImageType()) {
         case IMAGETYPE_PNG:
             imagepng($this->resource, $this->getSource());
             break;
         case IMAGETYPE_JPG:
             imagejpeg($this->resource, $this->getSource(), 80);
             break;
         case IMAGETYPE_GIF:
             imagegif($this->resource, $this->getSource());
             break;
         default:
             throw new ImageTypeNotSupportedError(null, $this->getImageType());
     }
     // switch
     return true;
 }
 /**
  * Safe file attribute value to a file
  *
  * @param void
  * @return boolean
  */
 protected function saveFileAttributes()
 {
     $file = $this->getAttributesFilePath();
     if (is_file($file) && !file_is_writable($file)) {
         throw new FileNotWritableError($file);
     }
     // if
     return file_put_contents($file, "<?php\n\nreturn " . var_export($this->attributes, true) . ";\n\n?>");
 }
Example #10
0
	/**
	 * Execute environment checks
	 *
	 * @access public
	 * @param void
	 * @return boolean
	 */
	function execute() {
		$all_ok = true;

		// Check PHP version
		if(version_compare(PHP_VERSION, '5.0.2', 'ge')) {
			$this->addToChecklist('PHP version is ' . PHP_VERSION, true);
		} else {
			$this->addToChecklist('You PHP version is ' . PHP_VERSION . '. PHP 5.0.2 or newer is required', false);
			$all_ok = false;
		} // if

		foreach($this->check_extensions as $extension_name) {
			if(extension_loaded($extension_name)) {
				$this->addToChecklist("'$extension_name' extension is loaded", true);
			} else {
				$this->addToChecklist("'$extension_name' extension is not loaded", false);
				$all_ok = false;
			} // if
		} // if

		if(is_array($this->check_is_writable)) {
			foreach($this->check_is_writable as $relative_folder_path) {
				$check_this = INSTALLATION_PATH . $relative_folder_path;

				$is_writable = false;
				if(is_file($check_this)) {
					$is_writable = file_is_writable($check_this);
				} elseif(is_dir($check_this)) {
					$is_writable = folder_is_writable($check_this);
				} else {
					 
				}

				if($is_writable) {
					$this->addToChecklist("$relative_folder_path is writable", true);
				} else {
					$this->addToChecklist("$relative_folder_path is not writable", false);
					$all_ok = false;
				} // if
			} // foreach
		} // if
		$memory_config_value = ini_get('memory_limit');
		if($memory_config_value && $memory_config_value!==0 && trim($memory_config_value) != ''){
			$memory_limit = $this->return_bytes($memory_config_value); // Memory allocated to PHP scripts
			if ($memory_limit > 0){
				$suggested_memory = 12582912;
				if ( $memory_limit < $suggested_memory ) {
					$this->addToChecklist("PHP Variable 'memory_limit' is $memory_limit which might not be enough for Feng Office. You should increase it to at least $suggested_memory in your php.ini.", false);
				}
			}
		}

		$this->setContentFromTemplate('checks.php');

		if(ini_get('zend.ze1_compatibility_mode')) {
			$this->addToChecklist('zend.ze1_compatibility_mode is set to On. This can cause some strange problems. It is strongly suggested to turn this value to Off (in your php.ini file)', false);
		} // if

		if($all_ok) {
			return $this->isSubmited();
		} // if

		$this->setNextDisabled(true);
		return false;
	} // execute