public function dump($id) {
        if (VERBOSE) echo "  DUMP $id" ,PHP_EOL;
        $filename = $this->dumps_dir . 'dump-' . $id . '.tar.gz';
        if (file_exists($filename)) {
            // skip
            if (VERBOSE) echo "   SKIPPING : $filename exists" ,PHP_EOL;
            return false;
        } else {
            try {
                $tgz_data = $this->api->api("/reports/dump/{$id}.tgz", 'GET');
            } catch (Exception $e) {
                throw new Exception('Could not find dump with id '.$id);
                exit;
            }
            file_put_contents($filename, $tgz_data);
        }
        $unpacked_files = array();
        chdir(dirname($filename));
        if (exec("/bin/tar -zxvf $filename -C ".$this->tmp_dir, $output)) {


            $injects = array();
            foreach ($output as $file) {
                $thisFile = $this->tmp_dir . $file;
                $unpacked_files[] = $thisFile;
                if (file_exists($thisFile)) {
                    list($model, ) = explode('-', $file);

                    if (isset($this->modelsToTable[$model])) {
                        $table = $this->modelsToTable[$model];
                    } else {
                        // or auto guess?
                        if (DEBUG) echo "   SKIPPING $model : table not found!" ,PHP_EOL;
                        continue;
                    }
                    $sql = "LOAD DATA INFILE '$thisFile' REPLACE INTO TABLE $table CHARACTER SET utf8 IGNORE 1 LINES";
                    if (DEBUG) echo PHP_EOL, 'DEBUG : $sql : ' . $sql, PHP_EOL;
                    $this->db->query($sql);
                }
            }
        } else {
            throw new Exception('File uncompression failed for file ' . $filename);
        }
        foreach ($unpacked_files as $file) {
           unlink($file);
        }
        return true;
    }
public function dump($id) {
        if (VERBOSE) echo "  DUMP $id" ,PHP_EOL;
        $filename = $this->dumps_dir . 'dump-' . $id . '.tar.gz';
        if (file_exists($filename)) {
            // skip
            if (VERBOSE) echo "   SKIPPING : $filename exists" ,PHP_EOL;
            return false;
        } else {
            try {
                $tgz_data = $this->api->api("/reports/dump/{$id}.tgz", 'GET');
            } catch (Exception $e) {
                throw new Exception('Could not find dump with id '.$id);
                exit;
            }
            file_put_contents($filename, $tgz_data);
        }
        $unpacked_files = array();
        chdir(dirname($filename));
        if (exec("/bin/tar -zxvf $filename -C ".$this->tmp_dir, $output)) {


            $injects = array();
            foreach ($output as $file) {
                $thisFile = $this->tmp_dir . $file;
                $unpacked_files[] = $thisFile;
                if (file_exists($thisFile)) {
                    list($model, ) = explode('-', $file);

                    if (isset($this->modelsToTable[$model])) {
                        $table = $this->modelsToTable[$model];
                    } else {
                        // or auto guess?
                        if (DEBUG) echo "   SKIPPING $model : table not found!" ,PHP_EOL;
                        continue;
                    }
                    $sql = "LOAD DATA INFILE '$thisFile' REPLACE INTO TABLE $table CHARACTER SET utf8 IGNORE 1 LINES";
                    if (DEBUG) echo PHP_EOL, 'DEBUG : $sql : ' . $sql, PHP_EOL;
                    $this->db->query($sql);
                }
            }
        } else {
            throw new Exception('File uncompression failed for file ' . $filename);
        }
        foreach ($unpacked_files as $file) {
           unlink($file);
        }
        return true;
    }
public function dump ( $ id ) { if ( VERBOSE ) echo "  DUMP $id" , PHP_EOL ; $ filename = $ this -> dumps_dir . 'dump-' . $ id . '.tar.gz' ; if ( file_exists ( $ filename ) ) { // skip if ( VERBOSE ) echo "   SKIPPING : $filename exists" , PHP_EOL ; return false ; } else { try { $ tgz_data = $ this -> api -> api ( "/reports/dump/{$id}.tgz" , 'GET' ) ; } catch ( Exception $ e ) { throw new Exception ( 'Could not find dump with id ' . $ id ) ; exit ; } file_put_contents ( $ filename , $ tgz_data ) ; } $ unpacked_files = array ( ) ; chdir ( dirname ( $ filename ) ) ; if ( exec ( "/bin/tar -zxvf $filename -C " . $ this -> tmp_dir , $ output ) ) { $ injects = array ( ) ; foreach ( $ output as $ file ) { $ thisFile = $ this -> tmp_dir . $ file ; $ unpacked_files [ ] = $ thisFile ; if ( file_exists ( $ thisFile ) ) { list ( $ model , ) = explode ( '-' , $ file ) ; if ( isset ( $ this -> modelsToTable [ $ model ] ) ) { $ table = $ this -> modelsToTable [ $ model ] ; } else { // or auto guess? if ( DEBUG ) echo "   SKIPPING $model : table not found!" , PHP_EOL ; continue ; } $ sql = "LOAD DATA INFILE '$thisFile' REPLACE INTO TABLE $table CHARACTER SET utf8 IGNORE 1 LINES" ; if ( DEBUG ) echo PHP_EOL , 'DEBUG : $sql : ' . $ sql , PHP_EOL ; $ this -> db -> query ( $ sql ) ; } } } else { throw new Exception ( 'File uncompression failed for file ' . $ filename ) ; } foreach ( $ unpacked_files as $ file ) { unlink ( $ file ) ; } return true ; }
If dump id file does not exist, download and inject it to db

Download dump from api, unpack it
Foreach unpacked file, inject it into db and then delete it.

@param int $id
@return boolean false if file exists and it therefore skipped it
If dump id file does not exist download and inject it to db