Ejemplo n.º 1
0
function createSystem()
{
    global $settings;
    global $_testInstall_Ok;
    try {
        /*
         * The settings system is used to create a lot of output,
         * we swallow it all
         */
        ob_start();
        /*
         * Get the schema version and other constants
         */
        require_once "lib/Bootstrap.php";
        $bootstrap = new Bootstrap();
        /*
         * Now create the database
         */
        $dbsettings = $_SESSION['spotsettings']['db'];
        $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
        $dbCon->connect($dbsettings['host'], $dbsettings['user'], $dbsettings['pass'], $dbsettings['dbname']);
        $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
        $daoFactory->setConnection($dbCon);
        /*
         * The database must exist before we can get the Service_Settings_Base instance
         */
        $dbStruct = SpotStruct_abs::factory($dbsettings['engine'], $daoFactory->getConnection());
        $dbStruct->updateSchema();
        $spotSettings = $bootstrap->getSettings($daoFactory, false);
        $svcUpgradeBase = new Services_Upgrade_Base($daoFactory, $spotSettings, $dbsettings['engine']);
        /*
         * Create all the different settings (only the default) ones
         */
        $svcUpgradeBase->settings();
        /*
         * Create the users
         */
        $svcUpgradeBase->users();
        /*
         * print all the output as HTML comment for debugging
         */
        $dbCreateOutput = ob_get_contents();
        ob_end_clean();
        /*
         * Now it is time to do something with
         * the information the user has given to us
         */
        /*
         * Update the NNTP settings in the databas
         */
        $spotSettings->set('nntp_nzb', $_SESSION['spotsettings']['nntp']['nzb']);
        $spotSettings->set('nntp_hdr', $_SESSION['spotsettings']['nntp']['hdr']);
        $spotSettings->set('nntp_post', $_SESSION['spotsettings']['nntp']['post']);
        /*
         * Create the given user
         */
        $svcUserRecord = new Services_User_Record($daoFactory, $spotSettings);
        $spotUser = $_SESSION['spotsettings']['adminuser'];
        /*
         * and actually add the user
         */
        $spotUser['userid'] = $svcUserRecord->createUserRecord($spotUser)->getData('userid');
        /*
         * When the new user was created a random password was assigned, 
         * so now have to set the supplied password
         */
        $svcUserRecord->setUserPassword($spotUser);
        # Change the administrators' account password to that of this created user
        $adminUser = $svcUserRecord->getUser(SPOTWEB_ADMIN_USERID);
        $adminUser['newpassword1'] = $spotUser['newpassword1'];
        $svcUserRecord->setUserPassword($adminUser);
        # update the settings with our system type and our admin id
        $spotSettings->set('custom_admin_userid', $spotUser['userid']);
        $spotSettings->set('systemtype', $spotUser['systemtype']);
        # Set the system type
        $svcUpgradeBase->resetSystemType($spotUser['systemtype']);
        /* 
         * Create the necessary database connection information
         */
        $dbConnectionString = '';
        switch ($_SESSION['spotsettings']['db']['engine']) {
            case 'pdo_mysql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_mysql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # mysql
            # mysql
            case 'pdo_pgsql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_pgsql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # pdo_pgsql
        }
        # switch
        # Try to create the dbsettings.inc.php file for the user
        @file_put_contents("dbsettings.inc.php", "<?php" . PHP_EOL . $dbConnectionString);
        $createdDbSettings = file_exists("dbsettings.inc.php");
        showTemplate("step-final.inc.php", array('createdDbSettings' => $createdDbSettings, 'dbCreateOutput' => $dbCreateOutput, 'dbConnectionString' => $dbConnectionString));
    } catch (Exception $x) {
        showTemplate("fatalerror.inc.php", array('x' => $x));
    }
    # exception
}
Ejemplo n.º 2
0
 /**
  * Returns the DAO factory used by all of
  * Spotweb
  *
  * @throws DatabaseConnectionException
  * @return Dao_Base_Factory
  */
 public function getDaoFactory()
 {
     SpotTiming::start(__CLASS__ . '::' . __FUNCTION__);
     @(include "dbsettings.inc.php");
     if (empty($dbsettings)) {
         throw new DatabaseConnectionException("No database settings have been entered, please use the 'install.php' wizard to install and configure Spotweb." . PHP_EOL . "If you are upgrading from an earlier version of Spotweb, please consult https://github.com/spotweb/spotweb/wiki/Frequently-asked-questions/ first");
     }
     # if
     /*
      * Store the DB settings so we can retrieve them later, if so desired,
      * we do overwrite the password to make sure it doesn't show up in a
      * stacktrace.
      */
     $this->_dbSettings = $dbsettings;
     $this->_dbSettings['pass'] = '******';
     $this->_dbSettings['user'] = '******';
     $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
     $dbCon->connect($dbsettings['host'], $dbsettings['user'], $dbsettings['pass'], $dbsettings['dbname']);
     $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
     $daoFactory->setConnection($dbCon);
     SpotTiming::stop(__CLASS__ . '::' . __FUNCTION__);
     return $daoFactory;
 }
Ejemplo n.º 3
0
 /**
  * Returns an list of spots with the mastercollection id inserted into the
  * collectionInfo variable of the actual spot record. It will create the
  * master collection record if necessary
  *
  * @param array $spotList
  * @param bool $isRecursive
  * @return array
  */
 public function getCollectionIdList(array $spotList, $isRecursive = false)
 {
     $toFetch = array();
     if (!$isRecursive) {
         $this->_conn->beginTransaction();
     }
     # if
     /*
      * This is a very crude way to prevent us from running
      * out of memory.
      */
     if (count(self::$mc_CacheList) > 250000 && count($spotList) < 250000) {
         self::$mc_CacheList = array();
         self::$startedWithFullCacheLoad = false;
     }
     // if
     // fetch from cache where possible
     foreach ($spotList as &$spot) {
         if ($spot['collectionInfo'] !== null) {
             $title = $spot['collectionInfo']->getTitle();
             $catType = $spot['collectionInfo']->getCatType();
             $year = $spot['collectionInfo']->getYear();
             if ($this->isInLocalCache($title, $catType, $year)) {
                 $spot['collectionInfo']->setMcId($this->getMcIdFromLocalCache($title, $catType, $year));
                 /*
                  * Try to find this specific collection id. If it isn't matched,
                  * we know for sure the collection is not in the database, because
                  * we always retrieve the list of collections when retrieving the
                  * master collection.
                  */
                 $spot['collectionInfo'] = $this->matchCreateSpecificCollection($spot['collectionInfo'], $spot['stamp'], $spot['id']);
             } else {
                 $toFetch[$spot['collectionInfo']->getTitle()] = array('cattype' => $spot['collectionInfo']->getCatType(), 'year' => $spot['collectionInfo']->getYear());
             }
             // else
         }
         // if
     }
     // foreach
     unset($spot);
     /*
      * Update the local collection information with the latest stamp
      */
     $this->updateMcCollectionStamp();
     // get remaining titles from database
     if (!empty($toFetch)) {
         $this->loadCollectionCache($toFetch);
         /*
          * Loop through all titles once more, and if we still do not have
          * a cache record for these, create the mastercollection record.
          */
         foreach ($toFetch as $key => $val) {
             /*
              * Make sure the master title record is in the db, if we didn't get it
              * the first time, create it now.
              */
             if (!$this->isInLocalCache($key, $val['cattype'], $val['year'])) {
                 # echo 'Creating mastercollections: (' . $key . '),(' . $val['cattype'] . '),('. $val['year'] . ')' . PHP_EOL;
                 $this->_conn->exec('INSERT INTO mastercollections(title, cattype, year, tmdb_id, tvrage_id)
                                           VALUES (:title, :cattype, :year, NULL, NULL)', array(':title' => array($key, PDO::PARAM_STR), ':cattype' => array($val['cattype'], PDO::PARAM_INT), ':year' => array($val['year'], PDO::PARAM_INT)));
                 // add the newly generated mastercollection to the local cache
                 $this->addMcToLocalCache($this->_conn->lastInsertId('mastercollections'), $key, $val['cattype'], $val['year']);
             }
             // if
         }
         // foreach
         /*
          * We call ourselves recursively. This is an ugly solution, but
          * we are rather lazy to not further optimize this until necessary.
          *
          * The above code garantuees us both the specific collection and master
          * record are set, so the second time this is run, the toFetch list
          * will always be empty, so we never recurse more than once. You can
          * get out your pitchforks now.
          */
         $spotList = $this->getCollectionIdList($spotList, true);
     }
     // if
     if (!$isRecursive) {
         /*
          * We try one more time to see if we can re-arrange the movies
          * with the year NULL
          */
         foreach ($spotList as &$spot) {
             if ($spot['collectionInfo'] !== null) {
                 $collInfo = $spot['collectionInfo'];
                 /*
                  * Is there any other year available yet? If so, use that one.
                  */
                 $fixedYear = $this->fixCollectionYear($collInfo->getTitle(), $collInfo->getCatType(), $collInfo->getYear());
                 if ($fixedYear !== null) {
                     $collInfo->setYear($fixedYear);
                     $spot['collectionInfo'] = $this->matchCreateSpecificCollection($collInfo, $spot['stamp'], $spot['id']);
                 }
                 // if
             }
         }
         // foreach
         unset($spot);
         $this->_conn->commit();
     }
     // if
     return $spotList;
 }