Example #1
0
 /**
  * @param Doctrine\MongoDB\Database
  * @param string $file
  *
  * @return array
  *
  * @throws RuntimeException
  * @throws InvalidArgumentException
  * @throws Exception
  */
 public function executeScript(Database $db, $file)
 {
     $scripts = $this->configuration->getMigrationsScriptDirectory();
     if (null === $scripts) {
         throw new \RuntimeException('Missing Configuration for migrations script directory');
     }
     $path = realpath($scripts . '/' . $file);
     if (!file_exists($path)) {
         throw new \InvalidArgumentException(sprintf('Could not execute %s. File does not exist.', $path));
     }
     try {
         $js = file_get_contents($path);
         if (false === $js) {
             throw new \Exception('file_get_contents returned false');
         }
     } catch (\Exception $e) {
         throw $e;
     }
     $result = $db->command(array('$eval' => $js, 'nolock' => true));
     if (isset($result['errmsg'])) {
         throw new \Exception($result['errmsg'], isset($result['errno']) ? $result['errno'] : null);
     }
     return $result;
 }