[pLog-svn] r1608 - in plog/trunk: . class/config class/file
ork at devel.plogworld.net
ork at devel.plogworld.net
Sat Mar 26 20:00:48 GMT 2005
Author: ork
Date: 2005-03-26 20:00:48 +0000 (Sat, 26 Mar 2005)
New Revision: 1608
Modified:
plog/trunk/class/config/configfilestorage.class.php
plog/trunk/class/file/file.class.php
plog/trunk/wizard.php
Log:
added a createConfigFile() method in case there is no config.file and
changed the wizard.php.
Modified: plog/trunk/class/config/configfilestorage.class.php
===================================================================
--- plog/trunk/class/config/configfilestorage.class.php 2005-03-26 18:44:34 UTC (rev 1607)
+++ plog/trunk/class/config/configfilestorage.class.php 2005-03-26 20:00:48 UTC (rev 1608)
@@ -77,6 +77,43 @@
return $this->_configFile;
}
+ /**
+ * Create a new config file from scratch.
+ *
+ * $return true if config file could be created, false otherwise
+ */
+ function createConfigFile( $configFileName = null )
+ {
+ // please keep this synced to the release/config.properties.php.dist file.
+ $defaultConfigFile = '<?php
+ #
+ # database settings
+ #
+ $config["db_host"] = "";
+ $config["db_username"] = "";
+ $config["db_password"] = "";
+ $config["db_database"] = "";
+ #
+ # the database prefix will be appended to the name of each database tables in case you want
+ # to have more than one version of plog running at the same time, such as the stable and
+ # unstable one for testing. Each one could use a different prefix and therefore they could
+ # coexist in the same unique database. If you change this after the initial configuration done
+ # with the installation wizard, please make sure that you also rename the tables.
+ #
+ $config["db_prefix"] = "";
+ ?>';
+
+ $file = new File( $configFileName );
+ $writable = $file->open( 'w' );
+ if ($writable) {
+ $file->write( $defaultConfigFile );
+ $file->close();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Private function that given a piece of PHP data, will return an string representing
* it, literally. Examples:
Modified: plog/trunk/class/file/file.class.php
===================================================================
--- plog/trunk/class/file/file.class.php 2005-03-26 18:44:34 UTC (rev 1607)
+++ plog/trunk/class/file/file.class.php 2005-03-26 20:00:48 UTC (rev 1608)
@@ -398,5 +398,21 @@
return file_exists( $fileName );
}
+
+ /**
+ * returns true if the file could be touched
+ *
+ * Can be used to create a file or to reset the timestamp.
+ * @return true if successful or false otherwise
+ * @see PHP Function touch()
+ *
+ */
+ function touch( $fileName = null )
+ {
+ if( $fileName == null )
+ return false;
+
+ return touch($fileName);
+ }
}
?>
Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php 2005-03-26 18:44:34 UTC (rev 1607)
+++ plog/trunk/wizard.php 2005-03-26 20:00:48 UTC (rev 1608)
@@ -813,7 +813,20 @@
// before doing anything, we should check of the configuration file is
// writable by this script, or else, throw an error and bail out gracefully
$configFileName = $configFile->getConfigFileName();
- if( !File::isWritable( $configFileName )) {
+ if( !File::exists( $configFileName )) {
+ if (! File::touch( $configFileName ) ) {
+ $this->_view = new WizardView( "intro" );
+ $message = "Could not create the pLog configuration file $configFileName. Please make sure
+ that the file can be created by the user running the webserver. It is needed to
+ store the database configuration settings.";
+ $this->_view->setErrorMessage( $message );
+ $this->setCommonData( true );
+ return false;
+ } else {
+ ConfigFileStorage::createConfigFile( $configFileName );
+ }
+ }
+ if( File::exists( $configFileName ) && !File::isWritable( $configFileName )) {
$this->_view = new WizardView( "intro" );
$message = "Please make sure that the file $configFileName can be written by this script during
the installation process. It is needed to store the database configuration settings. Once the
@@ -1358,6 +1371,9 @@
// connect to the db
$this->_db = connectDb();
+ // store error messages in this var
+ $message = "";
+
if( !$this->_db ) {
$this->_view = new WizardView( "update1" );
WizardStepTwo::setDbConfigValues( $this->_view );
More information about the pLog-svn
mailing list