Ejemplo n.º 1
0
function recommendations_featured($job, $step)
{
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $old = "{$fw['installerCFG.db3.dbname']}`.`{$fw['installerCFG.db3.prefix']}fanfiction_";
    $i = 0;
    $newdata = new \DB\SQL\Mapper($fw->db5, $fw['installerCFG.db5.prefix'] . "featured");
    $dataIn = $fw->db3->exec("SELECT Rec.recid as id, Rec.featured as status, 'RC' as type FROM `{$old}recommendations`Rec WHERE Rec.featured > 0;");
    foreach ($dataIn as $data) {
        $i++;
        $newdata->copyfrom($data);
        $newdata->save();
        $newdata->reset();
    }
    $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 2, `items` = :items WHERE `id` = :id ", [':items' => $i, ':id' => $step['id']]);
}
Ejemplo n.º 2
0
function textblocks_copy($job, $step)
{
    // Copy the existing blocks
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $old = "{$fw['installerCFG.db3.dbname']}`.`{$fw['installerCFG.db3.prefix']}fanfiction_";
    $i = 0;
    $newdata = new \DB\SQL\Mapper($fw->db5, $fw['installerCFG.db5.prefix'] . "textblocks");
    $dataIn = $fw->db3->exec("SELECT message_id as id, message_name as label, message_title as title, message_text as content, 1 as as_page FROM `{$old}messages`;");
    foreach ($dataIn as $data) {
        $i++;
        $newdata->copyfrom($data);
        $newdata->save();
        $newdata->reset();
    }
    $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 2, `items` = :items WHERE `id` = :id ", [':items' => $i, ':id' => $step['id']]);
}
Ejemplo n.º 3
0
 function order()
 {
     $return = "";
     $domain = $this->f3->get("domain");
     //$ID = (isset($_GET['ID'])) ? $_GET['ID'] : "";
     $f3 = \Base::instance();
     $list = $_POST['id'];
     $a = new \DB\SQL\Mapper($f3->get("DB"), "dir_categories");
     $sort = array();
     foreach ($list as $id => $parentId) {
         $a->load("ID='{$id}'");
         $a->parentID = $parentId;
         if (!$a->dry()) {
             $a->save();
         }
         $a->reset();
     }
     test_array($sort);
     return $GLOBALS["output"]['data'] = $return;
 }
Ejemplo n.º 4
0
function users_fields($job, $step)
{
    /*
    	1 = URL
    	2 = Options
    	3 = yes/no
    	4 = URL with ID
    	5 = code -> now tpl field
    	6 = text
    */
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $old = "{$fw['installerCFG.db3.dbname']}`.`{$fw['installerCFG.db3.prefix']}fanfiction_";
    $limit = 50;
    $i = 0;
    $newdata = new \DB\SQL\Mapper($fw->db5, $fw['installerCFG.db5.prefix'] . "user_fields");
    $dataIn = $fw->db3->exec("SELECT `field_id`, `field_type`, `field_name`, `field_title`, `field_options`, `field_code_out`, `field_on`\r\n\t\t\t\t\t\t\tFROM `{$old}authorfields`\r\n\t\t\t\t\t\t\tORDER BY `field_id` ASC;");
    foreach ($dataIn as $data) {
        $i++;
        if ($data['field_type'] == 2) {
            $data['field_options'] = json_encode(explode("|#|", $data['field_options']));
        }
        if ($data['field_type'] == 5) {
            // Code fields are now tpl fields
            $data['field_options'] = $data['field_code_out'];
            // Disable, so it won't show weird stuff before being modified
            $data['field_on'] = 0;
        }
        $newdata->copyfrom($data);
        $newdata->save();
        $newdata->reset();
    }
    // Add avatar field (formerly image from author info)
    //$fw->db5->exec("INSERT INTO `{$new}user_fields` ( field_type, field_name, field_title ) VALUES ( 1, 'avatar', 'Avatar' );");
    $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 2, `items` = :items WHERE `id` = :id ", [':items' => $i, ':id' => $step['id']]);
}
Ejemplo n.º 5
0
function various_poll($job, $step)
{
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $old = "{$fw['installerCFG.db3.dbname']}`.`{$fw['installerCFG.db3.prefix']}fanfiction_";
    $limit = 20;
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    $newdata = new \DB\SQL\Mapper($fw->db5, $fw['installerCFG.db5.prefix'] . "poll");
    if ($step['success'] == 0) {
        try {
            $total = $fw->db3->exec("SELECT COUNT(*) as found FROM `{$old}poll`;")[0]['found'];
            $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 1, `total` = :total WHERE `id` = :id ", [':total' => $total, ':id' => $step['id']]);
        } catch (PDOException $e) {
            // There's no source table, so we just finish with 0 entries
            $tracking->items = -1;
            $tracking->success = 2;
            $tracking->save();
            return TRUE;
            // escape plan
        }
    }
    $dataIn = $fw->db3->exec("SELECT `poll_id`, `poll_question` as question, `poll_opts` as options, `poll_start` as start_date, `poll_end` as end_date, `poll_results` as results\r\n\t\t\t\t\t\t\t\tFROM `{$old}poll` \r\n\t\t\t\t\t\t\t\tORDER BY `poll_id` ASC LIMIT {$step['items']},{$limit};");
    if (0 < ($count = sizeof($dataIn))) {
        foreach ($dataIn as $data) {
            $data['results'] = $data['results'] == NULL ? NULL : json_encode(explode("#", $data['results']));
            $data['options'] = json_encode(explode("|#|", $data['options']));
            $newdata->copyfrom($data);
            $newdata->save();
            $newdata->reset();
            $tracking->items = $tracking->items + 1;
            $tracking->save();
        }
    }
    if ($count == 0 or $count <= $limit) {
        // There was either nothing to be done, or there are no elements left for the next run
        $tracking->success = 2;
        $tracking->save();
    }
}
Ejemplo n.º 6
0
 private function runTestSuite($db)
 {
     $schema = new \DB\SQL\Schema($db);
     $schema->dropTable($this->tname);
     // create table
     $table = $schema->createTable($this->tname);
     $table = $table->build();
     $result = $schema->getTables();
     $this->test->expect(in_array($this->tname, $result), $this->getTestDesc('create default table'));
     unset($result);
     $this->test->expect($table instanceof \DB\SQL\TableModifier, $this->getTestDesc('$table->build() returns TableModifier'));
     // drop table
     $table->drop();
     $this->test->expect(in_array($this->tname, $schema->getTables()) == false, $this->getTestDesc('drop table'));
     unset($table);
     // create table with columns
     $table = $schema->createTable($this->tname);
     $table->addColumn('title')->type($schema::DT_VARCHAR128);
     $table->addColumn('number')->type($schema::DT_INT4);
     $table = $table->build();
     $r1 = $schema->getTables();
     $r2 = $table->getCols();
     $this->test->expect(in_array($this->tname, $r1) && in_array('id', $r2) && in_array('title', $r2) && in_array('number', $r2), $this->getTestDesc('create new table with additional columns'));
     unset($r1, $r2);
     // testing all datatypes
     foreach (array_keys($schema->dataTypes) as $index => $field) {
         // testing column type
         $table->addColumn('column_' . $index)->type($field);
         $table->build();
         $r1 = $table->getCols();
         $this->test->expect(in_array('column_' . $index, $r1), $this->getTestDesc('adding column [' . $field . '], nullable'));
     }
     unset($r1);
     // adding some testing data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'hello world';
     $mapper->save();
     $mapper->reset();
     $result = $mapper->findone(array('column_7 = ?', 'hello world'))->cast();
     unset($mapper);
     $this->test->expect($result['column_7'] == 'hello world', $this->getTestDesc('mapping dummy data'));
     // default value text, not nullable
     $table->addColumn('text_default_not_null')->type($schema::DT_VARCHAR128)->nullable(false)->defaults('foo bar');
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('text_default_not_null', array_keys($r1)) && $r1['text_default_not_null']['default'] == 'foo bar' && $r1['text_default_not_null']['nullable'] == false, $this->getTestDesc('adding column [VARCHAR128], not nullable with default value'));
     unset($r1);
     // some testing dummy data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'tanduay';
     $mapper->save();
     $mapper->reset();
     $result = $mapper->findone(array('column_7 = ?', 'tanduay'))->cast();
     $this->test->expect($result['column_7'] == 'tanduay' && $result['text_default_not_null'] == 'foo bar', $this->getTestDesc('mapping dummy data'));
     unset($mapper, $result);
     // default value numeric, not nullable
     $table->addColumn('int_default_not_null')->type($schema::DT_INT4)->nullable(false)->defaults(123);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('int_default_not_null', array_keys($r1)) && $r1['int_default_not_null']['default'] == 123 && $r1['int_default_not_null']['nullable'] == false, $this->getTestDesc('adding column [INT4], not nullable with default value'));
     unset($r1);
     // adding testing data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'test3';
     $mapper->save();
     $mapper->reset();
     $r1 = $mapper->findone(array('column_7 = ?', 'test3'))->cast();
     $this->test->expect($r1['column_7'] == 'test3' && $r1['int_default_not_null'] == 123, $this->getTestDesc('mapping dummy data'));
     unset($mapper, $r1);
     // default value text, nullable
     $table->addColumn('text_default_nullable')->type($schema::DT_VARCHAR128)->defaults('foo bar');
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('text_default_nullable', array_keys($r1)) && $r1['text_default_nullable']['default'] == 'foo bar', $this->getTestDesc('adding column [VARCHAR128], nullable with default value'));
     unset($r1);
     // adding some dummy data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'test4';
     $mapper->save();
     $mapper->reset();
     $mapper->column_7 = 'test5';
     $mapper->text_default_nullable = null;
     $mapper->save();
     $mapper->reset();
     $result = $mapper->find(array('column_7 = ? OR column_7 = ?', 'test4', 'test5'));
     foreach ($result as &$r) {
         $r = $r->cast();
     }
     $this->test->expect(array_key_exists(0, $result) && array_key_exists(1, $result) && $result[0]['column_7'] == 'test4' && $result[0]['text_default_nullable'] == 'foo bar' && $result[1]['column_7'] == 'test5' && $result[1]['text_default_nullable'] === null, $this->getTestDesc('mapping dummy data'));
     unset($mapper, $result);
     // default value numeric, nullable
     $table->addColumn('int_default_nullable')->type($schema::DT_INT4)->defaults(123);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('int_default_nullable', array_keys($r1)) == true && $r1['int_default_nullable']['default'] == 123, $this->getTestDesc('adding column [INT4], nullable with default value'));
     unset($r1);
     // adding dummy data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'test6';
     $mapper->save();
     $mapper->reset();
     $mapper->column_7 = 'test7';
     $mapper->int_default_nullable = null;
     $mapper->save();
     $mapper->reset();
     $result = $mapper->find(array('column_7 = ? OR column_7 = ?', 'test6', 'test7'));
     foreach ($result as &$r) {
         $r = $r->cast();
     }
     $this->test->expect(array_key_exists(0, $result) && array_key_exists(1, $result) && $result[0]['column_7'] == 'test6' && $result[0]['int_default_nullable'] === 123 && $result[1]['column_7'] == 'test7' && $result[1]['int_default_nullable'] === null, $this->getTestDesc('mapping dummy data'));
     unset($mapper, $result);
     // current timestamp
     $table->addColumn('stamp')->type($schema::DT_TIMESTAMP)->nullable(false)->defaults($schema::DF_CURRENT_TIMESTAMP);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('stamp', array_keys($r1)) && $r1['stamp']['default'] == $schema::DF_CURRENT_TIMESTAMP, $this->getTestDesc('adding column [TIMESTAMP], not nullable with current_timestamp default value'));
     unset($r1);
     // datetime nullable
     $table->addColumn('datetime')->type_datetime()->nullable(true);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(in_array('datetime', array_keys($r1)) && $r1['datetime']['nullable'] == true, $this->getTestDesc('adding column [DATETIME], nullable, no default'));
     unset($r1);
     // adding dummy data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->column_7 = 'test_datetime';
     $mapper->datetime = NULL;
     $mapper->save();
     $mapper->reset();
     $result = $mapper->find(array('column_7 = ?', 'test_datetime'));
     foreach ($result as &$r) {
         $r = $r->cast();
     }
     $this->test->expect(array_key_exists(0, $result) && $result[0]['column_7'] == 'test_datetime' && $result[0]['datetime'] === null, $this->getTestDesc('mapping dummy data'));
     unset($mapper, $result);
     // rename column
     $table->renameColumn('text_default_not_null', 'title123');
     $table->build();
     $r1 = $table->getCols();
     $this->test->expect(in_array('title123', $r1) && !in_array('text_default_not_null', $r1), $this->getTestDesc('renaming column'));
     unset($r1);
     // adding dummy data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->title123 = 'test8';
     $mapper->save();
     $mapper->reset();
     $result = $mapper->findone(array('title123 = ?', 'test8'));
     $this->test->expect(!$result->dry(), $this->getTestDesc('mapping dummy data'));
     $table->renameColumn('title123', 'text_default_not_null');
     $table->build();
     unset($result, $mapper);
     // remove column
     $table->dropColumn('column_1');
     $table->build();
     $r1 = $table->getCols();
     $this->test->expect(!in_array('column_1', $r1), $this->getTestDesc('removing column'));
     unset($r1);
     // rename table
     $schema->dropTable('test123');
     $table->rename('test123');
     $result = $schema->getTables();
     $this->test->expect(in_array('test123', $result) && !in_array($this->tname, $result), $this->getTestDesc('renaming table'));
     $table->rename($this->tname);
     unset($result);
     // check record count
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $this->test->expect(count($mapper->find()) == 9, $this->getTestDesc('check record count'));
     unset($mapper);
     // adding composite primary keys
     $table->addColumn('version')->type($schema::DT_INT4)->nullable(false)->defaults(1);
     $table->primary(array('id', 'version'));
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(!empty($r1) && isset($r1['version']) && $r1['id']['pkey'] == true && $r1['version']['pkey'] == true, $this->getTestDesc('adding composite primary-keys'));
     unset($r1);
     // check record count
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $this->test->expect(count($mapper->find()) == 9, $this->getTestDesc('check record count'));
     unset($mapper);
     // drop table
     $schema->dropTable($this->tname);
     $this->test->expect(!in_array($this->tname, $schema->getTables()), $this->getTestDesc('drop table'));
     // adding composite primary keys
     $table = $schema->createTable($this->tname);
     $table->addColumn('version')->type($schema::DT_INT4)->defaults(1)->nullable(false);
     $table->primary(array('id', 'version'));
     $table = $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(!empty($r1) && $r1['id']['pkey'] == true && $r1['version']['pkey'] == true, $this->getTestDesc('creating new table with composite key'));
     $this->test->expect(!empty($r1) && $r1['version']['default'] == '1', $this->getTestDesc('default value on composite primary key'));
     unset($r1);
     // more fields to composite primary key table
     $table->addColumn('title')->type($schema::DT_VARCHAR256);
     $table->addColumn('title2')->type($schema::DT_TEXT);
     $table->addColumn('title_notnull')->type($schema::DT_VARCHAR128)->nullable(false)->defaults("foo");
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(array_key_exists('title', $r1) && array_key_exists('title_notnull', $r1) && $r1['id']['pkey'] == true && $r1['version']['pkey'] == true, $this->getTestDesc('adding more fields to composite pk table'));
     unset($r1);
     // testing primary keys with inserted data
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->title = 'test1';
     $mapper->save();
     $mapper->reset();
     $mapper->id = 1;
     $mapper->title = 'nullable';
     $mapper->version = 2;
     $mapper->save();
     $mapper->reset();
     $mapper->title = 'test3';
     $mapper->title2 = 'foobar';
     $mapper->title_notnull = 'bar';
     $mapper->save();
     $result = array_map(array($mapper, 'cast'), $mapper->find());
     $cpk_expected = array(0 => array('id' => 1, 'version' => 1, 'title' => 'test1', 'title2' => NULL, 'title_notnull' => 'foo'), 1 => array('id' => 1, 'version' => 2, 'title' => 'nullable', 'title2' => NULL, 'title_notnull' => 'foo'), 2 => array('id' => 2, 'version' => 1, 'title' => 'test3', 'title2' => 'foobar', 'title_notnull' => 'bar'));
     foreach ($result as &$r) {
         ksort($r);
     }
     foreach ($cpk_expected as &$r) {
         ksort($r);
     }
     $this->test->expect(json_encode($result) == json_encode($cpk_expected), $this->getTestDesc('adding items with composite primary-keys'));
     $schema->dropTable($this->tname);
     // indexes
     $table = $schema->createTable($this->tname);
     $table->addColumn('rawtest', array('type' => $schema::DT_VARCHAR256, 'default' => 'foo'));
     $table->addColumn('text')->type($schema::DT_TEXT);
     $table->addColumn('foo')->type($schema::DT_VARCHAR128)->index();
     $table = $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(isset($r1['rawtest']) && ($r1['rawtest']['default'] = 'foo'), $this->getTestDesc('adding column with options array'));
     $indexes = $table->listIndex();
     $this->test->expect(isset($indexes[$table->name . '___foo']), $this->getTestDesc('column index on table creation'));
     $table->addColumn('bar')->type($schema::DT_VARCHAR128)->index(true);
     $table->addColumn('baz')->type($schema::DT_VARCHAR128);
     $table->addIndex(array('foo', 'baz'));
     $table->build();
     $indexes = $table->listIndex();
     $this->test->expect(isset($indexes[$table->name . '___bar']), $this->getTestDesc('column index on table alteration'));
     $this->test->expect(isset($indexes[$table->name . '___bar']) && $indexes[$table->name . '___bar']['unique'] == true, $this->getTestDesc('unique index'));
     $this->test->expect(isset($indexes[$table->name . '___foo__baz']), $this->getTestDesc('index on combined columns'));
     if ($this->current_engine == 'sqlite') {
         $table->dropColumn('rawtest');
         $table->build();
         $indexes = $table->listIndex();
         $this->test->expect(isset($indexes[$table->name . '___foo__baz']) && isset($indexes[$table->name . '___bar']) && $indexes[$table->name . '___bar']['unique'], $this->getTestDesc('preserve indexes after table rebuild'));
     }
     $table->dropIndex($table->name . '___bar');
     $table->build();
     $indexes = $table->listIndex();
     $this->test->expect(!array_key_exists($table->name . '___bar', $indexes), $this->getTestDesc('drop index'));
     // update column
     $table->updateColumn('bar', $schema::DT_TEXT);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(array_key_exists('bar', $r1) && $r1['bar']['type'] == 'text', $this->getTestDesc('update column'));
     // create table with text not nullable column
     $table2 = $schema->createTable($this->tname . '_notnulltext');
     $table2->addColumn('desc')->type($schema::DT_TEXT)->nullable(false);
     $table2 = $table2->build();
     $r1 = $schema->getTables();
     $r2 = $table2->getCols(true);
     $this->test->expect(in_array($this->tname . '_notnulltext', $r1) && array_key_exists('desc', $r2) && $r2['desc']['nullable'] == false, $this->getTestDesc('create new table with not nullable text column'));
     $table2->drop();
 }
Ejemplo n.º 7
0
function chapters_copy($job, $step)
{
    // Chapters copy is a 1-pass module, doing the entire chapter relocation
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $old = "{$fw['installerCFG.db3.dbname']}`.`{$fw['installerCFG.db3.prefix']}fanfiction_";
    $limit = 100;
    $report = [];
    $source = $fw->get('installerCFG.data.store');
    // "files" or "mysql"
    $target = $fw->get('installerCFG.chapters');
    // "filebase" or "database"
    // Initialize
    if ($step['success'] == 0) {
        // drop an existing chapter DB file
        if (file_exists(realpath('..') . '/data/chapters.sq3')) {
            unlink(realpath('..') . '/data/chapters.sq3');
        }
        // if we need the filebase storage, initialize it now
        if ($target = "filebase") {
            $fw->dbsqlite = new DB\SQL('sqlite:' . realpath('..') . '/data/chapters.sq3');
            $fw->dbsqlite->begin();
            $fw->dbsqlite->exec("DROP TABLE IF EXISTS 'chapters'");
            $fw->dbsqlite->exec("CREATE TABLE IF NOT EXISTS 'chapters' ('chapid' INTEGER PRIMARY KEY NOT NULL, 'sid' INTEGER, 'chaptertext' BLOB);");
            // inorder might be obsolete
            //$fw->dbsqlite->exec ( "CREATE TABLE IF NOT EXISTS 'chapters' ('chapid' INTEGER PRIMARY KEY NOT NULL, 'sid' INTEGER, 'inorder' INTEGER,'chaptertext' BLOB);" );
            $fw->dbsqlite->commit();
            unset($fw->dbsqlite);
        } else {
        }
        // Count total chapters and take note
        $total = $fw->db3->exec("SELECT COUNT(*) as found FROM `{$old}chapters`;")[0]['found'];
        $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 1, `total` = :total WHERE `id` = :id ", [':total' => $total, ':id' => $step['id']]);
    }
    $dataIn = $fw->db3->exec("SELECT COUNT(reviewid) as reviewsNew, Ch.uid as folder, Ch.chapid as chapter, Ch.*\r\n\t\t\t\t\t\t\t\tFROM `{$old}chapters`Ch \r\n\t\t\t\t\t\t\t\tLEFT JOIN `{$old}reviews`R ON ( Ch.chapid = R.chapid AND R.type='ST' )\r\n\t\t\t\t\t\t\t\tGROUP BY Ch.chapid\r\n\t\t\t\t\t\t\t\tORDER BY chapid ASC LIMIT {$step['items']},{$limit};");
    if (0 < ($count = sizeof($dataIn))) {
        $newchapter = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'chapters');
        if ($target = "filebase") {
            $fw->dbsqlite = new DB\SQL('sqlite:' . realpath('..') . '/data/chapters.sq3');
            $newchapterText = new DB\SQL\Mapper($fw->dbsqlite, 'chapters');
        }
        $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
        $tracking->load(['id = ?', $step['id']]);
        foreach ($dataIn as $chapterIn) {
            // Get chapter text, from file or DB
            if ($source == "files") {
                $s = upgradetools::getChapterFile($chapterIn);
                if ($s[0]) {
                    $chaptertext = mb_convert_encoding($s[1], "UTF-8", mb_detect_encoding($s[1], 'UTF-8, ISO-8859-1'));
                } else {
                    // report error
                }
            } elseif ($source == "mysql") {
                $chaptertext = $chapterIn['storytext'];
            }
            if ($target == "filebase") {
                // No text in Database
                $newchapter->chaptertext = NULL;
                // Store data in the filebase storage
                $newchapterText->chapid = $chapterIn['chapter'];
                $newchapterText->sid = $chapterIn['sid'];
                //$newchapterText->inorder	= $chapterIn['inorder'];
                $newchapterText->chaptertext = $chaptertext;
                $newchapterText->save();
                $newchapterText->reset();
            } else {
                $newchapter->chaptertext = $chaptertext;
            }
            $newchapter->chapid = $chapterIn['chapter'];
            $newchapter->sid = $chapterIn['sid'];
            $newchapter->title = $chapterIn['title'];
            $newchapter->inorder = $chapterIn['inorder'];
            $newchapter->notes = $chapterIn['notes'];
            $newchapter->endnotes = $chapterIn['endnotes'];
            $newchapter->validated = $chapterIn['validated'];
            $newchapter->wordcount = count(preg_split("/\\p{L}[\\p{L}\\p{Mn}\\p{Pd}'\\x{2019}]{1,}/u", $chaptertext));
            $newchapter->rating = $chapterIn['rating'];
            $newchapter->reviews = $chapterIn['reviewsNew'];
            $newchapter->count = $chapterIn['count'];
            $newchapter->save();
            $newchapter->reset();
            $tracking->items = $tracking->items + 1;
            $tracking->save();
        }
        //
    }
    if ($count == 0 or $count < $limit) {
        // There was either nothing to be done, or there are no elements left for the next run
        $tracking->success = 2;
        $tracking->save();
    }
}
Ejemplo n.º 8
0
 static function save($ID, $values)
 {
     $timer = new timer();
     $f3 = \base::instance();
     $user = $f3->get("user");
     //	test_array($values);
     $IDorig = $ID;
     $changes = array();
     $art = new \DB\SQL\Mapper($f3->get("DB"), "dir_items");
     $art->load("ID='{$ID}'");
     //	test_array(array($art->ID,$ID));
     //test_array($this->get("14"));
     foreach ($values as $key => $value) {
         $value = $f3->scrub($value, $f3->get("TAGS"));
         if (isset($art->{$key})) {
             $art->{$key} = $value;
         }
     }
     $art->save();
     $ID = $art->ID ? $art->ID : $art->_id;
     if (isset($values['photos'])) {
         $art = new \DB\SQL\Mapper($f3->get("DB"), "dir_items_photos");
         foreach ($values['photos'] as $item) {
             $art->load("ID='{$item['ID']}'");
             $art->itemID = $ID;
             $art->photo = $item['photo'];
             $art->save();
             $art->reset();
         }
     }
     if (isset($values['categoryID'])) {
         $f3->get("DB")->exec("DELETE FROM dir_item_category WHERE itemID = '{$ID}';");
         if (count($values['categoryID'])) {
             foreach ((array) $values['categoryID'] as $item) {
                 $f3->get("DB")->exec("INSERT INTO dir_item_category  (itemID, catID) VALUES ('{$ID}','{$item}');");
             }
         }
     }
     $timer->_stop(__NAMESPACE__, __CLASS__, __FUNCTION__, func_get_args());
     return $ID;
 }
Ejemplo n.º 9
0
 function post_delete_food($f3)
 {
     $orm = new DB\SQL\Mapper($f3->get('DB'), 'MEAL');
     $selectIds = $f3->get('POST.selectId');
     $redirect = $f3->get("POST.destination");
     if (isset($selectIds)) {
         foreach ($selectIds as $meal) {
             $orm->load(array('id = ?', $meal));
             if (!$orm->dry()) {
                 $orm->erase();
             }
             $orm->reset();
         }
         AlertControl::message_info("Valitut annokset on poistettu");
         $f3->reroute($redirect);
     }
     $menuId = $f3->get('POST.menuId');
     $id = $f3->get('PARAMS.id');
     $orm->load(array('id=?', $id));
     $meal_name = $orm->name;
     $orm->erase();
     AlertControl::message_info("Annos {$meal_name} on poistettu");
     $f3->reroute("/menu/{$menuId}");
 }
Ejemplo n.º 10
0
 public function saveStoryChanges(\DB\SQL\Mapper $current, array $post)
 {
     // Step one: save the plain data
     $current->title = $post['story_title'];
     $current->summary = str_replace("\n", "<br />", $post['story_summary']);
     $current->storynotes = str_replace("\n", "<br />", $post['story_notes']);
     $current->ratingid = $post['ratingid'];
     $current->completed = $post['completed'];
     $current->validated = $post['validated'];
     $current->save();
     // Step two: check for changes in relation tables
     // Check tags:
     $post['tags'] = explode(",", $post['tags']);
     $tags = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_tags');
     foreach ($tags->find(array('`sid` = ? AND `character` = ?', $current->sid, 0)) as $X) {
         $temp = array_search($X['tid'], $post['tags']);
         if ($temp === FALSE) {
             // Excess relation, drop from table
             $tags->erase(['lid=?', $X['lid']]);
         } else {
             unset($post['tags'][$temp]);
         }
     }
     // Insert any tag IDs not already present
     if (sizeof($post['tags']) > 0) {
         foreach ($post['tags'] as $temp) {
             // Add relation to table
             $tags->reset();
             $tags->sid = $current->sid;
             $tags->tid = $temp;
             $tags->character = 0;
             $tags->save();
         }
     }
     unset($tags);
     // Check Characters:
     $post['characters'] = explode(",", $post['characters']);
     $characters = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_tags');
     foreach ($characters->find(array('`sid` = ? AND `character` = ?', $current->sid, 1)) as $X) {
         $temp = array_search($X['tid'], $post['characters']);
         if ($temp === FALSE) {
             // Excess relation, drop from table
             $characters->erase(['lid=?', $X['lid']]);
         } else {
             unset($post['characters'][$temp]);
         }
     }
     // Insert any character IDs not already present
     if (sizeof($post['characters']) > 0) {
         foreach ($post['characters'] as $temp) {
             // Add relation to table
             $characters->reset();
             $characters->sid = $current->sid;
             $characters->tid = $temp;
             $characters->character = 1;
             $characters->save();
         }
     }
     unset($characters);
     // Check Categories:
     $post['category'] = explode(",", $post['category']);
     $categories = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_categories');
     foreach ($categories->find(array('`sid` = ?', $current->sid)) as $X) {
         $temp = array_search($X['cid'], $post['category']);
         if ($temp === FALSE) {
             // Excess relation, drop from table
             $categories->erase(['lid=?', $X['lid']]);
         } else {
             unset($post['category'][$temp]);
         }
     }
     // Insert any character IDs not already present
     if (sizeof($post['category']) > 0) {
         foreach ($post['category'] as $temp) {
             // Add relation to table
             $categories->reset();
             $categories->sid = $current->sid;
             $categories->cid = $temp;
             $categories->save();
         }
     }
     unset($categories);
     // Author and co-Author preparation:
     $post['author'] = explode(",", $post['author']);
     $post['coauthor'] = explode(",", $post['coauthor']);
     // remove co-authors, that are already in the author field
     $post['coauthor'] = array_diff($post['coauthor'], $post['author']);
     // Check Authors:
     $author = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_authors');
     foreach ($author->find(array('`sid` = ? AND `ca` = ?', $current->sid, 0)) as $X) {
         $temp = array_search($X['aid'], $post['author']);
         if ($temp === FALSE) {
             // Excess relation, drop from table
             $author->erase(['lid=?', $X['lid']]);
         } else {
             unset($post['author'][$temp]);
         }
     }
     // Insert any character IDs not already present
     if (sizeof($post['author']) > 0) {
         foreach ($post['author'] as $temp) {
             // Add relation to table
             $author->reset();
             $author->sid = $current->sid;
             $author->aid = $temp;
             $author->ca = 0;
             $author->save();
         }
     }
     unset($author);
     // Check co-Authors:
     $coauthor = new \DB\SQL\Mapper($this->db, $this->prefix . 'stories_authors');
     foreach ($coauthor->find(array('`sid` = ? AND `ca` = ?', $current->sid, 1)) as $X) {
         $temp = array_search($X['aid'], $post['coauthor']);
         if ($temp === FALSE) {
             // Excess relation, drop from table
             $coauthor->erase(['lid=?', $X['lid']]);
         } else {
             unset($post['coauthor'][$temp]);
         }
     }
     // Insert any character IDs not already present
     if (sizeof($post['coauthor']) > 0) {
         foreach ($post['coauthor'] as $temp) {
             // Add relation to table
             $coauthor->reset();
             $coauthor->sid = $current->sid;
             $coauthor->aid = $temp;
             $coauthor->ca = 1;
             $coauthor->save();
         }
     }
     unset($coauthor);
     $this->rebuildStoryCache($current->sid);
     return TRUE;
 }