예제 #1
0
 /**
  * Once the database information has been posted successfully,
  * testDB determines if the database connection can be made and,
  * if so, if there a database to which to connect. If not, then
  * it creates the database (if specified)
  */
 public function testDB($force_on_populated = false)
 {
     $connection = $this->checkConnection();
     Branch::loadHubDB();
     switch ($connection) {
         case BRANCH_CONNECT_NO_DB:
             // connection made, but database does not exist
             if (isset($_POST['createdb'])) {
                 $result = $this->createDB();
                 if (PHPWS_Error::isError($result)) {
                     $this->message[] = dgettext('branch', 'An error occurred when trying to connect to the database.');
                     $this->edit_db();
                 } elseif ($result) {
                     $this->message[] = dgettext('branch', 'Database created successfully.');
                     $this->setCreateStep(2);
                     $this->saveDSN();
                     $this->edit_basic();
                 } else {
                     $this->message[] = dgettext('branch', 'Unable to create the database. You will need to create it manually.');
                     $this->edit_db();
                 }
             } else {
                 $this->message[] = dgettext('branch', 'Connected successfully, but the database does not exist.');
                 $this->edit_db();
             }
             break;
         case BRANCH_NO_CONNECTION:
         case BRANCH_CONNECT_BAD_DB:
             // Failed connection
             $this->message[] = dgettext('branch', 'Could not connect to the database.');
             $this->edit_db();
             break;
         case BRANCH_CONNECT_SUCCESS:
             // connection successful
             $this->setCreateStep(2);
             $this->saveDSN();
             $this->message[] = dgettext('branch', 'Connection successful. Database available.');
             $this->edit_basic();
             break;
         case BRANCH_CONNECT_WITH_TABLES:
             if ($force_on_populated && !empty($this->dbprefix)) {
                 $this->setCreateStep(2);
                 $this->saveDSN();
                 $this->message[] = dgettext('branch', 'Connection successful. Database available.');
                 $this->edit_basic();
             } else {
                 $this->message[] = dgettext('branch', 'Connected successfully, but this database already contains tables.');
                 if (!empty($this->dbprefix)) {
                     $this->message[] = dgettext('branch', 'Though not recommended, you can force installation by clicking Continue below.');
                     $force = true;
                 } else {
                     $this->message[] = dgettext('branch', 'Though not recommended, prefixing will allow you to install to this database.');
                     $force = false;
                 }
                 $this->edit_db($force);
             }
             break;
     }
 }
예제 #2
0
/**
 * boost install file for users
 *
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function users_install(&$content)
{
    PHPWS_Core::initModClass('users', 'Users.php');
    PHPWS_Core::initModClass('users', 'Action.php');
    PHPWS_Core::configRequireOnce('users', 'config.php');
    if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'branch') {
        $db = new PHPWS_DB();
        PHPWS_Settings::clear();
        if (!createLocalAuthScript()) {
            $content[] = 'Could not create authorization script.';
            return false;
        }
        Branch::loadHubDB();
        $db = new PHPWS_DB('mod_settings');
        $db->addWhere('module', 'users');
        $db->addWhere('setting_name', 'site_contact');
        $db->addColumn('small_char');
        $site_contact = $db->select('one');
        $db = new PHPWS_DB('users');
        $sql = 'select a.password, b.* from user_authorization as a, users as b where b.deity = 1 and a.username = b.username';
        $deities = $db->getAll($sql);
        if (PHPWS_Error::isError($deities)) {
            PHPWS_Error::log($deities);
            $content[] = dgettext('users', 'Could not access hub database.');
            Branch::restoreBranchDB();
            return FALSE;
        } elseif (empty($deities)) {
            $content[] = dgettext('users', 'Could not find any hub deities.');
            Branch::restoreBranchDB();
            return FALSE;
        } else {
            Branch::restoreBranchDB();
            PHPWS_Settings::set('users', 'site_contact', $site_contact);
            PHPWS_Settings::save('users');
            $auth_db = new PHPWS_DB('user_authorization');
            $user_db = new PHPWS_DB('users');
            $group_db = new PHPWS_DB('users_groups');
            foreach ($deities as $deity) {
                $auth_db->addValue('username', $deity['username']);
                $auth_db->addValue('password', $deity['password']);
                $result = $auth_db->insert();
                if (PHPWS_Error::isError($result)) {
                    PHPWS_Error::log($result);
                    $content[] = dgettext('users', 'Unable to copy deity login to branch.');
                    continue;
                }
                unset($deity['password']);
                $user_db->addValue($deity);
                $result = $user_db->insert();
                if (PHPWS_Error::isError($result)) {
                    PHPWS_Error::log($result);
                    $content[] = dgettext('users', 'Unable to copy deity users to branch.');
                    Branch::loadBranchDB();
                    return FALSE;
                }
                $group_db->addValue('active', 1);
                $group_db->addValue('name', $deity['username']);
                $group_db->addValue('user_id', $result);
                if (PHPWS_Error::logIfError($group_db->insert())) {
                    $content[] = dgettext('users', 'Unable to copy deity user group to branch.');
                    Branch::loadBranchDB();
                    return FALSE;
                }
                $group_db->reset();
                $auth_db->reset();
                $user_db->reset();
            }
            $content[] = dgettext('users', 'Deity users copied to branch.');
        }
        return TRUE;
    }
    if (!createLocalAuthScript()) {
        $content[] = 'Could not create local authorization script.';
        return false;
    }
    $authorize_id = PHPWS_Settings::get('users', 'local_script');
    $user = new PHPWS_User();
    $content[] = '<hr />';
    return TRUE;
}
예제 #3
0
 public function updateBranches(&$content)
 {
     if (!PHPWS_Core::moduleExists('branch')) {
         return true;
     }
     PHPWS_Core::initModClass('branch', 'Branch_Admin.php');
     $branches = Branch_Admin::getBranches(true);
     if (empty($branches)) {
         return true;
     }
     $keys = array_keys($this->status);
     foreach ($branches as $branch) {
         $GLOBALS['Boost_In_Branch'] = $branch;
         // used as the "local" directory in updateFiles
         $GLOBALS['boost_branch_dir'] = $branch->directory;
         if (PHPWS_Error::isError($branch->loadBranchDB())) {
             $content[] = dgettext('boost', 'Problem connecting to the branch. May be too many connections.');
             continue;
         }
         // create a new boost based on the branch database
         $branch_boost = new PHPWS_Boost();
         $branch_boost->loadModules($keys, false);
         $content[] = '<hr />';
         $content[] = sprintf(dgettext('boost', 'Updating branch %s'), $branch->branch_name);
         $result = $branch_boost->update($content);
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
             $content[] = dgettext('boost', 'Unable to update branch.');
         }
     }
     Branch::loadHubDB();
     $GLOBALS['Boost_In_Branch'] = false;
 }