| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
class midcom_midcom_services_at_entry_db extends __midcom_midcom_services_at_entry_db |
|---|
| 15 |
{ |
|---|
| 16 |
|
|---|
| 17 |
* Unserialized form of argumentsstore |
|---|
| 18 |
* |
|---|
| 19 |
* @var array |
|---|
| 20 |
*/ |
|---|
| 21 |
var $arguments = array(); |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
* Empty constructor |
|---|
| 25 |
*/ |
|---|
| 26 |
function __construct($id = null) |
|---|
| 27 |
{ |
|---|
| 28 |
$this->_use_rcs = false; |
|---|
| 29 |
return parent::__construct($id); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
* Makes sure $arguments is properly set |
|---|
| 34 |
* |
|---|
| 35 |
* @return boolean Always true |
|---|
| 36 |
*/ |
|---|
| 37 |
function _on_loaded() |
|---|
| 38 |
{ |
|---|
| 39 |
$this->_unserialize_arguments(); |
|---|
| 40 |
return true; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* Makes sure we have status set and arguments serialized |
|---|
| 45 |
* |
|---|
| 46 |
* @return boolean Always true |
|---|
| 47 |
*/ |
|---|
| 48 |
function _on_creating() |
|---|
| 49 |
{ |
|---|
| 50 |
if (!$this->status) |
|---|
| 51 |
{ |
|---|
| 52 |
$this->status = MIDCOM_SERVICES_AT_STATUS_SCHEDULED; |
|---|
| 53 |
} |
|---|
| 54 |
if (!$this->host) |
|---|
| 55 |
{ |
|---|
| 56 |
$this->host = $_MIDGARD['host']; |
|---|
| 57 |
} |
|---|
| 58 |
$this->_serialize_arguments(); |
|---|
| 59 |
return true; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
* Makes sure we have arguments serialized |
|---|
| 64 |
* |
|---|
| 65 |
* @return boolean Always true |
|---|
| 66 |
*/ |
|---|
| 67 |
function _on_updating() |
|---|
| 68 |
{ |
|---|
| 69 |
$this->_serialize_arguments(); |
|---|
| 70 |
return true; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* Autopurge after delete |
|---|
| 75 |
*/ |
|---|
| 76 |
function _on_deleted() |
|---|
| 77 |
{ |
|---|
| 78 |
if (!method_exists($this, 'purge')) |
|---|
| 79 |
{ |
|---|
| 80 |
return; |
|---|
| 81 |
} |
|---|
| 82 |
$this->purge(); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
* Unserializes argumentsstore to arguments |
|---|
| 87 |
*/ |
|---|
| 88 |
function _unserialize_arguments() |
|---|
| 89 |
{ |
|---|
| 90 |
$unserRet = @unserialize($this->argumentsstore); |
|---|
| 91 |
if ($unserRet === false) |
|---|
| 92 |
{ |
|---|
| 93 |
|
|---|
| 94 |
$unserRet = @unserialize($this->_fix_serialization($this->argumentsstore)); |
|---|
| 95 |
if ($unserRet === false) |
|---|
| 96 |
{ |
|---|
| 97 |
debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 98 |
debug_add('Failed to unserialize argumentsstore', MIDCOM_LOG_WARN); |
|---|
| 99 |
debug_pop(); |
|---|
| 100 |
$this->arguments = array(); |
|---|
| 101 |
return; |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
$this->arguments = $unserRet; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
* Serializes arguments to argumentsstore |
|---|
| 109 |
*/ |
|---|
| 110 |
function _serialize_arguments() |
|---|
| 111 |
{ |
|---|
| 112 |
$this->argumentsstore = serialize($this->arguments); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
* Fixes newline etc encoding issues in serialized data |
|---|
| 117 |
* |
|---|
| 118 |
* @param string $data The data to fix. |
|---|
| 119 |
* @return string $data with serializations fixed. |
|---|
| 120 |
*/ |
|---|
| 121 |
function _fix_serialization($data = null) |
|---|
| 122 |
{ |
|---|
| 123 |
|
|---|
| 124 |
if (empty($data)) |
|---|
| 125 |
{ |
|---|
| 126 |
return $data; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
$preg='/s:([0-9]+):"(.*?)";/ms'; |
|---|
| 130 |
|
|---|
| 131 |
preg_match_all($preg, $data, $matches); |
|---|
| 132 |
$cache = array(); |
|---|
| 133 |
|
|---|
| 134 |
foreach ($matches[0] as $k => $origFullStr) |
|---|
| 135 |
{ |
|---|
| 136 |
$origLen = $matches[1][$k]; |
|---|
| 137 |
$origStr = $matches[2][$k]; |
|---|
| 138 |
$newLen = strlen($origStr); |
|---|
| 139 |
|
|---|
| 140 |
if ($newLen != $origLen) |
|---|
| 141 |
{ |
|---|
| 142 |
$newFullStr="s:$newLen:\"$origStr\";"; |
|---|
| 143 |
|
|---|
| 144 |
if (!array_key_exists($origFullStr, $cache)) |
|---|
| 145 |
{ |
|---|
| 146 |
$data = str_replace($origFullStr, $newFullStr, $data); |
|---|
| 147 |
$cache[$origFullStr] = true; |
|---|
| 148 |
} |
|---|
| 149 |
} |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
return $data; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
* By default all authenticated users should be able to do |
|---|
| 157 |
* whatever they wish with entry objects, later we can add |
|---|
| 158 |
* restrictions on object level as necessary. |
|---|
| 159 |
* |
|---|
| 160 |
* @return array MidCOM privileges |
|---|
| 161 |
*/ |
|---|
| 162 |
function get_class_magic_default_privileges() |
|---|
| 163 |
{ |
|---|
| 164 |
$privileges = parent::get_class_magic_default_privileges(); |
|---|
| 165 |
$privileges['USERS']['midgard:create'] = MIDCOM_PRIVILEGE_ALLOW; |
|---|
| 166 |
$privileges['USERS']['midgard:update'] = MIDCOM_PRIVILEGE_ALLOW; |
|---|
| 167 |
$privileges['USERS']['midgard:read'] = MIDCOM_PRIVILEGE_ALLOW; |
|---|
| 168 |
return $privileges; |
|---|
| 169 |
} |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
class midcom_services_at_entry extends midcom_midcom_services_at_entry_db |
|---|
| 177 |
{ |
|---|
| 178 |
function __construct($id = null) |
|---|
| 179 |
{ |
|---|
| 180 |
return parent::__construct($id); |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
?> |
|---|