Beispiel #1
0
 private function ipIsAlreadyRegistered($ip, $gaddress)
 {
     $faucet = new DB\SQL\Mapper($this->db, 'faucet');
     $faucet->load(array('user_ip=?', $ip));
     if ($faucet->user_ip == null) {
         $faucet->load(array('gaddress=?', $gaddress));
         if ($faucet->gaddress == null) {
             $faucet->user_ip = $ip;
             $faucet->gaddress = $gaddress;
             $faucet->save();
             return false;
         }
     }
     return true;
 }
function recommendations_cache($job, $step)
{
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $limit = 50;
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    if ($step['success'] == 0) {
        $total = $fw->db5->exec("SELECT COUNT(*) as found FROM `{$new}recommendations`;")[0]['found'];
        $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 1, `total` = :total WHERE `id` = :id ", [':total' => $total, ':id' => $step['id']]);
    }
    $dataIn = $fw->db5->exec("SELECT SELECT_OUTER.recid,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT tid,',',tag,',',description ORDER BY `order`,tgid,tag ASC SEPARATOR '||') AS tagblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT charid,',',charname ORDER BY charname ASC SEPARATOR '||') AS characterblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT cid,',',category ORDER BY category ASC SEPARATOR '||' ) as categoryblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT ratingid,',',rating_name,',',rating_image SEPARATOR '||' ) as rating\r\n\t\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\tSELECT R.recid,\r\n\t\t\t\t\t\t\t\t\t\tR.ratingid, Ra.rating as rating_name, IF(Ra.rating_image,Ra.rating_image,'') as rating_image,\r\n\t\t\t\t\t\t\t\t\t\tCat.cid, Cat.category,\r\n\t\t\t\t\t\t\t\t\t\tTG.description,TG.order,TG.tgid,T.label as tag,T.tid,\r\n\t\t\t\t\t\t\t\t\t\tCh.charid, Ch.charname\r\n\t\t\t\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\tSELECT R1.*\r\n\t\t\t\t\t\t\t\t\t\t\tFROM `{$new}recommendations` R1\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE R1.cache_tags IS NULL\r\n\t\t\t\t\t\t\t\t\t\t\tLIMIT 0,{$limit}\r\n\t\t\t\t\t\t\t\t\t\t) AS R\r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}ratings` Ra ON ( Ra.rid = R.ratingid )\r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}recommendation_relations`rRT ON ( rRT.recid = R.recid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tags` T ON ( T.tid = rRT.relid AND rRT.type='T' )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tag_groups` TG ON ( TG.tgid = T.tgid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}characters` Ch ON ( Ch.charid = rRT.relid AND rRT.type = 'CH' )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}categories` Cat ON ( Cat.cid = rRT.relid AND rRT.type = 'CA' )\r\n\t\t\t\t\t\t\t\t)AS SELECT_OUTER\r\n\t\t\t\t\t\t\t\tGROUP BY recid ORDER BY recid ASC;");
    if (0 < ($count = sizeof($dataIn))) {
        foreach ($dataIn as $item) {
            $fw->db5->exec("UPDATE `{$new}recommendations` SET \r\n\t\t\t\t\t`cache_tags`\t\t= :tagblock,\r\n\t\t\t\t\t`cache_characters`\t= :characterblock,\r\n\t\t\t\t\t`cache_categories`\t= :categoryblock,\r\n\t\t\t\t\t`cache_rating`\t\t= :rating\r\n\t\t\t\tWHERE recid = {$item['recid']} ;", [':tagblock' => json_encode(upgradetools::cleanResult($item['tagblock'])), ':characterblock' => json_encode(upgradetools::cleanResult($item['characterblock'])), ':categoryblock' => json_encode(upgradetools::cleanResult($item['categoryblock'])), ':rating' => json_encode(explode(",", $item['rating']))]);
        }
        $tracking->items = $tracking->items + $count;
        $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();
    }
}
Beispiel #3
0
 public function userSession($uid)
 {
     $session = new \DB\SQL\Mapper($this->db, $this->prefix . "sessions");
     $session->load(array('session=?', $_SESSION['session_id']));
     $session->user = $uid;
     $session->save();
 }
Beispiel #4
0
function series_cache($job, $step)
{
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $limit = 20;
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    if ($step['success'] == 0) {
        $total = $fw->db5->exec("SELECT COUNT(*) as found FROM `{$new}series`;")[0]['found'];
        $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 1, `total` = :total WHERE `id` = :id ", [':total' => $total, ':id' => $step['id']]);
    }
    $dataIn = $fw->db5->exec("SELECT \r\n\t\t\t\t\t\t\t\tSERIES.seriesid, \r\n\t\t\t\t\t\t\t\tSERIES.tagblock, \r\n\t\t\t\t\t\t\t\tSERIES.characterblock, \r\n\t\t\t\t\t\t\t\tSERIES.authorblock, \r\n\t\t\t\t\t\t\t\tSERIES.categoryblock, \r\n\t\t\t\t\t\t\t\tCONCAT(rating,'||',max_rating_id) as max_rating\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\tSELECT \r\n\t\t\t\t\t\t\tSer.seriesid,\r\n\t\t\t\t\t\t\tMAX(Ra.rid) as max_rating_id,\r\n\t\t\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT U.uid,',',U.nickname ORDER BY nickname ASC SEPARATOR '||' ) as authorblock,\r\n\t\t\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT Chara.charid,',',Chara.charname ORDER BY charname ASC SEPARATOR '||') AS characterblock,\r\n\t\t\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT C.cid,',',C.category ORDER BY category ASC SEPARATOR '||' ) as categoryblock,\r\n\t\t\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT T.tid,',',T.label,',',TG.description ORDER BY TG.order,TG.tgid,T.label ASC SEPARATOR '||') AS tagblock\r\n\t\t\t\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT Ser1.seriesid\r\n\t\t\t\t\t\t\t\t\t\t\tFROM `{$new}series`Ser1\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE Ser1.cache_authors IS NULL\r\n\t\t\t\t\t\t\t\t\t\t\tLIMIT 0,{$limit}\r\n\t\t\t\t\t\t\t\t\t) AS Ser\r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}series_stories`TrS ON ( Ser.seriesid = TrS.seriesid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories`S ON ( TrS.sid = S.sid )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}ratings`Ra ON ( Ra.rid = S.ratingid )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories_tags`rST ON ( rST.sid = S.sid )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tags`T ON ( T.tid = rST.tid AND rST.character = 0 )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tag_groups`TG ON ( TG.tgid = T.tgid )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}characters`Chara ON ( Chara.charid = rST.tid AND rST.character = 1 )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories_categories`rSC ON ( rSC.sid = S.sid )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}categories`C ON ( rSC.cid = C.cid )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories_authors`rSA ON ( rSA.sid = S.sid )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}users` U ON ( rSA.aid = U.uid )\r\n\t\t\t\t\t\t\t\t\tGROUP BY Ser.seriesid\r\n\t\t\t\t\t\t\t) AS SERIES\r\n\t\t\t\t\t\t\tLEFT JOIN `{$new}ratings`R ON (R.rid = max_rating_id);");
    if (0 < ($count = sizeof($dataIn))) {
        foreach ($dataIn as $item) {
            $fw->db5->exec("UPDATE `{$new}series` SET \r\n\t\t\t\t\t\t`cache_authors`\t\t= :authorblock,\r\n\t\t\t\t\t\t`cache_tags`\t\t= :tagblock,\r\n\t\t\t\t\t\t`cache_characters`\t= :characterblock,\r\n\t\t\t\t\t\t`cache_categories`\t= :categoryblock,\r\n\t\t\t\t\t\t`max_rating`\t\t= :max_rating\r\n\t\t\t\t\tWHERE seriesid = {$item['seriesid']} ;", [':authorblock' => json_encode(upgradetools::cleanResult($item['authorblock'])), ':tagblock' => json_encode(upgradetools::cleanResult($item['tagblock'])), ':characterblock' => json_encode(upgradetools::cleanResult($item['characterblock'])), ':categoryblock' => json_encode(upgradetools::cleanResult($item['categoryblock'])), ':max_rating' => json_encode(explode(",", $item['max_rating']))]);
        }
        $tracking->items = $tracking->items + $count;
        $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();
    }
}
Beispiel #5
0
 public function cacheCategories($catID = 0)
 {
     // clear stats of affected categories
     $sql = "UPDATE `tbl_categories` SET `stats` = NULL";
     if ($catID > 0) {
         $sql .= " WHERE `cid` = {$catID};";
     }
     $this->exec($sql);
     $categories = new \DB\SQL\Mapper($this->db, $this->prefix . 'categories');
     $sql = "SELECT C.cid, C.category, COUNT(DISTINCT S.sid) as counted, \r\n\t\t\t\t\tGROUP_CONCAT(DISTINCT C1.category SEPARATOR '||' ) as sub_categories, \r\n\t\t\t\t\tGROUP_CONCAT(DISTINCT C1.stats SEPARATOR '||' ) as sub_stats\r\n\t\t\tFROM `tbl_categories`C \r\n\t\t\t\tINNER JOIN (SELECT leveldown FROM `tbl_categories` WHERE `stats` = '' ORDER BY leveldown DESC LIMIT 0,1) c2 ON ( C.leveldown = c2.leveldown )\r\n\t\t\t\tLEFT JOIN `tbl_stories_categories`SC ON ( C.cid = SC.cid )\r\n\t\t\t\tLEFT JOIN `tbl_stories`S ON ( S.sid = SC.sid )\r\n\t\t\t\tLEFT JOIN `tbl_categories`C1 ON ( C.cid = C1.parent_cid )\r\n\t\t\tGROUP BY C.cid";
     do {
         $items = $this->exec($sql);
         $change = FALSE;
         foreach ($items as $item) {
             if ($item['sub_categories'] == NULL) {
                 $sub = NULL;
             } else {
                 $sub_categories = explode("||", $item['sub_categories']);
                 $sub_stats = explode("||", $item['sub_stats']);
                 $sub_stats = array_map("json_decode", $sub_stats);
                 foreach ($sub_categories as $key => $value) {
                     $item['counted'] += $sub_stats[$key]->count;
                     $sub[$value] = $sub_stats[$key]->count;
                 }
             }
             $stats = json_encode(["count" => (int) $item['counted'], "cid" => $item['cid'], "sub" => $sub]);
             unset($sub);
             $categories->load(array('cid=?', $item['cid']));
             $categories->stats = $stats;
             $categories->save();
             $change = $change ?: $categories->changed();
         }
     } while ($change != FALSE);
 }
Beispiel #6
0
function contests_cache($job, $step)
{
    $fw = \Base::instance();
    $new = "{$fw['installerCFG.db5.dbname']}`.`{$fw['installerCFG.db5.prefix']}";
    $limit = 50;
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    if ($step['success'] == 0) {
        $total = $fw->db5->exec("SELECT COUNT(*) as found FROM `{$new}contests`;")[0]['found'];
        $fw->db5->exec("UPDATE `{$new}convert`SET `success` = 1, `total` = :total WHERE `id` = :id ", [':total' => $total, ':id' => $step['id']]);
    }
    $dataIn = $fw->db5->exec("SELECT \r\n\t\t\t\t\t\t\t\tCon.conid,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT S.sid,',',S.title,',',U.uid,',',U.nickname ORDER BY charname ASC SEPARATOR '||') AS storyblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT Chara.charid,',',Chara.charname ORDER BY charname ASC SEPARATOR '||') AS characterblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT C.cid,',',C.category ORDER BY category ASC SEPARATOR '||' ) as categoryblock,\r\n\t\t\t\t\t\t\t\tGROUP_CONCAT(DISTINCT T.tid,',',T.label,',',TG.description ORDER BY TG.order,TG.tgid,T.label ASC SEPARATOR '||') AS tagblock\r\n\t\t\t\t\t\t\t\t\tFROM \r\n\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\tSELECT Con1.conid\r\n\t\t\t\t\t\t\t\t\t\t\tFROM `{$new}contests`Con1\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE Con1.cache_tags IS NULL\r\n\t\t\t\t\t\t\t\t\t\t\tLIMIT 0,{$limit}\r\n\t\t\t\t\t\t\t\t\t) AS Con\r\n\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}contest_relations`rC ON ( rC.conid = Con.conid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories`S ON ( S.sid = rC.relid and rC.type='ST' )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}stories_authors`rSA ON ( rSA.sid = S.sid )\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}users`U ON ( U.uid = rSA.aid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tags`T ON ( T.tid = rC.relid AND rC.type = 'T' )\r\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}tag_groups`TG ON ( TG.tgid = T.tgid )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}characters`Chara ON ( Chara.charid = rC.relid AND rC.type = 'CH' )\r\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN `{$new}categories`C ON ( C.cid = rC.relid AND rC.type = 'CA' )\r\n\t\t\t\t\t\t\t\t\tGROUP BY Con.conid;");
    if (0 < ($count = sizeof($dataIn))) {
        foreach ($dataIn as $item) {
            $fw->db5->exec("UPDATE `{$new}contests` SET \r\n\t\t\t\t\t\t`cache_stories`\t\t= :storyblock,\r\n\t\t\t\t\t\t`cache_tags`\t\t= :tagblock,\r\n\t\t\t\t\t\t`cache_characters`\t= :characterblock,\r\n\t\t\t\t\t\t`cache_categories`\t= :categoryblock\r\n\t\t\t\t\tWHERE conid = {$item['conid']} ;", [':storyblock' => json_encode(upgradetools::cleanResult($item['storyblock'])), ':tagblock' => json_encode(upgradetools::cleanResult($item['tagblock'])), ':characterblock' => json_encode(upgradetools::cleanResult($item['characterblock'])), ':categoryblock' => json_encode(upgradetools::cleanResult($item['categoryblock']))]);
        }
        $tracking->items = $tracking->items + $count;
        $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();
    }
}
Beispiel #7
0
 /**
  * Load by ID directly if a number is passed
  * @param  string|array  $filter
  * @param  array         $options
  * @param  integer       $ttl
  * @return mixed
  */
 function load($filter = NULL, array $options = NULL, $ttl = 0)
 {
     if (is_numeric($filter)) {
         return parent::load(array("id = ?", $filter), $options, $ttl);
     } elseif (is_array($filter)) {
         return parent::load($filter, $options, $ttl);
     }
     throw new \Exception('$filter must be an int or array');
 }
Beispiel #8
0
 function photo_delete()
 {
     $return = "done";
     $ID = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : "";
     $art = new \DB\SQL\Mapper($this->f3->get("DB"), "dir_items_photos");
     $art->load("ID='{$ID}'");
     $art->erase();
     return $GLOBALS["output"]['data'] = $return;
 }
 function GetDbMapperInstance($table)
 {
     $id = $this->f3->get('REQUEST.id');
     $result = new DB\SQL\Mapper($this->f3->get('DB'), $table);
     if ($id) {
         $result->load(array('id=?', $id));
     }
     return $result;
 }
Beispiel #10
0
 public function update($table, $data, $where)
 {
     $handle = new \DB\SQL\Mapper($this->db, str_replace("tbl_", $this->prefix, $table));
     $handle->load($where);
     foreach ($data as $key => $value) {
         $handle->{$key} = $value;
     }
     $handle->save();
     unset($handle);
 }
Beispiel #11
0
 public function save()
 {
     $v = new DB\SQL\Mapper(Events::$db, 'venues');
     if ($this->id) {
         $v->load('id=' . $this->id);
     }
     $v->name = $this->name;
     $v->address = $this->address;
     $v->postcode = $this->postcode;
     $v->info = $this->info;
     $v->save();
 }
Beispiel #12
0
 function edit($f3)
 {
     $video = new DB\SQL\Mapper($f3->get('db'), 'videos');
     $video->load(array('id=?', $f3->get('PARAMS.videoID')));
     if ($f3->get('POST.delete') == '1') {
         $video->erase();
     } else {
         $video->startTime = $f3->get('POST.startTime');
         $video->endTime = $f3->get('POST.endTime');
         $video->save();
     }
     $f3->reroute('@channelList');
 }
Beispiel #13
0
 static function get_menus()
 {
     $db = new DB\SQL('mysql:host=localhost;dbname=MealDB', 'root', '');
     $menuInst = new DB\SQL\Mapper($db, "MENU");
     $menus = array();
     $menuInst->load('');
     while (!$menuInst->dry()) {
         $id = $menuInst->id;
         $name = $menuInst->name;
         $menus[$id] = $name;
         $menuInst->next();
     }
     return $menus;
 }
Beispiel #14
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;
 }
Beispiel #15
0
 public function newsletter()
 {
     $f3 = \Base::instance();
     $db = $f3->get('DB.instance');
     // Getting info about request, $org = organisation, $nId = newsletter id.
     $org = $f3->get('PARAMS.org');
     $nId = (int) $f3->get('PARAMS.nId');
     $nmap = new \DB\SQL\Mapper($db, 'newsletters');
     $omap = new \DB\SQL\Mapper($db, 'organisations');
     if ($omap->load(array('id=? OR cname=?', $org, $org))) {
         // Organisation exists
         if ($nmap->load(array('id=? AND orgId=?', $nId, $omap->id))) {
             $nmap->views++;
             $nmap->save();
             // Render
             $f3->set('v_org', $omap);
             $f3->set('v_let', $nmap);
             $this->_render('public/newsletter.html');
         } else {
             /*
              * Newsletter does not exists
              *
              * Render a page that says so, and lists other newsletters made by the same company.
              */
             $f3->set('v_org', $nmap);
             $lastNews = $nmap->find(array('orgId=?', $omap->id));
             $f3->set('v_lastNews', $lastNews);
             $this->_render('public/newsletter_notfound.html');
         }
     } else {
         /*
          * Organisation does not exists, error page
          */
         $this->_render('public/organisation_notfound.html');
     }
 }
Beispiel #16
0
 function lookup($ID, $table)
 {
     $art = new \DB\SQL\Mapper($this->f3->get("DB"), $table);
     $art->load("ID ='{$ID}'");
     return $art;
 }
Beispiel #17
0
function various_poll_votes($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 = 50;
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    if ($step['success'] == 0) {
        try {
            $total = $fw->db3->exec("SELECT COUNT(*) as found FROM `{$old}poll_votes`;")[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 `vote_id`, `vote_user`, `vote_opt`, `vote_poll`\r\n\t\t\t\t\t\t\t\tFROM `{$old}poll_votes` \r\n\t\t\t\t\t\t\t\tORDER BY `vote_id` ASC LIMIT {$step['items']},{$limit};");
    if (0 < ($count = sizeof($dataIn))) {
        foreach ($dataIn as $data) {
            $values[] = "( '{$data['vote_id']}', \r\n\t\t\t\t\t\t\t'{$data['vote_user']}',\r\n\t\t\t\t\t\t\t'{$data['vote_opt']}',\r\n\t\t\t\t\t\t\t'{$data['vote_poll']}' )";
        }
        $fw->db5->exec("INSERT INTO `{$new}poll_votes` (`vote_id`, `poll_id`, `uid`, `option`) VALUES " . implode(", ", $values) . "; ");
        $count = $fw->db5->count();
        $tracking->items = $tracking->items + $count;
        $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();
    }
}
Beispiel #18
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();
    }
}
Beispiel #19
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'));
     }
     $r1 = $table->getCols(true);
     foreach (array_keys($schema->dataTypes) as $index => $field) {
         if (isset($r1['column_' . $index])) {
             $datType = $schema->findQuery($schema->dataTypes[$field]);
             $compatible = $schema->isCompatible($field, $r1['column_' . $index]['type']);
             $this->test->expect($compatible, $this->getTestDesc('reverse lookup compatible: ' . ($compatible ? 'YES' : 'NO') . ', ' . $field . ': [' . $datType . ' > ' . $r1['column_' . $index]['type'] . ']'));
         }
     }
     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'));
     $mapper = new \DB\SQL\Mapper($db, $this->tname);
     $mapper->load();
     $rec_count_cur = $mapper->loaded();
     $schema->truncateTable($this->tname);
     $mapper->reset();
     $mapper->load();
     $rec_count_new = $mapper->loaded();
     $this->test->expect($rec_count_cur == 3 && $rec_count_new == 0, $this->getTestDesc('truncate table'));
     $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);
     $text = preg_match('/sybase|dblib|odbc|sqlsrv/', $this->current_engine) ? 'nvarchar' : 'text';
     $this->test->expect(array_key_exists('bar', $r1) && $r1['bar']['type'] == $text, $this->getTestDesc('update column'));
     // update column
     $cols = $table->getCols(true);
     $bar = $cols['bar'];
     $col = new \DB\SQL\Column('bar', $table);
     $col->copyfrom($bar);
     $col->type_varchar(60);
     $col->defaults('great');
     $table->updateColumn('bar', $col);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(array_key_exists('bar', $r1) && $r1['bar']['default'] == 'great', $this->getTestDesc('update column and default'));
     // update column default only
     $cols = $table->getCols(true);
     $bar = $cols['bar'];
     $col = new \DB\SQL\Column('bar', $table);
     $col->copyfrom($bar);
     $col->passThrough();
     $col->defaults('');
     $table->updateColumn('bar', $col);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(array_key_exists('bar', $r1) && $r1['bar']['default'] == '', $this->getTestDesc('update default value'));
     $col->nullable(false);
     $table->updateColumn('bar', $col);
     $table->build();
     $r1 = $table->getCols(true);
     $this->test->expect(array_key_exists('bar', $r1) && $r1['bar']['nullable'] == false, $this->getTestDesc('update nullable flag'));
     // 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();
     // boolean fields are actually bit/tinyint
     $schema->dropTable($this->tname . '_notnullbool');
     $table2 = $schema->createTable($this->tname . '_notnullbool');
     $table2->addColumn('active')->type($schema::DT_BOOL)->nullable(false);
     $table2 = $table2->build();
     $r1 = $schema->getTables();
     $r2 = $table2->getCols(true);
     $this->test->expect(in_array($this->tname . '_notnullbool', $r1) && array_key_exists('active', $r2) && $r2['active']['nullable'] == false, $this->getTestDesc('create new table with not nullable boolean column'));
     $table2->addColumn('active2')->type($schema::DT_BOOL)->nullable(false)->defaults(0);
     $table2->addColumn('active3')->type($schema::DT_BOOL)->nullable(false)->defaults(1);
     $table2->build();
     $r1 = $schema->getTables();
     $r2 = $table2->getCols(true);
     $this->test->expect(in_array($this->tname . '_notnullbool', $r1) && array_key_exists('active2', $r2) && $r2['active2']['nullable'] == false && ((int) $r2['active2']['default'] == 0 || $r2['active2']['default'] == 'false') && array_key_exists('active3', $r2) && $r2['active3']['nullable'] == false && ((int) $r2['active3']['default'] == 1 || $r2['active3']['default'] == 'true'), $this->getTestDesc('add not nullable boolean columns with default to existing table'));
     $table2->drop();
 }
Beispiel #20
0
 static function remove($ID)
 {
     $timer = new timer();
     $f3 = \base::instance();
     //	test_array($values);
     $art = new \DB\SQL\Mapper($f3->get("DB"), "dir_users");
     $art->load("ID='{$ID}'");
     $art->erase();
     $timer->_stop(__NAMESPACE__, __CLASS__, __FUNCTION__, func_get_args());
     return "done";
 }
Beispiel #21
0
 public function libraryBookFavDelete($params)
 {
     if (empty($params['id'][0]) or empty($params['id'][1])) {
         return FALSE;
     }
     if (in_array($params["id"][0], ["AU", "RC", "SE", "ST"])) {
         $mapper = new \DB\SQL\Mapper($this->db, $this->prefix . 'user_favourites');
         $mapper->load(array("uid=? AND item=? AND type=? AND bookmark=?", $_SESSION['userID'], $params["id"][1], $params["id"][0], array_key_exists("bookmark", $params) ? 1 : 0));
         if (NULL !== ($fid = $mapper->get('fid'))) {
             $mapper->erase();
             return TRUE;
         }
         unset($mapper);
         return FALSE;
     }
 }
Beispiel #22
0
 function edit($f3)
 {
     $db = $f3->get('db');
     $channel = new DB\SQL\Mapper($db, 'channels');
     $channel->load(array('id=?', $f3->get('PARAMS.channelID')));
     // Delete Channel
     if ($f3->get('POST.delete') == '1') {
         $channel->erase();
         $db->exec('DELETE FROM videos WHERE channel=?', $f3->get('PARAMS.channelID'));
         $db->exec('DELETE FROM schedule WHERE channel=?', $f3->get('PARAMS.channelID'));
         $f3->reroute('@channelList');
         // Update Name
     } else {
         $channel->name = $f3->get('POST.name');
         $channel->live = $f3->get('POST.live');
         $channel->save();
         $f3->reroute('@channelList');
     }
 }
Beispiel #23
0
function feedback_news($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 = 500;
    $i = 0;
    //$newdata = new \DB\SQL\Mapper( $fw->db5, $fw['installerCFG.db5.prefix']."stories" );
    if ($step['success'] == 0) {
        $total = $fw->db3->exec("SELECT COUNT(*) as found FROM `{$old}comments`;")[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 C.nid, C.uid, C.comment, C.time FROM `{$old}comments`C LIMIT {$step['items']},{$limit};");
    $tracking = new DB\SQL\Mapper($fw->db5, $fw->get('installerCFG.db5.prefix') . 'convert');
    $tracking->load(['id = ?', $step['id']]);
    if (0 < ($count = sizeof($dataIn))) {
        /* this is slower, but requires no quoting. will keep the code in case need arises
        		foreach($dataIn as $data)
        		{
        			$i++;
        			$newdata->copyfrom($data);
        			$newdata->save();
        			$newdata->reset();
        
        			$tracking->items = $tracking->items+1;
        			$tracking->save();
        		}*/
        // build the insert values
        foreach ($dataIn as $data) {
            $values[] = "( '{$data['nid']}', '{$data['uid']}', {$fw->db5->quote($data['comment'])}, '{$data['time']}', 'C' )";
        }
        $fw->db5->exec("INSERT INTO `{$new}feedback` ( `reference`, `writer_uid`, `text`, `datetime`, `type` ) VALUES " . implode(", ", $values) . "; ");
        $count = $fw->db5->count();
        $tracking->items = $tracking->items + $count;
        $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();
    }
}
Beispiel #24
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}");
 }
Beispiel #25
0
 public function saveShout($id, array $data)
 {
     $shout = new \DB\SQL\Mapper($this->db, $this->prefix . 'shoutbox');
     $shout->load(array('id=?', $id));
     $shout->copyfrom(["message" => $data['message']]);
     $i = $shout->changed("message");
     $shout->save();
     return $i;
 }
$hauth_config = dirname(__FILE__) . '/hybridauth/config.php';
require dirname(__FILE__) . '/hybridauth/Hybrid/Auth.php';
$provider_name = $f3->get('PARAMS.action');
if (empty($provider_name)) {
    die("no provider");
}
// then grab the user profile
try {
    $hybridauth = new Hybrid_Auth($hauth_config);
    $adapter = $hybridauth->authenticate($provider_name);
    $user_profile = $adapter->getUserProfile();
    $_SESSION['logged_in'] = 'ok';
    $username = $user_profile->email;
    $f3->set('SESSION.logged_in', 'ok');
    $user = new DB\SQL\Mapper($db, 'memos');
    $user->load(array('email = :username LIMIT 0,1', ':username' => $username));
    if ($user->dry()) {
        $user->role = 'subscriber';
        $user->created = date('Y-m-d H:i:s');
        // Send email to Admin with the good news: a new user!
        $smtp = new SMTP(SMTP_SERVER, SMTP_PORT, SMTP_PROTOCOL, SMTP_USERNAME, SMTP_PASSWORD);
        $smtp->set('From', '"Do Not Forget Me" <' . ADMIN_EMAIL . '>');
        $smtp->set('To', '<' . ADMIN_EMAIL . '>');
        $smtp->set('Subject', 'Yay, New DNFM User : '******'Errors-to', '<' . ADMIN_EMAIL . '>');
        $message = "On " . date('Y-m-d at H:i') . ", a new user subscribed to Do Not Forget Me!";
        $message .= "\n\nname: " . $user_profile->displayName;
        $message .= "\nemail: " . $user_profile->email;
        $message .= "\n\n\nPop up the champaign!";
        $sent = $smtp->send($message, TRUE);
        $mylog = $smtp->log();
Beispiel #27
0
 public function save()
 {
     global $f3;
     $e = new DB\SQL\Mapper(Events::$db, 'events');
     $get_id = true;
     if ($this->id) {
         $e->load(array('id=?', $this->id));
         $get_id = false;
     }
     $e->id = $this->id;
     $e->title = $this->title;
     $e->startdt = $this->startdt->format("Y-m-d H:i");
     if ($this->enddt) {
         $e->enddt = $this->enddt->format("Y-m-d H:i");
     } else {
         $e->enddt = NULL;
     }
     $e->location_text = $this->location->dbname();
     $e->blurb = $this->blurb;
     $e->url = $this->url;
     $e->cost = $this->cost;
     if ($this->film) {
         $e->type = "film";
     }
     $e->host = $this->host;
     if (!$this->slug) {
         $setslug = true;
     } else {
         $e->slug = $this->slug;
     }
     $e->email = $this->email;
     $e->state = $this->state;
     $e->save();
     if ($get_id && $setslug) {
         $e->slug = $this->generateSlug();
         $e->save();
     }
 }
        $row = array('id' => $id, 'randomNumber' => $db->exec('SELECT randomNumber FROM World WHERE id = ?', $id, 0, false));
        $rnu = mt_rand(1, 10000);
        $row['randomNumber'] = $rnu;
        $db->exec('UPDATE World SET randomNumber = :ranNum WHERE id = :id', array(':ranNum' => $rnu, ':id' => $id), 0, false);
        $result[] = $row;
    }
    header("Content-type: application/json");
    echo json_encode($result);
});
$f3->route(array('GET /update-orm', 'GET /update-orm/@queries'), function ($f3, $params) {
    /** @var Base $f3 */
    $queries = 1;
    if (isset($params['queries'])) {
        $queries = (int) $params['queries'];
        $queries = $queries < 1 ? 1 : ($queries > 500 ? 500 : $queries);
    }
    $dbc = $f3->get('DBS');
    $db = new \DB\SQL($dbc[0], $dbc[1], $dbc[2], array(\PDO::ATTR_PERSISTENT => TRUE));
    $world = new \DB\SQL\Mapper($db, 'World');
    $result = array();
    for ($i = 0; $i < $queries; $i++) {
        $id = mt_rand(1, 10000);
        $world->load(array('id = ?', $id));
        $world->randomNumber = mt_rand(1, 10000);
        $world->save();
        $result[] = $world->cast();
    }
    header("Content-type: application/json");
    echo json_encode($result);
});
$f3->run();
Beispiel #29
0
		echo View::instance()->render('layout.htm');
	}
);
*/
$f3->route('POST /synchronise-memo', function ($f3) {
    global $db;
    // if user EMAIL matches user ID, update its memo
    $username = $f3->get('POST.email');
    $id = $f3->get('POST.id');
    $memo = $f3->get('POST.memo');
    $lastModified = $f3->get('POST.last_modified');
    if (empty($username)) {
        die("no user email sent.");
    }
    $user = new DB\SQL\Mapper($db, 'memos');
    $user->load(array('email = :username AND id= :id LIMIT 0,1', ':username' => $username, ':id' => $id));
    if ($user->dry()) {
        die("non existing user.");
    }
    if ($user->last_modified <= $lastModified) {
        // Save Data
        $memo = str_replace(array("\n", "\r", "\t"), '', $memo);
        $user->memo = json_encode($memo);
        $user->last_modified = $lastModified;
        $user->save();
        $result = array('last_modified' => $user->last_modified);
        $f3->set('SESSION.memo', stripslashes($user->memo));
    } else {
        // Send Data
        $result = array('memo' => $user->memo, 'last_modified' => $user->last_modified);
    }
Beispiel #30
0
$f3->config('config.ini');
$f3->set('DB', new \DB\SQL('sqlite:data/pastes.db'));
// force SSL
if ($f3->get('FORCE_SSL') && $f3->get('SCHEME') == 'http') {
    $f3->reroute(str_replace('http', 'https', $f3->get('REALM')));
}
// home
$f3->route('GET /', function (\Base $f3) {
    $f3->set('sub_tmpl', 'index.html');
    echo \Template::instance()->render('layout.html');
});
// view paste
$f3->route('GET @view: /view/@uuid', function (\Base $f3, $params) {
    $mapper = new \DB\SQL\Mapper($f3->get('DB'), $f3->get('db_table'));
    if ($f3->get('DELETE_ON_ACCESS')) {
        $mapper->load(array('uuid = ?', $params['uuid']));
    } else {
        // don't load deleted
        $mapper->load(array('uuid = ? and lifetime > ?', $params['uuid'], date('Y-m-d H:i:s')));
    }
    if ($mapper->dry()) {
        $f3->error(404, 'This document does not exist.');
    }
    // delete on access
    if ($f3->get('DELETE_ON_ACCESS') && strtotime($mapper->lifetime) <= time()) {
        $mapper->erase();
        $f3->error(404, 'This document does not exist.');
    }
    $f3->set('paste', $mapper);
    $f3->set('sub_tmpl', 'view.html');
    echo \Template::instance()->render('layout.html');