function delete_equal_attachments(array $attachments)
{
    echo "----- Start Purge -----\n";
    foreach ($attachments as $attachment_id => $artifact_type_id) {
        $parent_path = ArtifactFile::getParentDirectoryForArtifactTypeId($artifact_type_id);
        $attachment_path = $parent_path . DIRECTORY_SEPARATOR . $attachment_id;
        if (is_file($attachment_path)) {
            $res = db_query('SELECT filesize, md5(bin_data) as md5 FROM artifact_file WHERE id = ' . $attachment_id);
            if ($res && !db_error($res)) {
                $row = db_fetch_array($res);
                if (md5_file($attachment_path) === $row['md5']) {
                    db_query("UPDATE artifact_file SET bin_data = '' WHERE id = {$attachment_id}");
                    if (db_error()) {
                        error("An error occured while cleanning-up {$attachment_id}: " . @mysql_error());
                    }
                }
            }
            db_free_result($res);
        }
    }
    echo "----- Purge completed -----\n";
}
Beispiel #2
0
 function artifactfile_to_soap($file_id, Artifact $artifact, $set_bin_data)
 {
     $return = null;
     $attachedfiles_arr = $artifact->getAttachedFiles();
     $rows = db_numrows($attachedfiles_arr);
     for ($i = 0; $i < $rows; $i++) {
         $file = array();
         $attachment_id = db_result($attachedfiles_arr, $i, 'id');
         $file['id'] = $attachment_id;
         $file['artifact_id'] = db_result($attachedfiles_arr, $i, 'artifact_id');
         $file['filename'] = db_result($attachedfiles_arr, $i, 'filename');
         $file['description'] = SimpleSanitizer::unsanitize(db_result($attachedfiles_arr, $i, 'description'));
         if ($set_bin_data) {
             $attachment_path = ArtifactFile::getPathOnFilesystem($artifact, $attachment_id);
             if (is_file($attachment_path)) {
                 $file['bin_data'] = file_get_contents($attachment_path);
             } else {
                 $file['bin_data'] = db_result($attachedfiles_arr, $i, 'bin_data');
             }
         }
         $file['filesize'] = db_result($attachedfiles_arr, $i, 'filesize');
         $file['filetype'] = db_result($attachedfiles_arr, $i, 'filetype');
         $file['adddate'] = db_result($attachedfiles_arr, $i, 'adddate');
         $file['submitted_by'] = db_result($attachedfiles_arr, $i, 'user_name');
         if ($file['id'] == $file_id) {
             $return = $file;
         }
     }
     return $return;
 }
 /**
  *	Delete a tracker
  *
  *  @aparam atid: the artifact type id
  *
  *	@return	boolean
  */
 function deleteArtifactType($atid)
 {
     // Delete artifact_canned_responses
     $sql = "DELETE FROM artifact_canned_responses \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification
     $sql = "DELETE FROM artifact_notification  \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification_event
     $sql = "DELETE FROM artifact_notification_event   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_notification_role
     $sql = "DELETE FROM artifact_notification_role   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // Delete artifact_perm
     $sql = "DELETE FROM artifact_perm   \n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     db_query($sql);
     // We need to instanciate an artifactType to instanciate the factories
     $artifactType = new ArtifactType($this->getGroup(), $atid, false);
     $art_field_fact = new ArtifactFieldFactory($artifactType);
     $art_fieldset_fact = new ArtifactFieldSetFactory($artifactType);
     // Delete the fields of this tracker
     $art_field_fact->deleteFields($atid);
     // Delete the field sets of this tracker
     $art_fieldset_fact->deleteFieldSets();
     // Delete the artifact_report
     $art_report_fact = new ArtifactReportFactory();
     $art_report_fact->deleteReports($atid);
     //Generate an event
     $em =& EventManager::instance();
     $pref_params = array('atid' => $atid);
     $em->processEvent('artifactType_deleted', $pref_params);
     // Delete the artifact rules
     $art_rule_fact = ArtifactRuleFactory::instance();
     $art_rule_fact->deleteRulesByArtifactType($atid);
     // Delete artifact_watcher (be carefull, the column is named artifact_group_id)
     $sql = "DELETE FROM artifact_watcher   \n\t\t\t    WHERE artifact_group_id=" . db_ei($atid);
     db_query($sql);
     // Delete all records linked to artifact_id
     $sql_artifacts = 'SELECT artifact_id ' . 'FROM artifact ' . 'WHERE group_artifact_id=' . db_ei($atid);
     //echo $sql_artifacts;
     $res = db_query($sql_artifacts);
     while ($artifacts_array = db_fetch_array($res)) {
         $id = $artifacts_array["artifact_id"];
         // Delete artifact_cc records
         $sql = "DELETE FROM artifact_cc WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_dependencies records
         $sql = "DELETE FROM artifact_dependencies WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_field_value records
         $sql = "DELETE FROM artifact_field_value WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_file records
         $sql = "DELETE FROM artifact_file WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact_history records
         $sql = "DELETE FROM artifact_history WHERE artifact_id = " . db_ei($id);
         db_query($sql);
         // Delete artifact records
         $sql = "DELETE FROM artifact WHERE artifact_id = " . db_ei($id);
         db_query($sql);
     }
     // while
     // Delete file attachments
     ArtifactFile::deleteAllByArtifactType($atid);
     // Delete artifact_group_list
     $sql = "DELETE FROM artifact_group_list\n\t\t\t    WHERE group_artifact_id=" . db_ei($atid);
     //echo $sql;
     $result = db_query($sql);
     if (!$result || db_affected_rows($result) <= 0) {
         $this->setError('Error: deleteArtifactType ' . db_error());
         return false;
     }
     //Remove permissions
     permission_clear_all_tracker($this->Group->getID(), $atid);
     $em = EventManager::instance();
     $em->processEvent("artifact_type_factory_delete_artifact_type", array('tracker_id' => $atid));
     return true;
 }
 private function getFilePathOnServer($artifact_type_id, $attachment_id)
 {
     return ArtifactFile::getPathOnFilesystemByArtifactTypeId($artifact_type_id, $attachment_id);
 }
Beispiel #5
0
            $sql = "SELECT description,bin_data,filename,filesize,filetype FROM artifact_file WHERE id='" . db_ei($id) . "' AND artifact_id ='" . db_ei($artifact_id) . "'";
            //echo $sql;
            $result = db_query($sql);
            if ($result && db_numrows($result) > 0) {
                if (db_result($result, 0, 'filesize') == 0) {
                    exit_error($Language->getText('global', 'error'), $Language->getText('tracker_download', 'file_is_null'));
                } else {
                    // Download the patch with the correct filetype
                    require_once 'common/include/Codendi_HTTPPurifier.class.php';
                    $http = Codendi_HTTPPurifier::instance();
                    header('X-Content-Type-Options: nosniff');
                    header('Content-Type: ' . $http->purify(db_result($result, 0, 'filetype')));
                    header('Content-Length: ' . $http->purify(db_result($result, 0, 'filesize')));
                    header('Content-Disposition: attachment; filename="' . $http->purify(db_result($result, 0, 'filename')) . '"');
                    header('Content-Description: ' . $http->purify(db_result($result, 0, 'description')));
                    $attachment_path = ArtifactFile::getPathOnFilesystem($a, $id);
                    if (is_file($attachment_path)) {
                        readfile($attachment_path);
                    } else {
                        echo db_result($result, 0, 'bin_data');
                    }
                    exit;
                }
            }
        } else {
            exit_error($Language->getText('global', 'error'), $Language->getText('global', 'perm_denied'));
        }
    } else {
        exit_error($Language->getText('global', 'error'), $Language->getText('global', 'perm_denied'));
    }
}