Results 1 to 3 of 3

Thread: When a Document is deleted the file is NOT deleted (Bug ??)

  1. #1
    fulvio is offline Sugar Community Member
    Join Date
    Sep 2007
    Location
    Lesmo - MB
    Posts
    124

    Question When a Document is deleted the file is NOT deleted (Bug ??)

    Hi all,

    Sugar 5.5.0 CE
    Linux Debian Lenny
    Apache 2.2.9
    MySql 5.0.5
    PHP 5.2.6

    when a new Document is created, Sugar:
    - insert a new record into the documents table,
    - insert a new record into the document_revisions table
    - add the file into cache/upload
    But when I delete this Document, only the record into the documents
    table is marked "deleted", NOT into the document_revisions table, and
    the file into cache/upload is NOT deleted.
    Is this a bug ?

    fulvio

  2. #2
    agcopley is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Santiago, Chile
    Posts
    204

    Default Re: When a Document is deleted the file is NOT deleted (Bug ??)

    Quote Originally Posted by fulvio View Post
    Hi all,

    Sugar 5.5.0 CE
    Linux Debian Lenny
    Apache 2.2.9
    MySql 5.0.5
    PHP 5.2.6

    when a new Document is created, Sugar:
    - insert a new record into the documents table,
    - insert a new record into the document_revisions table
    - add the file into cache/upload
    But when I delete this Document, only the record into the documents
    table is marked "deleted", NOT into the document_revisions table, and
    the file into cache/upload is NOT deleted.
    Is this a bug ?

    fulvio
    Hi fulvio,
    It has always been thus! I think Sugar consider it a feature.
    I created a little batch script which cross-checks deleted document records with their id's
    and deletes those not found. The script below specificall removes notes but could be adapted to
    other types.


    <?php
    $path = '<your doc path>/cache/upload/'; // enter path of files to check if referred to by deleted records

    if($handle = opendir($path)) {
    if(is_file('<your base url>/config.php')) {
    echo "config file found";
    require_once('<your base url>/config.php'); // 'db_type' => 'mysql' add mysql only warning
    $dbUser = $sugar_config['dbconfig']['db_user_name'];
    $dbPassword = $sugar_config['dbconfig']['db_password'];
    $dbName = $sugar_config['dbconfig']['db_name'];
    $dbHost = $sugar_config['dbconfig']['db_host_name'];
    $dbConnection = @mysql_connect($dbHost, $dbUser, $dbPassword); // Make connnection
    if($dbConnection === FALSE || !mysql_select_db($dbName)) { // If can't open or select db
    echo 'Error connecting to database: '.mysql_errno().mysql_error(); // Handle error
    exit();
    }
    echo "Connected to database <br/>\n";
    } else {
    exit("Error locating config.php <br/>\n");
    }
    $count = 1;
    while(false !== ($file = readdir($handle))) {
    if(eregi("^[[:alnum:]]{8,8}-[[:alnum:]]{4,4}-[[:alnum:]]{4,4}-[[:alnum:]]{4,4}-[[:alnum:]]{12,12}$", $file)) {
    $result = mysql_query("SELECT COUNT(*) FROM `notes` WHERE id='$file' AND deleted=1");
    $row = mysql_fetch_array($result);
    if($row[0] > 0) {
    echo "$count. ";
    if(unlink($path.$file)===FALSE) echo "Error removing ";
    else echo "Deleted ";
    echo "$file<br/>\n";
    $count++;
    }
    }
    }
    closedir($handle);
    }
    else {
    echo "No handle obtained";
    }
    ?>

  3. #3
    fulvio is offline Sugar Community Member
    Join Date
    Sep 2007
    Location
    Lesmo - MB
    Posts
    124

    Post Re: When a Document is deleted the file is NOT deleted (Bug ??)

    Quote Originally Posted by agcopley View Post
    Hi fulvio,
    It has always been thus! I think Sugar consider it a feature.
    I created a little batch script which cross-checks deleted document records with their id's
    and deletes those not found. The script below specificall removes notes but could be adapted to other types.

    <cut>

    ?>
    agcoplay, thank you very much.

    fulvio

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 10
    Last Post: 2008-03-31, 05:31 PM
  2. Deleted Note doesn't delete uploaded file
    By kirkland in forum General Discussion
    Replies: 3
    Last Post: 2005-05-31, 05:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •