diff options
author | 2009-06-18 18:34:16 -0400 | |
---|---|---|
committer | 2009-06-18 18:34:16 -0400 | |
commit | 7cc564052c31f96897a2087e890372d425cc7670 (patch) | |
tree | 6b6aa7b76f157d9ccf5f4a8c74e92d35403bb600 /setup.php | |
parent | Plugged in sql_build to backend and frontend log viewer (diff) | |
download | ingenue-7cc564052c31f96897a2087e890372d425cc7670.tar.gz ingenue-7cc564052c31f96897a2087e890372d425cc7670.tar.bz2 ingenue-7cc564052c31f96897a2087e890372d425cc7670.zip |
Moved newclass utility into a cli script, created first-time setup script replacing the reset function from the frontend
Diffstat (limited to 'setup.php')
-rwxr-xr-x | setup.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/setup.php b/setup.php new file mode 100755 index 0000000..e65cc91 --- /dev/null +++ b/setup.php @@ -0,0 +1,69 @@ +#!/usr/bin/php +<?php +require_once(dirname(__FILE__).'/shared/include/includes.php'); // USE __DIR__ in 5.3.0 +require_once(SHARED.'/config.php'); +function echo_and_query($q) { + global $pdo; + echo $q."\n"; + return $pdo->query($q); +} +$interactive=posix_isatty(STDIN); +$opts=getopt('R'); +$pdo=new PDO('mysql:host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']); +if (isset($opts['R'])) { + echo_and_query('DROP DATABASE IF EXISTS `'.$conf['sqldb'].'`'); +} +echo_and_query('CREATE DATABASE IF NOT EXISTS `'.$conf['sqldb'].'`'); // We can add charset and collate here if we want +echo_and_query('USE `'.$conf['sqldb'].'`'); +sql_row_obj::set_pdo_obj($pdo); +foreach (get_declared_classes() as $class) { + if (!is_subclass_of($class, 'sql_row_obj')) { + continue; + } + $o=new $class(); // TODO this will be static once 5.3.0 is out + if (isset($opts['R'])) { + echo_and_query($o->drop_table()); + } + echo_and_query($o->create_table()); +} +do { + if ($user->email) { + echo 'Invalid entry: '.$user->email."\n"; + } + echo 'Admin email address: '; + $user=new sql_user(); + $user->email=trim(fgets(STDIN)); + if (!$interactive) { + echo "\n"; + } +} while (!Validate::email($user->email)); +do { + if ($user->name) { + echo 'Invalid entry: '.$user->name."\n"; + } + echo 'Admin display name: '; + $user->name=trim(fgets(STDIN)); + if (!$interactive) { + echo "\n"; + } +} while (!Validate::username($user->name)); +if ($interactive) { + system('stty -echo'); +} +do { + if ($pass && $passconfirm) { + echo "Entered passwords did not match. Try again.\n"; + } + echo 'Admin password: '; + $pass=trim(fgets(STDIN)); + echo "\nRepeat password: "; + $passconfirm=trim(fgets(STDIN)); + echo "\n"; +} while (!$pass || $pass != $passconfirm); +if ($interactive) { + system('stty echo'); +} +$user->passhash=sha1($pass); +$user->flags='a'; +$user->write(); +?> |