Beispiel #1
0
 private function writeItem($groupName, $basePath, $load_stream)
 {
     if (key_exists($groupName, $this->writtenGroups)) {
         return;
     }
     if (key_exists($groupName, $this->processing)) {
         print_r($this->dependencies);
         print_r($this->processing);
         fprintf(STDERR, "Circular dependency; see output above\n");
         exit(1);
     }
     $this->processing[$groupName] = true;
     if (key_exists($groupName, $this->dependencies)) {
         foreach ($this->dependencies[$groupName] as $dependency) {
             if (!key_exists($dependency, $this->groups)) {
                 throw new Exception("Group {$groupName} depends on bogus group {$dependency}");
             }
             $this->writeItem($dependency, $basePath, $load_stream);
         }
     }
     unset($this->processing[$groupName]);
     $sqlFile = "{$basePath}/{$groupName}.sql";
     $f = function () use($sqlFile) {
         static $stream = null;
         if ($stream === null) {
             if (!is_dir(dirname($sqlFile))) {
                 if (!mkdir(dirname($sqlFile))) {
                     throw new Exception("Could not create directory {$sqlFile}");
                 }
             }
             $stream = fopen($sqlFile, "wb");
         }
         if (!$stream) {
             throw new Exception("Could not open file {$sqlFile}");
         }
         return $stream;
     };
     $items = $this->groups[$groupName];
     foreach ($items as $i) {
         if (!$i instanceof Item) {
             throw new RuntimeException("Non-item in group {$groupName}: {$i}");
         }
         if (!in_array([$i->type, preg_replace('/\\(.*/', '', $i->name)], $this->skippedObjects, true)) {
             PGDumpReaderWriter::writeSingleItem($f(), $i);
         }
         $this->writtenItems[$i] = null;
     }
     if ($load_stream !== null) {
         $this->writeLoadInclude($basePath, "{$groupName}.sql", $load_stream);
     }
     $this->writtenGroups[$groupName] = null;
 }
<?php

require __DIR__ . "/classes.php";
if ($argc != 3) {
    fprintf(STDERR, "Syntax: php %s <in file> <class>\n", $argv[0]);
    exit(1);
}
$filter = new PGDumpFilter(new PGDumpReaderWriter($argv[1]), function (Item $it) use($argv) {
    return $it->type == $argv[2];
});
$filter->readAll();
foreach ($filter->getItems() as $item) {
    PGDumpReaderWriter::writeSingleItem(STDOUT, $item);
}