- $r = q("SELECT `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
- dbesc(protect_sprintf($datarray['title'])),
- intval($importer_uid),
- dbesc(NETWORK_MAIL));
- if (DBM::is_result($r)) {
- $datarray['parent-uri'] = $r[0]['parent-uri'];
+ $condition = ['title' => $datarray['title'], 'uid' => importer_uid, 'network' => Protocol::MAIL];
+ $params = ['order' => ['created' => true]];
+ $parent = Item::selectFirst(['parent-uri'], $condition, $params);
+ if (DBA::isResult($parent)) {
+ $datarray['parent-uri'] = $parent['parent-uri'];