Merge pull request #9497 from annando/attach-field

The "attach" field is replaced by the "post-media" table
This commit is contained in:
Hypolite Petovan 2020-11-08 02:42:53 -05:00 committed by GitHub
commit ff6ab4caa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 218 additions and 237 deletions

View file

@ -677,7 +677,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`psid` int unsigned COMMENT 'ID of the permission set of this post', `psid` int unsigned COMMENT 'ID of the permission set of this post',
`resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type', `resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type',
`event-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Used to link to the event.id', `event-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Used to link to the event.id',
`attach` mediumtext COMMENT 'JSON structure representing attachments to this item', `attach` mediumtext COMMENT 'Deprecated',
`allow_cid` mediumtext COMMENT 'Deprecated', `allow_cid` mediumtext COMMENT 'Deprecated',
`allow_gid` mediumtext COMMENT 'Deprecated', `allow_gid` mediumtext COMMENT 'Deprecated',
`deny_cid` mediumtext COMMENT 'Deprecated', `deny_cid` mediumtext COMMENT 'Deprecated',

View file

@ -2040,10 +2040,17 @@ function api_statuses_repeat($type)
Logger::log('API: api_statuses_repeat: '.$id); Logger::log('API: api_statuses_repeat: '.$id);
$fields = ['uri-id', 'body', 'title', 'attach', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); $item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (DBA::isResult($item) && $item['body'] != "") { if (DBA::isResult($item) && $item['body'] != "") {
if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
if (!Item::performActivity($id, 'announce', local_user())) {
throw new InternalServerErrorException();
}
$item_id = $id;
} else {
if (strpos($item['body'], "[/share]") !== false) { if (strpos($item['body'], "[/share]") !== false) {
$pos = strpos($item['body'], "[share"); $pos = strpos($item['body'], "[share");
$post = substr($item['body'], $pos); $post = substr($item['body'], $pos);
@ -2058,7 +2065,6 @@ function api_statuses_repeat($type)
$post .= "[/share]"; $post .= "[/share]";
} }
$_REQUEST['body'] = $post; $_REQUEST['body'] = $post;
$_REQUEST['attach'] = $item['attach'];
$_REQUEST['profile_uid'] = api_user(); $_REQUEST['profile_uid'] = api_user();
$_REQUEST['api_source'] = true; $_REQUEST['api_source'] = true;
@ -2067,8 +2073,7 @@ function api_statuses_repeat($type)
} }
$item_id = item_post($a); $item_id = item_post($a);
}
/// @todo Copy tags from the original post to the new one
} else { } else {
throw new ForbiddenException(); throw new ForbiddenException();
} }

View file

@ -72,6 +72,16 @@ class DBA
return DI::dba()->getConnection(); return DI::dba()->getConnection();
} }
/**
* Return the database driver string
*
* @return string with either "pdo" or "mysqli"
*/
public static function getDriver()
{
return DI::dba()->getDriver();
}
/** /**
* Returns the MySQL server version string * Returns the MySQL server version string
* *

View file

@ -39,6 +39,9 @@ use Psr\Log\LoggerInterface;
*/ */
class Database class Database
{ {
const PDO = 'pdo';
const MYSQLI = 'mysqli';
protected $connected = false; protected $connected = false;
/** /**
@ -119,7 +122,7 @@ class Database
$this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares'); $this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares');
if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = 'pdo'; $this->driver = self::PDO;
$connect = "mysql:host=" . $server . ";dbname=" . $db; $connect = "mysql:host=" . $server . ";dbname=" . $db;
if ($port > 0) { if ($port > 0) {
@ -140,7 +143,7 @@ class Database
} }
if (!$this->connected && class_exists('\mysqli')) { if (!$this->connected && class_exists('\mysqli')) {
$this->driver = 'mysqli'; $this->driver = self::MYSQLI;
if ($port > 0) { if ($port > 0) {
$this->connection = @new mysqli($server, $user, $pass, $db, $port); $this->connection = @new mysqli($server, $user, $pass, $db, $port);
@ -201,10 +204,10 @@ class Database
{ {
if (!is_null($this->connection)) { if (!is_null($this->connection)) {
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$this->connection = null; $this->connection = null;
break; break;
case 'mysqli': case self::MYSQLI:
$this->connection->close(); $this->connection->close();
$this->connection = null; $this->connection = null;
break; break;
@ -234,6 +237,16 @@ class Database
return $this->connection; return $this->connection;
} }
/**
* Return the database driver string
*
* @return string with either "pdo" or "mysqli"
*/
public function getDriver()
{
return $this->driver;
}
/** /**
* Returns the MySQL server version string * Returns the MySQL server version string
* *
@ -246,10 +259,10 @@ class Database
{ {
if ($this->server_info == '') { if ($this->server_info == '') {
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$this->server_info = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); $this->server_info = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
break; break;
case 'mysqli': case self::MYSQLI:
$this->server_info = $this->connection->server_info; $this->server_info = $this->connection->server_info;
break; break;
} }
@ -346,10 +359,10 @@ class Database
{ {
if ($this->connected) { if ($this->connected) {
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
return substr(@$this->connection->quote($str, PDO::PARAM_STR), 1, -1); return substr(@$this->connection->quote($str, PDO::PARAM_STR), 1, -1);
case 'mysqli': case self::MYSQLI:
return @$this->connection->real_escape_string($str); return @$this->connection->real_escape_string($str);
} }
} else { } else {
@ -371,14 +384,14 @@ class Database
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$r = $this->p("SELECT 1"); $r = $this->p("SELECT 1");
if ($this->isResult($r)) { if ($this->isResult($r)) {
$row = $this->toArray($r); $row = $this->toArray($r);
$connected = ($row[0]['1'] == '1'); $connected = ($row[0]['1'] == '1');
} }
break; break;
case 'mysqli': case self::MYSQLI:
$connected = $this->connection->ping(); $connected = $this->connection->ping();
break; break;
} }
@ -508,7 +521,7 @@ class Database
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
// If there are no arguments we use "query" // If there are no arguments we use "query"
if ($this->emulate_prepares || count($args) == 0) { if ($this->emulate_prepares || count($args) == 0) {
if (!$retval = $this->connection->query($this->replaceParameters($sql, $args))) { if (!$retval = $this->connection->query($this->replaceParameters($sql, $args))) {
@ -553,7 +566,7 @@ class Database
$this->affected_rows = $retval->rowCount(); $this->affected_rows = $retval->rowCount();
} }
break; break;
case 'mysqli': case self::MYSQLI:
// There are SQL statements that cannot be executed with a prepared statement // There are SQL statements that cannot be executed with a prepared statement
$parts = explode(' ', $orig_sql); $parts = explode(' ', $orig_sql);
$command = strtolower($parts[0]); $command = strtolower($parts[0]);
@ -861,9 +874,9 @@ class Database
return 0; return 0;
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
return $stmt->columnCount(); return $stmt->columnCount();
case 'mysqli': case self::MYSQLI:
return $stmt->field_count; return $stmt->field_count;
} }
return 0; return 0;
@ -882,9 +895,9 @@ class Database
return 0; return 0;
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
return $stmt->rowCount(); return $stmt->rowCount();
case 'mysqli': case self::MYSQLI:
return $stmt->num_rows; return $stmt->num_rows;
} }
return 0; return 0;
@ -909,10 +922,10 @@ class Database
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$columns = $stmt->fetch(PDO::FETCH_ASSOC); $columns = $stmt->fetch(PDO::FETCH_ASSOC);
break; break;
case 'mysqli': case self::MYSQLI:
if (get_class($stmt) == 'mysqli_result') { if (get_class($stmt) == 'mysqli_result') {
$columns = $stmt->fetch_assoc(); $columns = $stmt->fetch_assoc();
break; break;
@ -1023,10 +1036,10 @@ class Database
public function lastInsertId() public function lastInsertId()
{ {
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$id = $this->connection->lastInsertId(); $id = $this->connection->lastInsertId();
break; break;
case 'mysqli': case self::MYSQLI:
$id = $this->connection->insert_id; $id = $this->connection->insert_id;
break; break;
} }
@ -1046,7 +1059,7 @@ class Database
public function lock($table) public function lock($table)
{ {
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
if ($this->driver == 'pdo') { if ($this->driver == self::PDO) {
$this->e("SET autocommit=0"); $this->e("SET autocommit=0");
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
} else { } else {
@ -1055,12 +1068,12 @@ class Database
$success = $this->e("LOCK TABLES " . DBA::buildTableString($table) . " WRITE"); $success = $this->e("LOCK TABLES " . DBA::buildTableString($table) . " WRITE");
if ($this->driver == 'pdo') { if ($this->driver == self::PDO) {
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
} }
if (!$success) { if (!$success) {
if ($this->driver == 'pdo') { if ($this->driver == self::PDO) {
$this->e("SET autocommit=1"); $this->e("SET autocommit=1");
} else { } else {
$this->connection->autocommit(true); $this->connection->autocommit(true);
@ -1082,13 +1095,13 @@ class Database
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
$this->performCommit(); $this->performCommit();
if ($this->driver == 'pdo') { if ($this->driver == self::PDO) {
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
} }
$success = $this->e("UNLOCK TABLES"); $success = $this->e("UNLOCK TABLES");
if ($this->driver == 'pdo') { if ($this->driver == self::PDO) {
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares);
$this->e("SET autocommit=1"); $this->e("SET autocommit=1");
} else { } else {
@ -1111,13 +1124,13 @@ class Database
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
if (!$this->connection->inTransaction() && !$this->connection->beginTransaction()) { if (!$this->connection->inTransaction() && !$this->connection->beginTransaction()) {
return false; return false;
} }
break; break;
case 'mysqli': case self::MYSQLI:
if (!$this->connection->begin_transaction()) { if (!$this->connection->begin_transaction()) {
return false; return false;
} }
@ -1131,14 +1144,14 @@ class Database
protected function performCommit() protected function performCommit()
{ {
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
if (!$this->connection->inTransaction()) { if (!$this->connection->inTransaction()) {
return true; return true;
} }
return $this->connection->commit(); return $this->connection->commit();
case 'mysqli': case self::MYSQLI:
return $this->connection->commit(); return $this->connection->commit();
} }
@ -1169,7 +1182,7 @@ class Database
$ret = false; $ret = false;
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
if (!$this->connection->inTransaction()) { if (!$this->connection->inTransaction()) {
$ret = true; $ret = true;
break; break;
@ -1177,7 +1190,7 @@ class Database
$ret = $this->connection->rollBack(); $ret = $this->connection->rollBack();
break; break;
case 'mysqli': case self::MYSQLI:
$ret = $this->connection->rollback(); $ret = $this->connection->rollback();
break; break;
} }
@ -1634,10 +1647,10 @@ class Database
} }
switch ($this->driver) { switch ($this->driver) {
case 'pdo': case self::PDO:
$ret = $stmt->closeCursor(); $ret = $stmt->closeCursor();
break; break;
case 'mysqli': case self::MYSQLI:
// MySQLi offers both a mysqli_stmt and a mysqli_result class. // MySQLi offers both a mysqli_stmt and a mysqli_result class.
// We should be careful not to assume the object type of $stmt // We should be careful not to assume the object type of $stmt
// because DBA::p() has been able to return both types. // because DBA::p() has been able to return both types.

View file

@ -754,7 +754,6 @@ class Contact
$item['title'] = ''; $item['title'] = '';
$item['guid'] = ''; $item['guid'] = '';
$item['uri-id'] = 0; $item['uri-id'] = 0;
$item['attach'] = '';
$slap = OStatus::salmon($item, $user); $slap = OStatus::salmon($item, $user);
if (!empty($contact['notify'])) { if (!empty($contact['notify'])) {
@ -2233,7 +2232,6 @@ class Contact
$item['title'] = ''; $item['title'] = '';
$item['guid'] = ''; $item['guid'] = '';
$item['uri-id'] = 0; $item['uri-id'] = 0;
$item['attach'] = '';
$slap = OStatus::salmon($item, $owner); $slap = OStatus::salmon($item, $owner);

View file

@ -77,7 +77,7 @@ class Item
const DISPLAY_FIELDLIST = [ const DISPLAY_FIELDLIST = [
'uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity', 'uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink', 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach', 'language', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'language',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object', 'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id',
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
@ -95,7 +95,7 @@ class Item
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target', 'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'location', 'coord', 'app', 'private', 'title', 'body', 'location', 'coord', 'app',
'attach', 'deleted', 'extid', 'post-type', 'gravity', 'deleted', 'extid', 'post-type', 'gravity',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'owner-link', 'contact-uid', 'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer', 'network']; 'signed_text', 'signature', 'signer', 'network'];
@ -113,7 +113,7 @@ class Item
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'psid', 'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb', 'created', 'edited', 'commented', 'received', 'changed', 'verb',
'postopts', 'plink', 'resource-id', 'event-id', 'attach', 'inform', 'postopts', 'plink', 'resource-id', 'event-id', 'inform',
'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network', 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
@ -659,7 +659,7 @@ class Item
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', 'causer-id', 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', 'causer-id',
'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid', 'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
'created', 'edited', 'commented', 'received', 'changed', 'psid', 'created', 'edited', 'commented', 'received', 'changed', 'psid',
'resource-id', 'event-id', 'attach', 'post-type', 'file', 'resource-id', 'event-id', 'post-type', 'file',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global',
'id' => 'item_id', 'network', 'icid', 'id' => 'item_id', 'network', 'icid',
@ -1087,7 +1087,7 @@ class Item
Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]); Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
// locate item to be deleted // locate item to be deleted
$fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin', $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id', 'attach', 'deleted', 'file', 'resource-id', 'event-id',
'verb', 'object-type', 'object', 'target', 'contact-id', 'verb', 'object-type', 'object', 'target', 'contact-id',
'icid', 'psid', 'gravity']; 'icid', 'psid', 'gravity'];
$item = self::selectFirst($fields, ['id' => $item_id]); $item = self::selectFirst($fields, ['id' => $item_id]);
@ -1144,10 +1144,9 @@ class Item
} }
// If item has attachments, drop them // If item has attachments, drop them
/// @TODO: this should first check if attachment is used elsewhere $attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT]);
foreach (explode(",", $item['attach']) as $attach) { foreach($attachments as $attachment) {
preg_match("|attach/(\d+)|", $attach, $matches); if (preg_match("|attach/(\d+)|", $attachment['url'], $matches)) {
if (is_array($matches) && count($matches) > 1) {
Attach::delete(['id' => $matches[1], 'uid' => $item['uid']]); Attach::delete(['id' => $matches[1], 'uid' => $item['uid']]);
} }
} }
@ -1693,7 +1692,6 @@ class Item
$item['private'] = intval($item['private'] ?? self::PUBLIC); $item['private'] = intval($item['private'] ?? self::PUBLIC);
$item['body'] = trim($item['body'] ?? ''); $item['body'] = trim($item['body'] ?? '');
$item['raw-body'] = trim($item['raw-body'] ?? $item['body']); $item['raw-body'] = trim($item['raw-body'] ?? $item['body']);
$item['attach'] = trim($item['attach'] ?? '');
$item['app'] = trim($item['app'] ?? ''); $item['app'] = trim($item['app'] ?? '');
$item['origin'] = intval($item['origin'] ?? 0); $item['origin'] = intval($item['origin'] ?? 0);
$item['postopts'] = trim($item['postopts'] ?? ''); $item['postopts'] = trim($item['postopts'] ?? '');
@ -2857,14 +2855,19 @@ class Item
} }
if ($contact['network'] != Protocol::FEED) { if ($contact['network'] != Protocol::FEED) {
$old_uri_id = $datarray["uri-id"] ?? 0;
$datarray["guid"] = System::createUUID(); $datarray["guid"] = System::createUUID();
unset($datarray["plink"]); unset($datarray["plink"]);
$datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]); $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
$datarray["uri-id"] = ItemURI::getIdByURI($datarray["uri"]);
$datarray["parent-uri"] = $datarray["uri"]; $datarray["parent-uri"] = $datarray["uri"];
$datarray["thr-parent"] = $datarray["uri"]; $datarray["thr-parent"] = $datarray["uri"];
$datarray["extid"] = Protocol::DFRN; $datarray["extid"] = Protocol::DFRN;
$urlpart = parse_url($datarray2['author-link']); $urlpart = parse_url($datarray2['author-link']);
$datarray["app"] = $urlpart["host"]; $datarray["app"] = $urlpart["host"];
if (!empty($old_uri_id)) {
Post\Media::copy($old_uri_id, $datarray["uri-id"]);
}
} else { } else {
$datarray['private'] = self::PUBLIC; $datarray['private'] = self::PUBLIC;
} }
@ -3651,12 +3654,10 @@ class Item
$as = ''; $as = '';
$vhead = false; $vhead = false;
$matches = []; foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\"(?: title=\"(.*?)\")?|', $item['attach'], $matches, PREG_SET_ORDER); $mime = $attachment['mimetype'];
foreach ($matches as $mtch) {
$mime = $mtch[3];
$the_url = Contact::magicLinkById($item['author-id'], $mtch[1]); $the_url = Contact::magicLinkById($item['author-id'], $attachment['url']);
if (strpos($mime, 'video') !== false) { if (strpos($mime, 'video') !== false) {
if (!$vhead) { if (!$vhead) {
@ -3683,8 +3684,8 @@ class Item
$filesubtype = 'unkn'; $filesubtype = 'unkn';
} }
$title = Strings::escapeHtml(trim(($mtch[4] ?? '') ?: $mtch[1])); $title = Strings::escapeHtml(trim(($attachment['description'] ?? '') ?: $attachment['url']));
$title .= ' ' . $mtch[2] . ' ' . DI::l10n()->t('bytes'); $title .= ' ' . ($attachment['size'] ?? 0) . ' ' . DI::l10n()->t('bytes');
$icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>'; $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
$as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" rel="noopener noreferrer" >' . $icon . '</a>'; $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" rel="noopener noreferrer" >' . $icon . '</a>';
@ -3923,7 +3924,7 @@ class Item
$uid = $item['uid'] ?? 0; $uid = $item['uid'] ?? 0;
// first try to fetch the item via the GUID. This will work for all reshares that had been created on this system // first try to fetch the item via the GUID. This will work for all reshares that had been created on this system
$shared_item = self::selectFirst(['title', 'body', 'attach'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]); $shared_item = self::selectFirst(['title', 'body'], ['guid' => $shared['guid'], 'uid' => [0, $uid]]);
if (!DBA::isResult($shared_item)) { if (!DBA::isResult($shared_item)) {
if (empty($shared['link'])) { if (empty($shared['link'])) {
return $item; return $item;
@ -3936,7 +3937,7 @@ class Item
return $item; return $item;
} }
$shared_item = self::selectFirst(['title', 'body', 'attach'], ['id' => $id]); $shared_item = self::selectFirst(['title', 'body'], ['id' => $id]);
if (!DBA::isResult($shared_item)) { if (!DBA::isResult($shared_item)) {
return $item; return $item;
} }

View file

@ -86,6 +86,22 @@ class Media
} }
} }
/**
* Copy attachments from one uri-id to another
*
* @param integer $from_uri_id
* @param integer $to_uri_id
* @return void
*/
public static function copy(int $from_uri_id, int $to_uri_id)
{
$attachments = self::getByURIId($from_uri_id);
foreach ($attachments as $attachment) {
$attachment['uri-id'] = $to_uri_id;
self::insert($attachment);
}
}
/** /**
* Creates the "[attach]" element from the given attributes * Creates the "[attach]" element from the given attributes
* *
@ -263,11 +279,18 @@ class Media
* Retrieves the media attachments associated with the provided item ID. * Retrieves the media attachments associated with the provided item ID.
* *
* @param int $uri_id * @param int $uri_id
* @param array $types
* @return array * @return array
* @throws \Exception * @throws \Exception
*/ */
public static function getByURIId(int $uri_id) public static function getByURIId(int $uri_id, array $types = [])
{ {
return DBA::selectToArray('post-media', [], ['uri-id' => $uri_id]); $condition = ['uri-id' => $uri_id];
if (!empty($types)) {
$condition = DBA::mergeConditions($condition, ['type' => $types]);
}
return DBA::selectToArray('post-media', [], $condition);
} }
} }

View file

@ -52,7 +52,7 @@ class Fetch extends BaseModule
// Fetch the item // Fetch the item
$fields = [ $fields = [
'uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'received', 'app', 'location', 'coord', 'network', 'uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'received', 'app', 'location', 'coord', 'network',
'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'attach' 'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'uri-id'
]; ];
$condition = ['wall' => true, 'private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; $condition = ['wall' => true, 'private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$item = Item::selectFirst($fields, $condition); $item = Item::selectFirst($fields, $condition);

View file

@ -85,7 +85,7 @@ class Like extends BaseModule
private static function performDiasporaReshare(int $itemId) private static function performDiasporaReshare(int $itemId)
{ {
$fields = ['uri-id', 'body', 'title', 'attach', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; $fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $itemId, 'private' => [Item::PUBLIC, Item::UNLISTED]]); $item = Item::selectFirst($fields, ['id' => $itemId, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (!DBA::isResult($item) || ($item['body'] == '')) { if (!DBA::isResult($item) || ($item['body'] == '')) {
return; return;
@ -105,7 +105,6 @@ class Like extends BaseModule
$post .= '[/share]'; $post .= '[/share]';
} }
$_REQUEST['body'] = $post; $_REQUEST['body'] = $post;
$_REQUEST['attach'] = $item['attach'];
$_REQUEST['profile_uid'] = local_user(); $_REQUEST['profile_uid'] = local_user();
require_once 'mod/item.php'; require_once 'mod/item.php';

View file

@ -135,8 +135,6 @@ class Processor
return $item; return $item;
} }
$item['attach'] = '';
foreach ($activity['attachments'] as $attach) { foreach ($activity['attachments'] as $attach) {
switch ($attach['type']) { switch ($attach['type']) {
case 'link': case 'link':
@ -189,21 +187,6 @@ class Processor
} }
$item['body'] .= "\n[video]" . $attach['url'] . '[/video]'; $item['body'] .= "\n[video]" . $attach['url'] . '[/video]';
} elseif (!empty($attach['url'])) {
if (!empty($item['attach'])) {
$item['attach'] .= ',';
} else {
$item['attach'] = '';
}
$item['attach'] .= Post\Media::getAttachElement(
$attach['url'],
$attach['length'] ?? 0,
$attach['mediaType'] ?? '',
$attach['name'] ?? ''
);
} else {
Logger::notice('Unknown attachment', ['attach' => $attach]);
} }
} }
} }
@ -787,6 +770,10 @@ class Processor
$object_actor = $object['actor']; $object_actor = $object['actor'];
} elseif (!empty($object['attributedTo'])) { } elseif (!empty($object['attributedTo'])) {
$object_actor = $object['attributedTo']; $object_actor = $object['attributedTo'];
if (is_array($object_actor)) {
$compacted = JsonLD::compact($object);
$object_actor = JsonLD::fetchElement($compacted, 'as:attributedTo', '@id');
}
} else { } else {
// Shouldn't happen // Shouldn't happen
$object_actor = ''; $object_actor = '';

View file

@ -37,13 +37,13 @@ use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
use Friendica\Util\Images;
use Friendica\Util\JsonLD; use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature; use Friendica\Util\LDSignature;
use Friendica\Util\Map; use Friendica\Util\Map;
@ -829,7 +829,6 @@ class Transmitter
$mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT); $mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
$mail['event-type'] = ''; $mail['event-type'] = '';
$mail['attach'] = '';
$mail['parent'] = 0; $mail['parent'] = 0;
@ -1220,57 +1219,22 @@ class Transmitter
$attachments[] = $attachment; $attachments[] = $attachment;
} }
*/ */
$arr = explode('[/attach],', $item['attach']); foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
if (count($arr)) { $attachments[] = ['type' => 'Document',
foreach ($arr as $r) { 'mediaType' => $attachment['mimetype'],
$matches = false; 'url' => $attachment['url'],
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches); 'name' => $attachment['description']];
if ($cnt) {
$attributes = ['type' => 'Document',
'mediaType' => $matches[3],
'url' => $matches[1],
'name' => null];
if (trim($matches[4]) != '') {
$attributes['name'] = trim($matches[4]);
}
$attachments[] = $attributes;
}
}
} }
if ($type != 'Note') { if ($type != 'Note') {
return $attachments; return $attachments;
} }
// Simplify image codes foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) {
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
// Grab all pictures without alternative descriptions and create attachments out of them
if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
foreach ($pictures[1] as $picture) {
$imgdata = Images::getInfoFromURLCached($picture);
if ($imgdata) {
$attachments[] = ['type' => 'Document', $attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'], 'mediaType' => $attachment['mimetype'],
'url' => $picture, 'url' => $attachment['url'],
'name' => null]; 'name' => $attachment['description']];
}
}
}
// Grab all pictures with alternative description and create attachments out of them
if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
foreach ($pictures as $picture) {
$imgdata = Images::getInfoFromURLCached($picture[1]);
if ($imgdata) {
$attachments[] = ['type' => 'Document',
'mediaType' => $imgdata['mime'],
'url' => $picture[1],
'name' => $picture[2]];
}
}
} }
return $attachments; return $attachments;
@ -1454,16 +1418,16 @@ class Transmitter
$body = $item['body']; $body = $item['body'];
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
$body = self::prependMentions($body, $item['uri-id']);
}
if ($type == 'Note') { if ($type == 'Note') {
$body = self::removePictures($body); $body = $item['raw-body'] ?? self::removePictures($body);
} elseif (($type == 'Article') && empty($data['summary'])) { } elseif (($type == 'Article') && empty($data['summary'])) {
$data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000)); $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
} }
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
$body = self::prependMentions($body, $item['uri-id']);
}
if ($type == 'Event') { if ($type == 'Event') {
$data = array_merge($data, self::createEvent($item)); $data = array_merge($data, self::createEvent($item));
} else { } else {

View file

@ -866,27 +866,19 @@ class DFRN
*/ */
private static function getAttachment($doc, $root, $item) private static function getAttachment($doc, $root, $item)
{ {
$arr = explode('[/attach],', $item['attach']); foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
if (count($arr)) { $attributes = ['rel' => 'enclosure',
foreach ($arr as $r) { 'href' => $attachment['url'],
$matches = false; 'type' => $attachment['mimetype']];
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
if ($cnt) {
$attributes = ["rel" => "enclosure",
"href" => $matches[1],
"type" => $matches[3]];
if (intval($matches[2])) { if (!empty($attachment['size'])) {
$attributes["length"] = intval($matches[2]); $attributes['length'] = intval($attachment['size']);
}
if (!empty($attachment['description'])) {
$attributes['title'] = $attachment['description'];
} }
if (trim($matches[4]) != "") { XML::addElement($doc, $root, 'link', '', $attributes);
$attributes["title"] = trim($matches[4]);
}
XML::addElement($doc, $root, "link", "", $attributes);
}
}
} }
} }
@ -2154,9 +2146,9 @@ class DFRN
{ {
$rel = ""; $rel = "";
$href = ""; $href = "";
$type = ""; $type = null;
$length = "0"; $length = null;
$title = ""; $title = null;
foreach ($links as $link) { foreach ($links as $link) {
foreach ($link->attributes as $attributes) { foreach ($link->attributes as $attributes) {
switch ($attributes->name) { switch ($attributes->name) {
@ -2173,13 +2165,8 @@ class DFRN
$item["plink"] = $href; $item["plink"] = $href;
break; break;
case "enclosure": case "enclosure":
if (!empty($item["attach"])) { Post\Media::insert(['uri-id' => $item['uri-id'], 'type' => Post\Media::DOCUMENT,
$item["attach"] .= ","; 'url' => $href, 'mimetype' => $type, 'size' => $length, 'description' => $title]);
} else {
$item["attach"] = "";
}
$item["attach"] .= Post\Media::getAttachElement($href, $length, $type, $title);
break; break;
} }
} }

View file

@ -2458,8 +2458,8 @@ class Diaspora
} }
// Do we already have this item? // Do we already have this item?
$fields = ['body', 'title', 'attach', 'app', 'created', 'object-type', 'uri', 'guid', $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar', 'plink']; 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]]; $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
$item = Item::selectFirst($fields, $condition); $item = Item::selectFirst($fields, $condition);
@ -2502,8 +2502,8 @@ class Diaspora
} }
if ($stored) { if ($stored) {
$fields = ['body', 'title', 'attach', 'app', 'created', 'object-type', 'uri', 'guid', $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar', 'plink']; 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]]; $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
$item = Item::selectFirst($fields, $condition); $item = Item::selectFirst($fields, $condition);
@ -2646,7 +2646,7 @@ class Diaspora
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]); Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
$datarray["attach"] = $original_item["attach"]; Post\Media::copy($original_item['uri-id'], $datarray['uri-id']);
$datarray["app"] = $original_item["app"]; $datarray["app"] = $original_item["app"];
$datarray["plink"] = self::plink($author, $guid); $datarray["plink"] = self::plink($author, $guid);
@ -3578,13 +3578,11 @@ class Diaspora
$body = "### ".html_entity_decode($title)."\n\n".$body; $body = "### ".html_entity_decode($title)."\n\n".$body;
} }
if ($item["attach"]) { $attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]);
$cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item["attach"], $matches, PREG_SET_ORDER); if (!empty($attachments)) {
if ($cnt) {
$body .= "\n".DI::l10n()->t("Attachments:")."\n"; $body .= "\n".DI::l10n()->t("Attachments:")."\n";
foreach ($matches as $mtch) { foreach ($attachments as $attachment) {
$body .= "[".$mtch[3]."](".$mtch[1].")\n"; $body .= "[" . $attachment['description'] . "](" . $attachment['url'] . ")\n";
}
} }
} }

View file

@ -437,8 +437,8 @@ class Feed
$enclosures = $xpath->query("enclosure|atom:link[@rel='enclosure']", $entry); $enclosures = $xpath->query("enclosure|atom:link[@rel='enclosure']", $entry);
foreach ($enclosures AS $enclosure) { foreach ($enclosures AS $enclosure) {
$href = ""; $href = "";
$length = 0; $length = null;
$type = ""; $type = null;
foreach ($enclosure->attributes AS $attribute) { foreach ($enclosure->attributes AS $attribute) {
if (in_array($attribute->name, ["url", "href"])) { if (in_array($attribute->name, ["url", "href"])) {
@ -450,15 +450,9 @@ class Feed
} }
} }
if (!empty($item["attach"])) { if (!empty($href)) {
$item["attach"] .= ','; $attachments[] = ['type' => Post\Media::DOCUMENT, 'url' => $href, 'mimetype' => $type, 'size' => $length];
} else {
$item["attach"] = '';
} }
$attachments[] = ["link" => $href, "type" => $type, "length" => $length];
$item["attach"] .= Post\Media::getAttachElement($href, $length, $type);
} }
$taglist = []; $taglist = [];
@ -515,8 +509,8 @@ class Feed
if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) { if (!empty($contact["fetch_further_information"]) && ($contact["fetch_further_information"] < 3)) {
// Handle enclosures and treat them as preview picture // Handle enclosures and treat them as preview picture
foreach ($attachments AS $attachment) { foreach ($attachments AS $attachment) {
if ($attachment["type"] == "image/jpeg") { if ($attachment["mimetype"] == "image/jpeg") {
$preview = $attachment["link"]; $preview = $attachment["url"];
} }
} }
@ -576,7 +570,7 @@ class Feed
$item["body"] = $item["body"] . "\n" . PageInfo::getFooterFromData($data, false); $item["body"] = $item["body"] . "\n" . PageInfo::getFooterFromData($data, false);
$taglist = $contact["fetch_further_information"] == 2 ? PageInfo::getTagsFromUrl($item["plink"], $preview, $contact["ffi_keyword_denylist"] ?? '') : []; $taglist = $contact["fetch_further_information"] == 2 ? PageInfo::getTagsFromUrl($item["plink"], $preview, $contact["ffi_keyword_denylist"] ?? '') : [];
$item["object-type"] = Activity\ObjectType::BOOKMARK; $item["object-type"] = Activity\ObjectType::BOOKMARK;
unset($item["attach"]); $attachments = [];
} else { } else {
if (!empty($summary)) { if (!empty($summary)) {
$item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"]; $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"];
@ -616,11 +610,15 @@ class Feed
Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id); Logger::info("Feed for contact " . $contact["url"] . " stored under id " . $id);
if (!empty($id) && !empty($taglist)) { if (!empty($id) && (!empty($taglist) || !empty($attachments))) {
$feeditem = Item::selectFirst(['uri-id'], ['id' => $id]); $feeditem = Item::selectFirst(['uri-id'], ['id' => $id]);
foreach ($taglist as $tag) { foreach ($taglist as $tag) {
Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag); Tag::store($feeditem['uri-id'], Tag::HASHTAG, $tag);
} }
foreach ($attachments as $attachment) {
$attachment['uri-id'] = $feeditem['uri-id'];
Post\Media::insert($attachment);
}
} }
} }

View file

@ -1119,16 +1119,9 @@ class OStatus
if ($filetype == 'image') { if ($filetype == 'image') {
$link_data['add_body'] .= "\n[img]".$attribute['href'].'[/img]'; $link_data['add_body'] .= "\n[img]".$attribute['href'].'[/img]';
} else { } else {
if (!empty($item["attach"])) { Post\Media::insert(['uri-id' => $item['uri-id'], 'type' => Post\Media::DOCUMENT,
$item["attach"] .= ','; 'url' => $attribute['href'], 'mimetype' => $attribute['type'],
} else { 'size' => $attribute['length'] ?? null, 'description' => $attribute['title'] ?? null]);
$item["attach"] = '';
}
if (!isset($attribute['length'])) {
$attribute['length'] = "0";
}
$item["attach"] .= Post\Media::getAttachElement($attribute['href'],
$attribute['length'], $attribute['type'], $attribute['title'] ?? '');
} }
break; break;
case "related": case "related":
@ -1392,25 +1385,19 @@ class OStatus
} }
} }
$arr = explode('[/attach],', $item['attach']); foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
if (count($arr)) { $attributes = ['rel' => 'enclosure',
foreach ($arr as $r) { 'href' => $attachment['url'],
$matches = false; 'type' => $attachment['mimetype']];
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
if ($cnt) {
$attributes = ["rel" => "enclosure",
"href" => $matches[1],
"type" => $matches[3]];
if (intval($matches[2])) { if (!empty($attachment['size'])) {
$attributes["length"] = intval($matches[2]); $attributes['length'] = intval($attachment['size']);
}
if (trim($matches[4]) != "") {
$attributes["title"] = trim($matches[4]);
}
XML::addElement($doc, $root, "link", "", $attributes);
} }
if (!empty($attachment['description'])) {
$attributes['title'] = $attachment['description'];
} }
XML::addElement($doc, $root, 'link', '', $attributes);
} }
} }

View file

@ -747,9 +747,8 @@ return [
// It has to be decided whether these fields belong to the user or the structure // It has to be decided whether these fields belong to the user or the structure
"resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"], "resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
"event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"], "event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Could possibly be replaced by the "attach" table?
"attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
// Deprecated fields. Will be removed in upcoming versions // Deprecated fields. Will be removed in upcoming versions
"attach" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"], "allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"], "allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Deprecated"], "deny_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],

View file

@ -119,7 +119,14 @@ class DependencyCheckTest extends TestCase
$database = $this->dice->create(Database::class); $database = $this->dice->create(Database::class);
self::assertInstanceOf(Database::class, $database); self::assertInstanceOf(Database::class, $database);
self::assertTrue($database->connected()); self::assertContains($database->getDriver(), [Database::PDO, Database::MYSQLI], 'The driver returns an unexpected value');
self::assertNotNull($database->getConnection(), 'There is no database connection');
$result = $database->p("SELECT 1");
self::assertEquals($database->errorMessage(), '', 'There had been a database error message');
self::assertEquals($database->errorNo(), 0, 'There had been a database error number');
self::assertTrue($database->connected(), 'The database is not connected');
} }
public function testAppMode() public function testAppMode()
@ -129,7 +136,12 @@ class DependencyCheckTest extends TestCase
self::assertInstanceOf(App\Mode::class, $mode); self::assertInstanceOf(App\Mode::class, $mode);
self::assertTrue($mode->isNormal()); self::assertTrue($mode->has(App\Mode::LOCALCONFIGPRESENT), 'No local config present');
self::assertTrue($mode->has(App\Mode::DBAVAILABLE), 'Database is not available');
self::assertTrue($mode->has(App\Mode::DBCONFIGAVAILABLE), 'Database config is not available');
self::assertTrue($mode->has(App\Mode::MAINTENANCEDISABLED), 'In maintenance mode');
self::assertTrue($mode->isNormal(), 'Not in normal mode');
} }
public function testConfiguration() public function testConfiguration()