This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
/
AttachmentCache.php
126 lines (110 loc) · 3.72 KB
/
AttachmentCache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php declare(strict_types=1);
/**
* class to hold Attachment Cache data
*
* @package Felamimail
* @subpackage Model
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <p.mehrer@metaways.de>
* @copyright Copyright (c) 2021 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/
/**
* class to hold Attachment Cache data
*
* @package Felamimail
* @subpackage Model
*/
class Felamimail_Model_AttachmentCache extends Tinebase_Record_NewAbstract
{
const MODEL_NAME_PART = 'AttachmentCache';
const TABLE_NAME = 'felamimail_attachmentcache';
const FLD_HASH = 'hash';
const FLD_PART_ID = 'part_id';
const FLD_SOURCE_ID = 'source_id';
const FLD_SOURCE_MODEL = 'source_model';
/**
* Holds the model configuration (must be assigned in the concrete class)
*
* @var array
*/
protected static $_modelConfiguration = [
self::VERSION => 1,
self::MODLOG_ACTIVE => false,
self::HAS_ATTACHMENTS => true,
self::SINGULAR_CONTAINER_MODE => true,
self::HAS_PERSONAL_CONTAINER => false,
self::APP_NAME => Felamimail_Config::APP_NAME,
self::MODEL_NAME => self::MODEL_NAME_PART,
self::TABLE => [
self::NAME => self::TABLE_NAME,
],
self::FIELDS => [
self::FLD_HASH => [
self::TYPE => self::TYPE_STRING,
self::LENGTH => 255,
self::NULLABLE => true,
],
self::FLD_PART_ID => [
self::TYPE => self::TYPE_STRING,
self::DOCTRINE_IGNORE => true,
],
self::FLD_SOURCE_ID => [
self::TYPE => self::TYPE_STRING,
self::DOCTRINE_IGNORE => true,
],
self::FLD_SOURCE_MODEL => [
self::TYPE => self::TYPE_STRING,
self::DOCTRINE_IGNORE => true,
],
]
];
/*
* api
*/
public function isFSNode(): bool
{
if (Filemanager_Model_Node::class === $this->{self::FLD_SOURCE_MODEL} ||
Tinebase_Model_Tree_Node::class === $this->{self::FLD_SOURCE_MODEL}) {
return true;
}
return false;
}
/*
* more or less internals (though some publics)
*/
public static function modelConfigHook(array &$_definition)
{
$_definition['id']['length'] = 700;
}
public function hydrateFromBackend(array &$data)
{
parent::hydrateFromBackend($data);
$this->fillFromId($data['id']);
}
public function setFromArray(array &$_data)
{
parent::setFromArray($_data);
if (isset($_data['id'])) {
$this->fillFromId($_data['id']);
}
}
public function setId($_id)
{
parent::setId($_id);
$this->fillFromId($_id);
}
protected function fillFromId(string $id)
{
[$model, $recordId, $partId] = explode(':', $id, 3);
$this->{self::FLD_SOURCE_MODEL} = $model;
$this->{self::FLD_SOURCE_ID} = $recordId;
$this->{self::FLD_PART_ID} = $partId;
}
/**
* holds the configuration object (must be declared in the concrete class)
*
* @var Tinebase_ModelConfiguration
*/
protected static $_configurationObject = null;
}