Ejemplo n.º 1
0
 /**
  * Releases all shallow locks set within this request
  */
 public function shallowUnlock()
 {
     BeeHub_DB::query('COMMIT;');
 }
Ejemplo n.º 2
0
}
print "ok\n";
// Then import the database structure
$mysql = \BeeHub_DB::mysqli();
if ($mysql->connect_errno) {
    \header('HTTP/1.1 500 Internal Server Error');
    \ob_end_flush();
    print "\nFailed to connect to MySQL: (" . $mysql->connect_errno . ") " . $mysql->connect_error . "\n";
    exit;
}
$result = $mysql->query('SHOW TABLES');
if ($result->num_rows > 0) {
    print "MySQL database already contains tables. Skipping initialisation of database.\n";
} else {
    print "Creating database structure...";
    if (\BeeHub_DB::createDbTables() === false) {
        \header('HTTP/1.1 500 Internal Server Error');
        \ob_end_flush();
        print "\nUnable to create database structure\n";
        exit;
    }
    print "ok\n";
}
// Create principals.js with displaynames of all principals
\BeeHub_Principal::update_principals_json();
// Let 'them' know everything went well
print "\nDone configuring webserver\n";
\ob_end_flush();
/**
 * Checks whether a PHP configuration value is correct
 * 
Ejemplo n.º 3
0
 /**
  * Creates the database tables
  * 
  * @return  boolean  True on success, false of failure
  */
 public static function createDbTables()
 {
     $mysql = \BeeHub_DB::mysqli();
     $query = '';
     $filePointer = \fopen(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'db' . \DIRECTORY_SEPARATOR . 'db_structure.sql', 'r');
     while (($line = \fgets($filePointer)) !== false) {
         if (\substr($line, 0, 2) === '--') {
             continue;
         }
         $query .= ' ' . \trim($line);
         if (\substr($query, -1) === ';') {
             if ($mysql->real_query($query) === false) {
                 return false;
             }
             $query = '';
         }
     }
     \fclose($filePointer);
     return true;
 }
Ejemplo n.º 4
0
 public function testShallowWriteLock()
 {
     declare (ticks=1) {
         @\unlink('locksAreSet.deleteMe');
         @\unlink('allowWriteLocks.deleteMe');
         @\unlink('writeLockHangsLongEnough.deleteMe');
         @\unlink('writeLockSet.deleteMe');
         $registry = \BeeHub_Registry::inst();
         $pid = pcntl_fork();
         if ($pid === -1) {
             $this->markTestSkipped("Unable to fork process");
             return;
         }
         \BeeHub_DB::forceReconnect();
         if ($pid !== 0) {
             // This is the parent process. I could put this code after the if statement,
             // But now everything in the code is in the same (chronological) order as
             // how it is supposed to run.
             // Set a shallow read and write lock should just happen
             $timeBeforeLocks = time();
             $registry->shallowLock(array('/foo/file.txt'), array('/foo/file2.txt'));
             $this->assertGreaterThanOrEqual(-1, $timeBeforeLocks - time());
             // Let's assert that it takes less than a second to set the locks, else something is seriously wrong
             \touch('locksAreSet.deleteMe');
         } elseif ($pid === 0) {
             // we are the child
             $this->alternate_pid = true;
             $counter = 0;
             while (!\file_exists('locksAreSet.deleteMe')) {
                 \sleep(1);
                 if ($counter++ > 10) {
                     $this->assertTrue(false, 'Waited for 10 seconds for the initial locks to be set. This is really much much much too long');
                 }
             }
             // From another thread: Setting a shallow write lock on a resource with another write lock should hang until the other write lock is released
             $registry->shallowLock(array('/foo/file.txt'));
             if (\file_exists('allowWriteLocks.deleteMe')) {
                 \touch('writeLockHangsLongEnough.deleteMe');
             }
             \touch('writeLockSet.deleteMe');
             \BeeHub_DB::mysqli()->close();
             exit;
         }
         // Only the parent process will get to this
         // Then let's wait a second
         \sleep(2);
         \touch('allowWriteLocks.deleteMe');
         $registry->shallowUnlock();
         $counter = 0;
         while (!\file_exists('writeLockSet.deleteMe')) {
             \sleep(1);
             if ($counter++ > 10) {
                 $this->assertTrue(false, 'Waited for 10 seconds for the write lock to be set. This is really much much much too long');
             }
         }
         $this->assertTrue(\file_exists('writeLockHangsLongEnough.deleteMe'), 'A shallow write lock can not be set on resources with another shallow write lock');
         @\unlink('locksAreSet.deleteMe');
         @\unlink('allowWriteLocks.deleteMe');
         @\unlink('writeLockHangsLongEnough.deleteMe');
         @\unlink('writeLockSet.deleteMe');
     }
 }