← Back to team overview

amm-dev-tem team mailing list archive

[Branch ~amm-dev-tem/amm/trunk] Rev 33: Created setup procedure

 

------------------------------------------------------------
revno: 33
committer: The Whole Life To Learn <thewholelifetolearn@xxxxxxxxx>
branch nick: sources
timestamp: Sun 2011-07-17 21:12:32 +0200
message:
  Created setup procedure
removed:
  app/tmp/cache/models/
added:
  app/config/database.php
  app/controllers/setup_controller.php
  app/models/install_db.sql
  app/models/setup.php
  app/tmp/cache/models/
  app/views/setup/
  app/views/setup/finish.ctp
  app/views/setup/index.ctp
  app/views/setup/installed.ctp
  app/views/setup/second_step.ctp
modified:
  .bzrignore


--
lp:amm
https://code.launchpad.net/~amm-dev-tem/amm/trunk

Your team AMM dev team is subscribed to branch lp:amm.
To unsubscribe from this branch go to https://code.launchpad.net/~amm-dev-tem/amm/trunk/+edit-subscription
=== modified file '.bzrignore'
--- .bzrignore	2011-05-27 07:58:31 +0000
+++ .bzrignore	2011-07-17 19:12:32 +0000
@@ -24,3 +24,5 @@
 app/webroot/uploads/people/user_male__64_64x64.png
 app/tmp/cache/models/cake_model_default_authorizations
 app/tmp/cache/models/cake_model_default_authorizations_members
+app/tmp/cache/models
+app/tmp/cache/models/cake_model_default_amm-dev_list

=== added file 'app/config/database.php'
=== added file 'app/controllers/setup_controller.php'
--- app/controllers/setup_controller.php	1970-01-01 00:00:00 +0000
+++ app/controllers/setup_controller.php	2011-07-17 19:12:32 +0000
@@ -0,0 +1,93 @@
+<?php
+/**
+ *
+ * PHP versions 4 and 5
+ *
+ * Licensed under GPL v3
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @link          http://www.assomem.org Association Member Management Project
+ * @package       amm
+ * @subpackage    amm.app.controller
+ * @license       GPL v3 (http://www.gnu.org/licenses/gpl.html)
+ */
+
+/**
+ * Handles information for setup procedure
+ *
+ * @package       amm
+ * @subpackage    amm.app.controller
+ */
+class SetupController extends AppController {
+/**
+ * Name of the controller for PHP4.
+ *
+ * @var string
+ * @access public
+ */
+	var $name = 'Setup';
+
+/**
+ * Helpers declared for the views.
+ *
+ * @var array
+ * @access public
+ */
+	var $helpers = array('Js');
+
+/**
+ * Displays a welcome page for the installation.
+ *
+ */
+	function index() {
+		if(file_exists(MODELS.'install_db.sql')) {
+			$this->redirect(array('action' => 'installed'));
+		}
+	}
+
+/**
+ * Displays a formular for the database connection
+ *
+ */
+	function second_step() {
+		if (!empty($this->data)) {
+			$this->Setup->create($this->data);
+			if(!$this->Setup->validates()) {
+				$this->Session->setFlash(__("The data you gave in isn't valid.", true));
+				$this->validateErrors($this->Setup);
+			} else {
+				if($this->Setup->dbConnectionVerification()) {
+					$this->Setup->createDbConfigFile();
+					$this->Setup->installDb();
+					$this->redirect(array('action' => 'finish'));
+				} else {
+					$this->Session->setFlash(__("The data you gave in, doesn't permit to connect succesfully the database.", true));
+				}
+			}
+		}
+	}
+
+/**
+ * Displays the final installation page
+ *
+ */
+	function finish() {
+		if(!unlink(MODELS.'install_db.sql')) {
+			$this->Session->setFlash(
+				__("The file ", true) . MODELS.'install_db.sql' . __(" could not be deleted!<br />
+					Delete it before using the application.<br />
+					It avoids to have unexpected reinstallation.", true)
+				);
+		}
+	}
+
+/**
+ * The application is already installed
+ *
+ */
+	function installed() {
+
+	}
+}
+
+?>

=== added file 'app/models/install_db.sql'
--- app/models/install_db.sql	1970-01-01 00:00:00 +0000
+++ app/models/install_db.sql	2011-07-17 19:12:32 +0000
@@ -0,0 +1,122 @@
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+
+DROP TABLE IF EXISTS `authorizations`;
+CREATE TABLE IF NOT EXISTS `authorizations` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `name` text NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `authorizations_members`;
+CREATE TABLE IF NOT EXISTS `authorizations_members` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `authorization_id` int(10) unsigned NOT NULL,
+  `member_id` int(10) unsigned NOT NULL,
+  PRIMARY KEY (`id`),
+  KEY `fk_authorization` (`authorization_id`),
+  KEY `fk_member` (`member_id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `events`;
+CREATE TABLE IF NOT EXISTS `events` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(150) NOT NULL,
+  `date_begin` datetime NOT NULL,
+  `date_end` datetime DEFAULT NULL,
+  `fullday` tinyint(1) DEFAULT '0',
+  `notes` text NOT NULL,
+  `fees` decimal(10,2) unsigned DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `events_people`;
+CREATE TABLE IF NOT EXISTS `events_people` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `event_id` int(11) unsigned NOT NULL,
+  `person_id` int(11) unsigned NOT NULL,
+  `fees_payed` tinyint(4) NOT NULL DEFAULT '1',
+  `notes` text,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `formulas`;
+CREATE TABLE IF NOT EXISTS `formulas` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(45) DEFAULT NULL,
+  `prices` decimal(10,0) DEFAULT NULL,
+  `notes` text NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `members`;
+CREATE TABLE IF NOT EXISTS `members` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `person_id` int(11) unsigned NOT NULL,
+  `guardian1_id` int(11) unsigned DEFAULT NULL,
+  `guardian2_id` int(11) unsigned DEFAULT NULL,
+  `emergency1_id` int(11) unsigned DEFAULT NULL,
+  `emergency2_id` int(11) unsigned DEFAULT NULL,
+  `formula_id` int(11) unsigned NOT NULL,
+  `membership_date` date DEFAULT NULL,
+  `notes` text,
+  `medical_certificat` varchar(100) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `people`;
+CREATE TABLE IF NOT EXISTS `people` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `firstname` varchar(100) NOT NULL,
+  `lastname` varchar(100) NOT NULL,
+  `surname` varchar(100) DEFAULT NULL,
+  `name` varchar(255) NOT NULL,
+  `birthday` date DEFAULT NULL,
+  `address` varchar(100) DEFAULT NULL,
+  `addr_comp` varchar(100) DEFAULT NULL,
+  `postal_code` int(11) DEFAULT NULL,
+  `town` varchar(45) DEFAULT NULL,
+  `phone` varchar(21) DEFAULT NULL,
+  `email` varchar(100) DEFAULT NULL,
+  `job` varchar(45) DEFAULT NULL,
+  `photo` varchar(100) DEFAULT NULL,
+  `notes` text,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `uk_name` (`name`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `people_places`;
+CREATE TABLE IF NOT EXISTS `people_places` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `person_id` int(10) unsigned NOT NULL,
+  `place_id` int(10) unsigned NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `person_infos`;
+CREATE TABLE IF NOT EXISTS `person_infos` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `person_id` int(10) unsigned NOT NULL,
+  `rank_id` int(10) unsigned DEFAULT NULL,
+  `notes` text,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `places`;
+CREATE TABLE IF NOT EXISTS `places` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(45) DEFAULT NULL,
+  `address` varchar(100) DEFAULT NULL,
+  `address_complementary` varchar(100) DEFAULT NULL,
+  `postal_code` varchar(10) DEFAULT NULL,
+  `town` varchar(45) DEFAULT NULL,
+  `description` text,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `ranks`;
+CREATE TABLE IF NOT EXISTS `ranks` (
+  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+  `order` smallint(5) unsigned DEFAULT NULL,
+  `name` varchar(45) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

=== added file 'app/models/setup.php'
--- app/models/setup.php	1970-01-01 00:00:00 +0000
+++ app/models/setup.php	2011-07-17 19:12:32 +0000
@@ -0,0 +1,188 @@
+<?php
+/**
+ *
+ * PHP versions 4 and 5
+ *
+ * Licensed under GPL v3
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @link          http://www.assomem.org Association Member Management Project
+ * @package       amm
+ * @subpackage    amm.app.controller
+ * @license       GPL v3 (http://www.gnu.org/licenses/gpl.html)
+ */
+
+/**
+ * Setup model manages the setup procedure
+ *
+ * @package       amm
+ * @subpackage    amm.app.model
+ */
+class Setup extends AppModel {
+/**
+ * Name of the model.
+ *
+ * @var string
+ * @access public
+ */
+	var $name = 'Setup';
+/**
+ * No database table is used for this controller
+ *
+ * @var string
+ * @access public
+ */
+	var $useTable = false;
+/**
+ * List of validation rules. Append entries for validation as ('field_name' => '/^perl_compat_regexp$/')
+ * that have to match with preg_match(). Use these rules with Model::validate()
+ *
+ * @var array
+ * @access public
+ */
+	var $validate = array(
+		'host' => array(
+			'alphaNumeric' => array(
+				'rule' => array('alphaNumeric'),
+				'message' => 'A hostname is required. If the database and the application are on the same server, enter "localhost"',
+				//'allowEmpty' => false,
+				'required' => true,
+				//'last' => false, // Stop validation after this rule
+				//'on' => 'create', // Limit validation to 'create' or 'update' operations
+			),
+		),
+		'login' => array(
+			'notEmpty' => array(
+				'rule' => array('notEmpty'),
+				'message' => 'A login is needed to access the database.',
+				//'allowEmpty' => true,
+				'required' => true,
+				//'last' => false, // Stop validation after this rule
+				//'on' => 'create', // Limit validation to 'create' or 'update' operations
+			),
+		),
+		'password' => array(
+			'notEmpty' => array(
+				'rule' => array('notEmpty'),
+				'message' => 'A password is required to connect succesfully the database.',
+				//'allowEmpty' => true,
+				'required' => true,
+				//'last' => false, // Stop validation after this rule
+				//'on' => 'create', // Limit validation to 'create' or 'update' operations
+			),
+		),
+		'database' => array(
+			'notEmpty' => array(
+				'rule' => array('notEmpty'),
+				'message' => 'The name of the database is required to store the data.',
+				//'allowEmpty' => false,
+				'required' => true,
+				//'last' => false, // Stop validation after this rule
+				//'on' => 'create', // Limit validation to 'create' or 'update' operations
+			),
+		),
+		'prefix' => array(
+			'alphaNumeric' => array(
+				'rule' => array('alphaNumeric'),
+				//'message' => 'Your custom message here',
+				'allowEmpty' => true,
+				'required' => false,
+				//'last' => false, // Stop validation after this rule
+				//'on' => 'create', // Limit validation to 'create' or 'update' operations
+			),
+		)
+	);
+/**
+ * Field-by-field table metadata for inputs
+ *
+ * @var array
+ * @access protected
+ */
+	var $_schema = array(
+		'host' => array(
+			'type' => 'string',
+			'length' => 70
+		),
+		'login' => array(
+			'type' => 'string',
+			'length' => 70
+		),
+		'password' => array(
+			'type' => 'string',
+			'length' => 255
+		),
+		'database' => array(
+			'type' => 'string',
+			'length' => 125
+		),
+		'prefix' => array(
+			'type' => 'string',
+			'length' => 10
+		)
+	);
+
+/**
+ * Creates a configuration file for the database
+ *
+ * 
+ *
+ */
+	function createDbConfigFile() {
+		$file = fopen(CONFIGS.'database.php', 'wt');
+		if($file != null) {
+			fwrite($file, "<?php\n");
+			fwrite($file, "/**\n");
+			fwrite($file, " *\n");
+			fwrite($file, " * CONFIGURATION FILE CREATED DURING THE INSTALLATION PROCEDURE\n");
+			fwrite($file, " *\n");
+			fwrite($file, " */\n");
+			fwrite($file, "class DATABASE_CONFIG {\n");
+			fwrite($file, "\n");
+			fwrite($file, '	var $default = array('."\n");
+			fwrite($file, "		'driver' => 'mysql',\n");
+			fwrite($file, "		'persistent' => false,\n");
+			fwrite($file, "		'host' => '" . $this->data['Setup']['host'] . "',\n");
+			fwrite($file, "		'login' => '" . $this->data['Setup']['login'] . "',\n");
+			fwrite($file, "		'password' => '" . $this->data['Setup']['password'] . "',\n");
+			fwrite($file, "		'database' => '" . $this->data['Setup']['database'] . "',\n");
+			fwrite($file, "		'prefix' => '" . $this->data['Setup']['prefix'] . "',\n");
+			fwrite($file, '	);' . "\n");
+			fwrite($file, "}\n");
+			fwrite($file, "\n");
+		}
+	}
+
+	function dbConnectionVerification() {
+		$db = new ConnectionManager();
+		$db->create('default', array(
+		'driver' => 'mysql',
+		'persistent' => false,
+		'host' => $this->data['Setup']['host'],
+		'login' => $this->data['Setup']['login'],
+		'password' => $this->data['Setup']['password'],
+		'database' => $this->data['Setup']['database'],
+		'prefix' => $this->data['Setup']['prefix'],
+		));
+		$db = ConnectionManager::getDataSource('default');
+		if(!$db->isConnected()) {
+			return false;
+		} else {
+			return true;
+		}
+	}
+
+	function installDb() {
+		$db = ConnectionManager::getDataSource('default');
+		$scriptDb = file_get_contents(MODELS.'install_db.sql');
+		$scriptDb = explode(';', $scriptDb);
+
+		foreach ($scriptDb as $script) {
+			if (trim($script) != '') {
+				$db->query($script);
+			}
+		}
+	}
+
+}
+
+?>

=== removed directory 'app/tmp/cache/models'
=== added directory 'app/tmp/cache/models'
=== added directory 'app/views/setup'
=== added file 'app/views/setup/finish.ctp'
--- app/views/setup/finish.ctp	1970-01-01 00:00:00 +0000
+++ app/views/setup/finish.ctp	2011-07-17 19:12:32 +0000
@@ -0,0 +1,12 @@
+<div class="setups index">
+	<h2><?php __('Installation: finished');?></h2>
+	<p>
+		The installation is finished!<br />
+		You can immediatly use the application for your organization. You will find documentation on the application on our website
+		<a href="http://www.assomem.org";>http://www.assomem.org</a>.
+	</p>
+	<div class="actions">
+		<?php echo $this->Html->link(__('Go on AMM website', true), "http://www.assomem.org";); ?>
+		<?php echo $this->Html->link(__('Use the application', true), array('controller' => 'members', 'action' => 'index')); ?>
+	</div>
+</div>
\ No newline at end of file

=== added file 'app/views/setup/index.ctp'
--- app/views/setup/index.ctp	1970-01-01 00:00:00 +0000
+++ app/views/setup/index.ctp	2011-07-17 19:12:32 +0000
@@ -0,0 +1,17 @@
+<div class="setups index">
+	<h2><?php __('Installation: first step');?></h2>
+	<p>
+		Welcome on "Association Member Management" installation procedure.<br />
+		<br />
+		We are pleased that you have choosen this application for managing your organization.<br />
+		<br />
+		Before proceding the installation, please make sure that you have downloaded the application on
+		<a href="http://www.assomem.org"; title="AMM website">http://www.assomem.org</a>.<br />
+		If it isn't so, please download our latest release. You make sure to have the latest stable version of the application
+		and to have an application without spywares.
+	</p>
+	<div class="actions">
+		<?php echo $this->Html->link(__('Go on AMM website', true), "http://www.assomem.org";); ?>
+		<?php echo $this->Html->link(__('Step 2 >', true), array('action' => 'second_step')); ?>
+	</div>
+</div>
\ No newline at end of file

=== added file 'app/views/setup/installed.ctp'
--- app/views/setup/installed.ctp	1970-01-01 00:00:00 +0000
+++ app/views/setup/installed.ctp	2011-07-17 19:12:32 +0000
@@ -0,0 +1,11 @@
+<div class="setups index">
+	<h2><?php __('The application is installed!');?></h2>
+	<p>
+		The application has been already installed<br />
+		To reinstall the application, download the latest installation archive on our website and follow the procedure.
+	</p>
+	<div class="actions">
+		<?php echo $this->Html->link(__('Go on AMM website', true), "http://www.assomem.org";); ?>
+		<?php echo $this->Html->link(__('Use the application', true), array('controller' => 'members', 'action' => 'index')); ?>
+	</div>
+</div>
\ No newline at end of file

=== added file 'app/views/setup/second_step.ctp'
--- app/views/setup/second_step.ctp	1970-01-01 00:00:00 +0000
+++ app/views/setup/second_step.ctp	2011-07-17 19:12:32 +0000
@@ -0,0 +1,22 @@
+<div class="setups second_step">
+	<h2><?php __('Installation: second step');?></h2>
+	<p>
+		For the application to run properly, it needs a database. Please fill-in the form.<br />
+		If you are not aware of this information, contact your server's administrator.
+	</p>
+	<?php echo $this->Form->create('Setup', array('url' => 'second_step'));?>
+	<?php
+		echo $this->Form->input('host', array('label' => __('Hostname', true)));
+		echo $this->Form->input('login', array('label' => __('Login', true)));
+		echo $this->Form->input('password', array('label' => __('Password', true)));
+		echo $this->Form->input('database', array('label' => __('Database', true)));
+		echo $this->Form->input('prefix', array(
+			'label' => array(
+				"text" => __('Prefix', true),
+				"title" => "If you use the database for other application aswell, you should give a prefix for the tables"
+				)
+			)
+		);
+	?>
+	<?php echo $this->Form->end(__('Submit', true));?>
+</div>
\ No newline at end of file