Ejemplo n.º 1
0
 protected function setUp()
 {
     try {
         $dbparams = ezcTestSettings::getInstance()->db->dsn;
         MyDB::setParams($dbparams);
         $this->db = MyDB::create();
     } catch (Exception $e) {
         $this->markTestSkipped();
     }
 }
Ejemplo n.º 2
0
function convert()
{
    global $tmp_path, $db_filename, $inpx_input;
    $db = new MyDB($tmp_path . $db_filename);
    if (!$db) {
        die($db->lastErrorMsg());
    }
    $db->create();
    // get the absolute path to $file
    //$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
    $zip = new ZipArchive();
    $res = $zip->open($inpx_input);
    if ($res === TRUE) {
        // extract it to the path we determined above
        $zip->extractTo($tmp_path);
        $zip->close();
        echo "{$file} extracted to {$tmp_path}\n";
    } else {
        echo "Doh! I couldn't open {$inpx_input}\n";
    }
    $sep = chr(0x4);
    foreach (glob($tmp_path . '*.inp') as $file) {
        echo $file . "\n";
        $records = explode("\n", file_get_contents($file));
        foreach ($records as $rec) {
            $array = explode($sep, $rec);
            $authors_ids = array();
            $authors = explode(':', $array[0]);
            foreach ($authors as $author) {
                if (!empty($author)) {
                    $author = trim(str_replace(',', ' ', $author), " -\t\r!@#\$%^&*()_=+|");
                    $author_id = $db->addAuthor($author);
                    //echo "$author_id -> $author\n";
                    if ($author_id) {
                        $authors_ids[] = $author_id;
                    }
                }
            }
            $genres_ids = array();
            $genres = explode(':', $array[1]);
            foreach ($genres as $genre) {
                if (!empty($genre)) {
                    $genre_id = $db->addGenre($genre);
                    //echo "$genre_id -> $genre\n";
                    if ($genre_id) {
                        $genres_ids[] = $genre_id;
                    }
                }
            }
            $title = trim($array[2], " \t");
            $title_id = $db->addTitle($title);
            //echo "$title_id -> $title\n";
            $file_name = trim($array[5], " \t");
            $file_size = trim($array[6], " \t");
            $file_ext = trim($array[9], " \t");
            $date_add = trim($array[10], " \t");
            $lang = trim($array[11], "' \t");
            //echo "$file_name $file_ext\n";
            $db->addFile($authors_ids, $genres_ids, $title_id, $file_name, $file_ext, $file_size, $lang, $date_add);
        }
    }
    $db->close();
    rename($tmp_path . $db_filename, './' . $db_filename);
    // TODO: cleanup temporary directory
    exit;
}