Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
RInstaller Class Reference

Public Member Functions

 init ()
 run ()
 getInstalled ()

Public Attributes

const ERROR_NONE = 0
const ERROR_QUERY_FAILED = 1
 $defaultRoles
 $superuserName
 $authenticatedName
 $guestName
 $db

Detailed Description

Rights installer component class file.

Author
Christoffer Niska cnisk.nosp@m.a@li.nosp@m.ve.co.nosp@m.m
Since
0.9.3

Definition at line 9 of file RInstaller.php.

Member Function Documentation

RInstaller::getInstalled ( )
Returns
boolean whether Rights is installed.

Definition at line 160 of file RInstaller.php.

{
if( $this->_installed!==null )
{
return $this->_installed;
}
else
{
$schema = array(
"SELECT COUNT(*) FROM {$this->_authManager->itemTable}",
"SELECT COUNT(*) FROM {$this->_authManager->itemChildTable}",
"SELECT COUNT(*) FROM {$this->_authManager->assignmentTable}",
"SELECT COUNT(*) FROM {$this->_authManager->rightsTable}",
);
try
{
foreach( $schema as $sql )
{
$command = $this->db->createCommand($sql);
$command->queryScalar();
}
$installed = true;
}
catch( CDbException $e )
{
$installed = false;
}
return $this->_installed = $installed;
}
}
RInstaller::init ( )

Initializes the installer.

Exceptions
CExceptionif the authorization manager or the web user is not configured to use the correct class.

Definition at line 49 of file RInstaller.php.

References Rights\t().

{
// Make sure the application is configured
// to use a valid authorization manager.
$authManager = Yii::app()->getAuthManager();
if( ($authManager instanceof RDbAuthManager)===false )
throw new CException(Rights::t('install', 'Application authorization manager must extend the RDbAuthManager class.'));
// Make sure the application is configured
// to use a valid web user.
$user = Yii::app()->getUser();
if( ($user instanceof RWebUser)===false )
throw new CException(Rights::t('install', 'Application web user must extend the RWebUser class.'));
$this->_authManager = $authManager;
$this->db = $this->_authManager->db;
}
RInstaller::run ( )

Runs the installer.

Parameters
booleanwhether to drop tables if they exists.
Returns
boolean whether the installer ran successfully.

Definition at line 74 of file RInstaller.php.

{
// Get the table names.
$itemTable = $this->_authManager->itemTable;
$itemChildTable = $this->_authManager->itemChildTable;
$assignmentTable = $this->_authManager->assignmentTable;
$rightsTable = $this->_authManager->rightsTable;
// Fetch the schema.
$schema = file_get_contents(dirname(__FILE__).'/../data/schema.sql');
// Correct the table names.
$schema = strtr($schema, array(
'AuthItem'=>$itemTable,
'AuthItemChild'=>$itemChildTable,
'AuthAssignment'=>$assignmentTable,
'Rights'=>$rightsTable,
));
// Convert the schema into an array of sql queries.
$schema = preg_split("/;\s*/", trim($schema, ';'));
// Start transaction
$txn = $this->db->beginTransaction();
try
{
// Execute each query in the schema.
foreach( $schema as $sql )
{
$command = $this->db->createCommand($sql);
$command->execute();
}
// Insert the necessary roles.
$roles = $this->getUniqueRoles();
foreach( $roles as $roleName )
{
$sql = "INSERT INTO {$itemTable} (name, type, data)
VALUES (:name, :type, :data)";
$command = $this->db->createCommand($sql);
$command->bindValue(':name', $roleName);
$command->bindValue(':type', CAuthItem::TYPE_ROLE);
$command->bindValue(':data', 'N;');
$command->execute();
}
// Assign the logged in user the superusers role.
$sql = "INSERT INTO {$assignmentTable} (itemname, userid, data)
VALUES (:itemname, :userid, :data)";
$command = $this->db->createCommand($sql);
$command->bindValue(':itemname', $this->superuserName);
$command->bindValue(':userid', Yii::app()->getUser()->id);
$command->bindValue(':data', 'N;');
$command->execute();
// All commands executed successfully, commit.
$txn->commit();
return self::ERROR_NONE;
}
catch( CDbException $e )
{
// Something went wrong, rollback.
$txn->rollback();
return self::ERROR_QUERY_FAILED;
}
}

The documentation for this class was generated from the following file: