Browse Source

Utils Attachment patches

master
Janusz Tylek 2 years ago
parent
commit
8739eede08
2 changed files with 82 additions and 0 deletions
  1. +43
    -0
      modules/Utils/Attachment/patches/20171024_use_generic_file_field.php
  2. +39
    -0
      modules/Utils/Attachment/patches/20171025_use_generic_attached_to_field.php

+ 43
- 0
modules/Utils/Attachment/patches/20171024_use_generic_file_field.php View File

@@ -0,0 +1,43 @@
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');

$field = array('name' => _M('Files'),
'type' => 'file',
'position' => 'Note',
'required' => false,
'extra' => false,
'visible'=>false,
'QFfield_callback'=>array('Utils_AttachmentCommon','QFfield_files'),
);

Utils_RecordBrowserCommon::new_record_field('utils_attachment', $field);

$fields = Utils_RecordBrowserCommon::init('utils_attachment');
$field_key = $fields['Files']['pkey'];

$cp = Patch::checkpoint('add_file_values');
if (!$cp->is_done()) {
$last_id = $cp->get('last_id', 0);
$attachment_ids = DB::GetCol('SELECT id FROM utils_attachment_data_1 WHERE id > %d ORDER BY id ASC', [$last_id]);
foreach ($attachment_ids as $attachment_id) {
$files = DB::GetCol('SELECT id FROM utils_filestorage WHERE backref=%s', ['rb:utils_attachment/' . $attachment_id]);
if ($files) {
DB::Execute('UPDATE utils_filestorage SET backref=%s WHERE id IN (' . implode(',', array_fill(0, count($files), '%d')) . ')', array_merge(['rb:utils_attachment/' . $attachment_id . '/' . $field_key], array_values($files)));
$files = Utils_RecordBrowserCommon::encode_multi($files);
DB::Execute('UPDATE utils_attachment_data_1 SET f_files=%s WHERE id=%d', [$files, $attachment_id]);
}
$cp->set('last_id', $attachment_id);
}
$cp->done();
}

DB::DropTable('utils_attachment_download');
DB::DropTable('utils_attachment_file');
DB::DropTable('utils_attachment_clipboard');

+ 39
- 0
modules/Utils/Attachment/patches/20171025_use_generic_attached_to_field.php View File

@@ -0,0 +1,39 @@
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');

Utils_RecordBrowserCommon::delete_record_field('utils_attachment', 'Attached to');

$field = array('name' => _M('Attached to'),
'type' => 'multiselect',
'position' => 'Crypted',
'param' => '__RECORDSETS__::;',
'required' => false,
'extra' => false,
'visible'=>false,
);

Utils_RecordBrowserCommon::new_record_field('utils_attachment', $field);

$cp = Patch::checkpoint('add_attached_to_values');
if (!$cp->is_done()) {
$last_id = $cp->get('last_id', 0);
$attachment_ids = DB::GetCol('SELECT id FROM utils_attachment_data_1 WHERE id > %d ORDER BY id ASC', [$last_id]);
foreach ($attachment_ids as $attachment_id) {
$attached_to = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d', [$attachment_id]);
if ($attached_to) {
$attached_to = Utils_RecordBrowserCommon::encode_multi($attached_to);
DB::Execute('UPDATE utils_attachment_data_1 SET f_attached_to=%s WHERE id=%d', [$attached_to, $attachment_id]);
}
$cp->set('last_id', $attachment_id);
}
$cp->done();
}

DB::DropTable('utils_filestorage_local');


Loading…
Cancel
Save