mybb / merge-system

The MyBB Merge System allows for easy merging of an existing forum (be it MyBB or another forum software) into a MyBB 1.8.x forum.
Other
34 stars 33 forks source link

Move attachment copying to parent class #174

Closed JN-Jones closed 9 years ago

JN-Jones commented 9 years ago

Atm every attachment module has a after_insert function which basically looks like this for all boards:

function after_insert($data, $insert_data, $aid)
    {
        global $mybb, $import_session, $lang;

        // Transfer attachment
        $data_file = merge_fetch_remote_file($import_session['uploadspath'].'/'.$data['attach_location']);
        if(!empty($data_file))
        {
            $attachrs = @fopen($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], 'w');
            if($attachrs)
            {
                @fwrite($attachrs, $data_file);
            }
            else
            {
                $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_error, $aid));
            }
            @fclose($attachrs);

            @my_chmod($mybb->settings['uploadspath'].'/'.$insert_data['attachname'], '0777');
        }
        else
        {
            $this->board->set_error_notice_in_progress($lang->sprintf($lang->module_attachment_not_found, $aid));
        }
    }

Mostly the merge_fetch_remote_file($import_session['uploadspath'].'/'.$data['attach_location']) part changes. As we already have function like generate_raw_filename we can move that function to the general class.

JN-Jones commented 9 years ago

At least the phpbb 3 module also tries to update the attachment counter:

        $attach_details = $this->get_import->post_attachment_details($data['post_msg_id']);
        $db->write_query("UPDATE ".TABLE_PREFIX."threads SET attachmentcount = attachmentcount + 1 WHERE tid = '".$attach_details['tid']."'");

As we want to add the counter logic to the merge system (avoid running the recount/rebuild tools) that part should also be included.

JN-Jones commented 9 years ago

I've also decided to simplify the uploadspath process, it's pretty much the same.