Exemplo n.º 1
0
 /**
  * Insert new item in test mode, Use this function only in test tool to create very much items at one time
  *
  * @return boolean true on success
  */
 function dbinsert_test()
 {
     global $DB, $localtimenow;
     $this->set_param('last_touched_ts', 'date', date('Y-m-d H:i:s', $localtimenow));
     $DB->begin('SERIALIZABLE');
     if ($result = parent::dbinsert()) {
         // We could insert the item object..
         if (!is_null($this->extra_cat_IDs)) {
             // Insert new extracats:
             $query = 'INSERT INTO T_postcats ( postcat_post_ID, postcat_cat_ID ) VALUES ';
             foreach ($this->extra_cat_IDs as $extra_cat_ID) {
                 $query .= '( ' . $this->ID . ', ' . $extra_cat_ID . ' ),';
             }
             $query = substr($query, 0, strlen($query) - 1);
             $DB->query($query, 'insert new extracats');
         }
         // Create canonical slug with urltitle
         $canonical_Slug = new Slug();
         $canonical_Slug->set('title', $this->urltitle);
         $canonical_Slug->set('type', 'item');
         $canonical_Slug->set('itm_ID', $this->ID);
         // Create tiny slug:
         $tiny_Slug = new Slug();
         load_funcs('slugs/model/_slug.funcs.php');
         $tinyurl = getnext_tinyurl();
         $tiny_Slug->set('title', $tinyurl);
         $tiny_Slug->set('type', 'item');
         $tiny_Slug->set('itm_ID', $this->ID);
         if ($result = $canonical_Slug->dbinsert() && $tiny_Slug->dbinsert()) {
             $this->set('canonical_slug_ID', $canonical_Slug->ID);
             $this->set('tiny_slug_ID', $tiny_Slug->ID);
             if ($result = parent::dbupdate()) {
                 // save the last tinyurl
                 global $Settings;
                 $Settings->set('tinyurl', $tinyurl);
                 $Settings->dbupdate();
             }
         }
     }
     if ($result) {
         // The post and all related object was successfully created
         $DB->commit();
     } else {
         // Some error occured the transaction needs to be rollbacked
         $DB->rollback();
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Insert object into DB based on previously recorded changes
  *
  * @return boolean true on success
  */
 function dbinsert()
 {
     global $DB, $current_User, $Plugins;
     $DB->begin();
     if (empty($this->creator_user_ID)) {
         // No creator assigned yet, use current user:
         $this->set_creator_User($current_User);
     }
     // validate url title
     $this->set('urltitle', urltitle_validate($this->urltitle, $this->title, 0, false, $this->dbprefix, $this->dbIDname, $this->dbtablename));
     $this->update_renderers_from_Plugins();
     // TODO: allow a plugin to cancel update here (by returning false)?
     $Plugins->trigger_event('PrependItemInsertTransact', $params = array('Item' => &$this));
     $dbchanges = $this->dbchanges;
     // we'll save this for passing it to the plugin hook
     if ($result = parent::dbinsert()) {
         // We could insert the item object..
         // Let's handle the extracats:
         $this->insert_update_extracats('insert');
         // Let's handle the tags:
         $this->insert_update_tags('insert');
         $DB->commit();
         $Plugins->trigger_event('AfterItemInsert', $params = array('Item' => &$this, 'dbchanges' => $dbchanges));
     } else {
         $DB->rollback();
     }
     return $result;
 }