-CC-1736: install/airtime-user.php script needs to be updated for the new Zend Framework

This commit is contained in:
martin 2011-02-22 19:01:33 -05:00
parent a20e279840
commit 23e533aa67
2 changed files with 71 additions and 49 deletions

View file

@ -172,4 +172,13 @@ class User {
return $CC_DBC->GetRow($sql); return $CC_DBC->GetRow($sql);
} }
public static function GetUserID($login){
$user = CcSubjsQuery::create()->findOneByDbLogin($login);
if (is_null($user)){
return -1;
} else {
return $user->getDbId();
}
}
} }

View file

@ -1,7 +1,12 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
require_once(dirname(__FILE__).'/../conf.php');
require_once(dirname(__FILE__).'/../Subjects.php'); set_include_path('../application/models' . PATH_SEPARATOR . get_include_path());
require_once(__DIR__.'/../library/propel/runtime/lib/Propel.php');
Propel::init(__DIR__.'/../application/configs/airtime-conf.php');
require_once(dirname(__FILE__).'/../application/configs/conf.php');
require_once(dirname(__FILE__).'/../application/models/Users.php');
require_once('DB.php'); require_once('DB.php');
require_once('Console/Getopt.php'); require_once('Console/Getopt.php');
@ -22,52 +27,37 @@ function printUsage()
echo " This program allows you to manage Airtime users.\n"; echo " This program allows you to manage Airtime users.\n";
echo "\n"; echo "\n";
echo "OPTIONS:\n"; echo "OPTIONS:\n";
echo " --addupdate <username> <password>\n"; echo " --addupdate <username>\n";
echo " Add the user or update the password for the user.\n"; echo " Add the user or update user information.\n";
echo " --delete <username>\n"; echo " --delete <username>\n";
echo " Remove the user.\n"; echo " Remove the user.\n";
echo "\n"; echo "\n";
} }
$parsedCommandLine = Console_Getopt::getopt($argv, null, array("addupdate", "delete"));
if (PEAR::isError($parsedCommandLine)) { if (count($argv) != 3) {
printUsage();
exit(1);
}
$cmdLineOptions = $parsedCommandLine[0];
if (count($parsedCommandLine[1]) == 0) {
printUsage(); printUsage();
exit; exit;
} }
$action = null; $action = null;
foreach ($cmdLineOptions as $tmpValue) { switch ($argv[1]) {
$optionName = $tmpValue[0]; case '--addupdate':
$optionValue = $tmpValue[1]; $action = "addupdate";
switch ($optionName) { break;
case '--addupdate': case '--delete':
$action = "addupdate"; $action = "delete";
break 2; break;
case "--delete":
$action = "delete";
break 2;
}
} }
$username = $argv[2];
if (is_null($action)) { if (is_null($action)) {
printUsage(); printUsage();
exit; exit;
} }
if (count($parsedCommandLine) < 1) {
printUsage();
exit;
}
$username = $parsedCommandLine[1][0];
$password = $parsedCommandLine[1][1];
PEAR::setErrorHandling(PEAR_ERROR_RETURN); PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
if (PEAR::isError($CC_DBC)) { if (PEAR::isError($CC_DBC)) {
@ -75,28 +65,51 @@ if (PEAR::isError($CC_DBC)) {
} }
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
// Check if the user exists // Check if the user exists
$user = Subjects::GetSubject($username); $id = User::GetUserID($username);
if ($action == "addupdate") { if ($action == "addupdate") {
if (empty($password)) {
printUsage(); if ($id < 0) {
exit; echo "Creating user\n";
} $user = new User("");
if (empty($user)) { $user->setLogin($username);
// Add the user.
$r = Subjects::AddSubj($username, $password);
} else { } else {
// Update the password echo "Updating user\n";
$r = Subjects::Passwd($username, NULL, $password); $user = new User($id);
} }
} elseif (($action == "delete") && (is_array($user))) {
// Delete the user
$r = Subjects::RemoveSubj($username);
}
if (PEAR::isError($r)) { echo "Enter password: ";
die($r->getMessage()); $line = trim(fgets(fopen("php://stdin","r")));
} $user->setPassword($line);
exit(0);
do{
echo "Enter first name: ";
$line = trim(fgets(fopen("php://stdin","r")));
}while(strlen($line) < 1);
$user->setFirstName($line);
do{
echo "Enter last name: ";
$line = trim(fgets(fopen("php://stdin","r")));
}while(strlen($line) < 1);
$user->setLastName($line);
do{
echo "Enter user type [(A)dmin|(H)ost|(G)uest]: ";
$line = trim(fgets(fopen("php://stdin","r")));
} while($line != "A" && $line != "H" && $line != "G");
$user->setType($line);
$user->save();
} elseif ($action == "delete") {
if ($id < 0){
echo "Username not found!\n";
exit;
} else {
echo "Deleting user\n";
$user = new User($id);
$user->delete();
}
}