Author Topic: Adressbook - erase contacts from database instead of FLAG del  (Read 3834 times)

Offline chichi

  • Jr. Member
  • **
  • Posts: 33
Adressbook - erase contacts from database instead of FLAG del
« on: December 06, 2010, 10:40:20 AM »
Hello, I use .04 and the adressbook is a great tool.

improvements:
I want the to erase contacts from database instead of placing a field with FLAG del. Sometimes its better to delete them instead of holding deleted contacts in the database.

one more Bug: I made a subfolder in the addressbook and placed 260 contacts. I can view the first 200. When I try to view 201 - 260 the link jumps into the main folder and shows all contacts instead of the selected ones.

Thanks for improving this excellent Mail-system! I love it! chichi

Offline jolic

  • Jr. Member
  • **
  • Posts: 24
Re: Adressbook - erase contacts from database instead of FLAG del
« Reply #1 on: June 19, 2016, 02:06:33 PM »
I want to erase contacts from database instead of placing a field with FLAG del

Hi, I'm searching a solution for that and use these old thread (I use RC 1.2.0).
My database grows and grows. Some users import a lot datas with pictures and delete that, import again and so on.
Maybe I've overlooked it, but I can't find any information or a solution for this issue.
A crontab weekly to delete the flagged data record could be possible, but I prefer an immediate deletion.
Therefore here my 'quick and dirty' solution without guarantee! Maybe someone knows a better solution?

Code: [Select]
<?php
#~/program/lib/Roundcube/rcube_contacts.php
# I don't want flag records as deleted
# I exclude UPDATE with a hash (#) and DELETE the data record in the 3 functions: delete, delete_all and delete_group
# this is a 'quick and dirty' solution for RC 1.2.0 without guarantee!


    /**
     * Mark one or more contact records as deleted
     *
     * @param array   $ids   Record identifiers
     * @param boolean $force Remove record(s) irreversible (unsupported)
     */
    
function delete($ids$force true)
    {
        if (!
is_array($ids)) {
            
$ids explode(self::SEPARATOR$ids);
        }

        
$ids $this->db->array2list($ids'integer');

        
// flag record as deleted (always)
        
$this->db->query(
            
#"UPDATE " . $this->db->table_name($this->db_name, true).
            #" SET `del` = 1, `changed` = ".$this->db->now().
            
"DELETE FROM " $this->db->table_name($this->db_nametrue).
            
" WHERE `user_id` = ?".
                
" AND `contact_id` IN ($ids)",
            
$this->user_id
        
);

        
$this->cache null;

        return 
$this->db->affected_rows();
    }



    
/**
     * Remove all records from the database
     *
     * @param bool $with_groups Remove also groups
     *
     * @return int Number of removed records
     */
    
function delete_all($with_groups false)
    {
        
$this->cache null;

        
$now $this->db->now();

        
#$this->db->query("UPDATE " . $this->db->table_name($this->db_name, true)
        #    . " SET `del` = 1, `changed` = $now"
        
$this->db->query("DELETE FROM " $this->db->table_name($this->db_nametrue)   
            . 
" WHERE `user_id` = ?"$this->user_id);

        
$count $this->db->affected_rows();

        if (
$with_groups) {
            
#$this->db->query("UPDATE " . $this->db->table_name($this->db_groups, true)
            #    . " SET `del` = 1, `changed` = $now"
            
$this->db->query("DELETE FROM " $this->db->table_name($this->db_groupstrue)
                . 
" WHERE `user_id` = ?"$this->user_id);

            
$count += $this->db->affected_rows();
        }

        return 
$count;
    }



    
/**
     * Delete the given group (and all linked group members)
     *
     * @param string $gid Group identifier
     *
     * @return boolean True on success, false if no data was changed
     */
    
function delete_group($gid)
    {
        
// flag group record as deleted
        
$this->db->query(
            
#"UPDATE " . $this->db->table_name($this->db_groups, true)
            #. " SET `del` = 1, `changed` = " . $this->db->now()            
            
"DELETE FROM " $this->db->table_name($this->db_groupstrue)
            . 
" WHERE `contactgroup_id` = ?"
                
" AND `user_id` = ?",
            
$gid$this->user_id
        
);

        
$this->cache null;

        return 
$this->db->affected_rows();
    }
« Last Edit: June 19, 2016, 02:48:38 PM by jolic »

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,882
    • SKaero - Custom Roundcube development
Re: Adressbook - erase contacts from database instead of FLAG del
« Reply #2 on: June 19, 2016, 02:28:32 PM »
The no modification way would be to run <RC root>/bin/cleandb.sh this wouldn't do immediate deletion but could be run in a cron monthly, weekly, hourly, etc.

Offline jolic

  • Jr. Member
  • **
  • Posts: 24
Re: Adressbook - erase contacts from database instead of FLAG del
« Reply #3 on: June 19, 2016, 02:36:36 PM »
Thanks for your information.
Yes that's probably still better, especially after an update.