Index: core/custom_file_api.php
===================================================================
--- core/custom_file_api.php (revision 994)
+++ core/custom_file_api.php (working copy)
@@ -1,123 +0,0 @@
- $t_max_file_size ) {
- trigger_error( ERROR_FILE_TOO_BIG, ERROR );
- }
- $c_file_size = db_prepare_int( $t_file_size );
-
- $t_method = config_get( 'file_upload_method' );
-
- switch( $t_method ) {
- case FTP:
- case DISK:
- file_ensure_valid_upload_path( $t_file_path );
-
- if( !file_exists( $t_disk_file_name ) ) {
- if( FTP == $t_method ) {
- $conn_id = file_ftp_connect();
- file_ftp_put( $conn_id, $t_disk_file_name, $t_tmp_file );
- file_ftp_disconnect( $conn_id );
- }
-
- // move_uploaded_file replaced with rename function. Needed since files added through the EmailReporting method are not seen as such
- if( !rename( $t_tmp_file, $t_disk_file_name ) ) {
- // Corrected trigger error message name, FILE_MOVE_FAILED should have been ERROR_FILE_MOVE_FAILED
- trigger_error( ERROR_FILE_MOVE_FAILED, ERROR );
- }
-
- chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) );
-
- $c_content = "''";
- } else {
- trigger_error( ERROR_FILE_DUPLICATE, ERROR );
- }
- break;
- case DATABASE:
- $c_content = db_prepare_binary_string( fread( fopen( $t_tmp_file, 'rb' ), $t_file_size ) );
- break;
- default:
- trigger_error( ERROR_GENERIC, ERROR );
- }
-
- $t_file_table = db_get_table( 'mantis_' . $p_table . '_file_table' );
- $c_id = ( 'bug' == $p_table ) ? $c_bug_id : $c_project_id;
-
- $query = "INSERT INTO $t_file_table
- (" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)
- VALUES
- ($c_id, '$c_title', '$c_desc', '$c_unique_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', '" . db_now() . "', $c_content, $c_user_id)";
- db_query( $query );
-
- if( 'bug' == $p_table ) {
-
- # updated the last_updated date
- $result = bug_update_date( $p_bug_id );
-
- # log new bug
- history_log_event_special( $p_bug_id, FILE_ADDED, $t_file_name );
- }
-}
-?>
Index: core/mail_api.php
===================================================================
--- core/mail_api.php (revision 998)
+++ core/mail_api.php (working copy)
@@ -13,8 +13,6 @@
require_once( 'user_api.php' );
require_once( 'file_api.php' );
- require_once( plugin_config_get( 'path_erp', NULL, TRUE ) . 'core/custom_file_api.php' );
-
require_once( 'Net/POP3.php' );
require_once( plugin_config_get( 'path_erp', NULL, TRUE ) . 'core/Net/IMAP_1.0.3.php' );
@@ -735,7 +733,7 @@
foreach ( $p_email[ 'X-Mantis-Parts' ] as $part )
{
- $t_file_rejected = $this->add_file( $t_bug_id, $part );
+ $t_file_rejected = $this->add_file( $t_bug_id, $p_email[ 'Reporter_id' ], $part );
if ( $t_file_rejected !== TRUE )
{
@@ -765,7 +763,7 @@
# --------------------
# Very dirty: Adds a file to a bug.
# returns true on success and the filename with reason on error
- private function add_file( $p_bug_id, &$p_part )
+ private function add_file( $p_bug_id, $p_user_id, &$p_part )
{
# Handle the file upload
$t_part_name = ( ( isset( $p_part[ 'name' ] ) ) ? trim( $p_part[ 'name' ] ) : NULL );
@@ -794,17 +792,34 @@
$this->_file_number++;
}
- $t_file_name = $this->_mail_tmp_directory . '/' . md5( microtime() );
+ $t_file_name = $this->_mail_tmp_directory . '/' . $this->_file_number . '-' . $t_part_name;
file_put_contents( $t_file_name, $p_part[ 'body' ] );
- ERP_custom_file_add( $p_bug_id, array(
- 'tmp_name' => realpath( $t_file_name ),
- 'name' => $this->_file_number . '-' . $t_part_name,
- 'type' => $p_part[ 'ctype' ],
- 'error' => NULL
- ), 'bug' );
-
+ $ch = curl_init();
+
+ $data = array('bug_id' => $p_bug_id,
+ 'user_id' => $p_user_id,
+ 'file' => '@'.$t_file_name); // .';type='.$p_part[ 'ctype' ]); // the type part does not work under all versions of PHP (5.2.6 KO, 5.2.13 OK)
+
+ $url = config_get_global( 'path' ).plugin_page('file_add.php', true);
+ echo $url."\n";
+ echo "\n\n";
+ print_r($data);
+ echo "\n\n";
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+
+ if(curl_exec($ch) === false)
+ {
+ echo 'Curl error: ' . curl_error($ch) ."
\n";
+ }
+
+ // Close handle
+ curl_close($ch);
+
if ( is_file( $t_file_name ) )
{
unlink( $t_file_name );
Index: pages/file_add.php
===================================================================
--- pages/file_add.php (revision 0)
+++ pages/file_add.php (revision 0)
@@ -0,0 +1,49 @@
+\n";
+echo "User id: $f_user_id<
\n";
+echo "File info:
\n";
+print_r($f_file);
+echo "
\n";
+
+if ( $f_bug_id == -1 && $f_file == -1 ) {
+ # _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
+ trigger_error( ERROR_FILE_TOO_BIG, ERROR );
+}
+
+# Must set global current user id because file_add and other functions it calls
+# make calls to auth_get_current_user_id() and we obviously have no user logged
+# in when run via the cron job
+global $g_cache_current_user_id;
+$g_cache_current_user_id = $f_user_id;
+
+echo "Adding file
\n";
+file_add( $f_bug_id, $f_file, 'bug');
+echo "All done
\n";
+
+
+?>
\ No newline at end of file