function commit()
 {
     //if the object is already in the db it is updated by the changes made to this object, otherwise a new db entry is made
     global $db, $config_vars;
     if (!isset($this->id)) {
         if ($this->is_serie === false) {
             $is_serie = 0;
         } else {
             $is_serie = 1;
         }
         // this is object is not yet in the datebase, make a new entry
         $sql = 'INSERT INTO ' . $config_vars['table_prefix'] . "cats (name, current_rating, parent_id, catgroup_id,is_serie,content_amount,description,child_content_amount,child_comments_amount)\n\t\t\t\tVALUES ('" . database_encode($this->name) . "', '{$this->current_rating}', '{$this->parent_id}', '{$this->catgroup_id}', '{$is_serie}', '{$this->content_amount}', '" . database_encode($this->description) . "', '{$this->child_content_amount}', '{$this->child_comments_amount}')";
         if (!($result = $db->sql_query($sql))) {
             $error = new phreak_error(E_WARNING, SQL_ERROR, __LINE__, __FILE__, 'commit', $this->id, 0, 0, $sql);
             $error->commit();
             // 				error_report(SQL_ERROR, 'commit' , __LINE__, __FILE__,$sql);
         }
         $this->id = $db->sql_nextid();
         return OP_SUCCESSFUL;
     } else {
         // object is already in the database just du an update
         $sql = 'UPDATE ' . $config_vars['table_prefix'] . "cats \n\t\t\t\tSET \tname = '" . database_encode($this->name) . "',\n\t\t\t\t\tcurrent_rating = '{$this->current_rating}', \n\t\t\t\t\tparent_id = '{$this->parent_id}', \n\t\t\t\t\tcatgroup_id = '{$this->catgroup_id}',\n\t\t\t\t\tis_serie = '{$this->is_serie}',\n\t\t\t\t\tcontent_amount = '{$this->content_amount}',\n\t\t\t\t\tdescription = '" . database_encode($this->description) . "',\n\t\t\t\t\tchild_content_amount = '{$this->child_content_amount}',\n\t\t\t\t\tchild_comments_amount = '{$this->child_comments_amount}'\n\t\t\t\tWHERE id like {$this->id}";
         if (!($result = $db->sql_query($sql))) {
             $error = new phreak_error(E_WARNING, SQL_ERROR, __LINE__, __FILE__, 'commit', $this->id, 0, 0, $sql);
             $error->commit();
             // 				error_report(SQL_ERROR, 'commmit' , __LINE__, __FILE__,$sql);
         }
         // recalc child content_amount
         if ($this->get_id() != $config_vars['root_categorie']) {
             $cat = new categorie();
             $cat->generate_from_id($this->get_parent_id());
             $cat->set_child_content_amount($cat->calc_child_content_amount());
             $cat->commit();
         }
         if (isset($this->commit_parent_cat)) {
             $this->commit_parent_cat->commit();
         }
         return OP_SUCCESSFUL;
     }
 }
Exemple #2
0
    $cat->generate_from_id($row['id']);
    $catarray[] = $cat;
}
foreach ($catarray as $cat) {
    // check how many content is in this cat
    $should_be = $cat->calc_content_amount();
    if ($should_be != $cat->get_content_amount()) {
        $missmatch['type'] = CONTENT_IN_CAT_AMOUNT;
        $missmatch['id'] = $cat->id;
        $missmatch['name'] = $cat->get_name();
        $missmatch['value'] = $cat->get_content_amount();
        $missmatch['should_be'] = $should_be;
        $missmatch_array[] = $missmatch;
    }
    // check child_content_amount
    $calc_child_content_amount = $cat->calc_child_content_amount();
    if ($calc_child_content_amount != $cat->get_child_content_amount()) {
        $missmatch['type'] = CHILD_CONTENT_IN_CAT_AMOUNT;
        $missmatch['id'] = $cat->id;
        $missmatch['name'] = $cat->get_name();
        $missmatch['value'] = $cat->get_child_content_amount();
        $missmatch['should_be'] = $calc_child_content_amount;
        $missmatch_array[] = $missmatch;
    }
    // check child comment amount
    $calc_child_comments_amount = $cat->calc_child_comments_amount();
    if ($calc_child_comments_amount != $cat->get_child_comments_amount()) {
        $missmatch['type'] = CHILD_COMMENTS_IN_CAT_AMOUNT;
        $missmatch['id'] = $cat->id;
        $missmatch['name'] = $cat->get_name();
        $missmatch['value'] = $cat->get_child_comments_amount();