Esempio n. 1
0
    /**
     * Insert object into DB based on previously recorded changes.
     *
     * @return boolean true on success
     */
    function dbinsert()
    {
        global $DB;
        if ($this->ID != 0) {
            die('Existing object cannot be inserted!');
        }
        $DB->begin();
        if (Chapter::urlname_exists($this->urlname)) {
            // We gotta find another name:
            $sql = 'SELECT cat_urlname
								FROM T_categories
							 WHERE cat_urlname REGEXP "^' . $this->urlname . '(-[0-9]+)?$"';
            $highest_number = 0;
            foreach ($DB->get_results($sql) as $row) {
                if (preg_match('/-([0-9]+)$/', $row->cat_urlname, $matches)) {
                    // This one has a number, we extract it:
                    $existing_number = (int) $matches[1];
                    if ($existing_number > $highest_number) {
                        // This is the new high
                        $highest_number = $existing_number;
                    }
                }
            }
            $this->set('urlname', $this->urlname . '-' . ($highest_number + 1));
        }
        $r = parent::dbinsert();
        $DB->commit();
        return $r;
    }
Esempio n. 2
0
 /**
  * Insert object into DB based on previously recorded changes.
  *
  * @return boolean true on success
  */
 function dbinsert()
 {
     global $DB;
     load_funcs('items/model/_item.funcs.php');
     if ($this->ID != 0) {
         die('Existing object cannot be inserted!');
     }
     // Start transaction because of urltitle validation
     $DB->begin('SERIALIZABLE');
     // validate url title / slug
     $this->set('urlname', urltitle_validate($this->urlname, $this->name, $this->ID, false, $this->dbprefix . 'urlname', $this->dbIDname, $this->dbtablename));
     if (parent::dbinsert()) {
         // The chapter was inserted successful
         $DB->commit();
         return true;
     }
     // Could not insert the chapter object
     $DB->rollback();
     return false;
 }