Remove adminer

pull/3924/head
Julio Montoya 4 years ago
parent db1185d2ed
commit 4496a73f68
  1. 1
      .codeclimate.yml
  2. 1
      .php_cs.dist
  3. 1
      .scrutinizer.yml
  4. 1
      ecs.php
  5. 1
      phpstan.neon
  6. 2
      psalm.xml
  7. 18
      public/main/inc/lib/database.constants.inc.php
  8. 422
      public/main/inc/lib/message.lib.php

@ -69,7 +69,6 @@ exclude_patterns:
- assets/*
- bin/*
- config/*
- public/main/admin/db.php
- public/main/admin/ldap_synchro.php
- public/main/chat/emoji_strategy.php
- public/main/inc/lib/browser/

@ -56,7 +56,6 @@ $finder = PhpCsFixer\Finder::create()
->exclude('var')
->exclude('vendor')
->notPath('public/main/admin/db.php')
->notPath('public/check.php')
->notPath('public/main/admin/ldap_synchro.php')
->notPath('public/main/chat/emoji_strategy.php')

@ -21,7 +21,6 @@ filter:
- 'bin/*'
- 'config/*'
- 'public/documentation/*'
- 'public/main/admin/db.php'
- 'public/main/admin/ldap_synchro.php'
- 'public/main/chat/emoji_strategy.php'
- 'public/main/inc/lib/javascript/*'

@ -96,7 +96,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$parameters->set(
Option::SKIP,
[
__DIR__.'/public/main/admin/db.php',
__DIR__.'/src/CoreBundle/Hook/*',
__DIR__.'/src/CoreBundle/Component/HTMLPurifier/Filter/AllowIframes.php',
__DIR__.'/src/CoreBundle/Traits/Repository/*',

@ -16,7 +16,6 @@ parameters:
doctrine:
objectManagerLoader: %rootDir%/../../../tests/phpstan/doctrine-orm-bootstrap.php
excludes_analyse:
- public/main/admin/db.php
- public/main/admin/index.php
- public/main/admin/settings.php
- public/main/admin/periodic_export.php

@ -162,9 +162,7 @@
<directory name="public/main/inc/lib/zombie" />
<directory name="public/main/exercise/export/qti2" />
<file name="public/main/admin/index.php"/>
<file name="public/main/admin/db.php"/>
<file name="public/main/admin/settings.php"/>
<file name="public/main/admin/periodic_export.php"/>
<file name="public/main/admin/user_move_stats.php"/>

@ -61,14 +61,6 @@ define('TABLE_MAIN_USER_FIELD', 'user_field');
define('TABLE_MAIN_USER_FIELD_OPTIONS', 'user_field_options');
define('TABLE_MAIN_USER_FIELD_VALUES', 'user_field_values');
/*define('TABLE_MAIN_LP_FIELD', 'lp_field');
define('TABLE_MAIN_LP_FIELD_OPTIONS', 'lp_field_options');
define('TABLE_MAIN_LP_FIELD_VALUES', 'lp_field_values');*/
/*define('TABLE_MAIN_CALENDAR_EVENT_FIELD', 'calendar_event_field');
define('TABLE_MAIN_CALENDAR_EVENT_OPTIONS', 'calendar_event_options');
define('TABLE_MAIN_CALENDAR_EVENT_VALUES', 'calendar_event_values');*/
//User tags
define('TABLE_MAIN_TAG', 'tag');
define('TABLE_MAIN_USER_REL_TAG', 'user_rel_tag');
@ -145,7 +137,6 @@ define('TABLE_ANNOUNCEMENT_ATTACHMENT', 'announcement_attachment');
define('TABLE_CHAT_CONNECTED', 'chat_connected');
define('TABLE_COURSE_DESCRIPTION', 'course_description');
define('TABLE_DOCUMENT', 'document');
//define('TABLE_ITEM_PROPERTY', 'item_property');
define('TABLE_LINK', 'link');
define('TABLE_LINK_CATEGORY', 'link_category');
define('TABLE_TOOL_LIST', 'tool');
@ -326,13 +317,4 @@ define('TABLE_BRANCH', 'branch_sync');
define('TABLE_BRANCH_TRANSACTION', 'branch_transaction');
define('TABLE_BRANCH_TRANSACTION_STATUS', 'branch_transaction_status');
// main/extra @todo after code is finished remove constants not used
define('TABLE_CAL_DATE', 'cal_dates');
define('TABLE_CAL_HORAIRE', 'cal_horaire');
define('TABLE_CAL_TEMP', 'cal_temp');
define('TABLE_STATISTIC_TRACK_E_EXERCICES_TEMP', 'track_e_exercices_temp');
define('TABLE_USER_INFO_DEF', 'userinfo_def');
define('TABLE_USER_INFO_CONTENT', 'userinfo_content');
define('TABLE_MAIN_USER_CAREER', 'user_career');

@ -18,221 +18,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
class MessageManager
{
/**
* @param array $extraParams
*
* @return string
*/
public static function getWhereConditions($extraParams)
{
$userId = api_get_user_id();
$keyword = isset($extraParams['keyword']) && !empty($extraParams['keyword']) ? $extraParams['keyword'] : '';
$type = isset($extraParams['type']) && !empty($extraParams['type']) ? $extraParams['type'] : '';
if (empty($type)) {
return '';
}
switch ($type) {
case Message::MESSAGE_TYPE_INBOX:
$statusList = [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD];
$userCondition = " user_receiver_id = $userId AND";
break;
case Message::MESSAGE_TYPE_OUTBOX:
$statusList = [MESSAGE_STATUS_OUTBOX];
$userCondition = " user_sender_id = $userId AND";
break;
case Message::MESSAGE_TYPE_PROMOTED:
$statusList = [MESSAGE_STATUS_PROMOTED];
$userCondition = " user_receiver_id = $userId AND";
break;
}
if (empty($statusList)) {
return '';
}
$keywordCondition = '';
if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);
$keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') ";
}
$messageStatusCondition = implode("','", $statusList);
return " $userCondition
msg_status IN ('$messageStatusCondition')
$keywordCondition";
}
/**
* Gets information about some messages, used for the inbox sortable table.
*
* @param int $from
* @param int $numberOfItems
* @param string $column
* @param string $direction
* @param array $extraParams
*
* @return array
*/
public static function getMessageData(
$from,
$numberOfItems,
$column,
$direction,
$extraParams = []
) {
$from = (int) $from;
$numberOfItems = (int) $numberOfItems;
$column = (int) $column;
// Forcing this order.
if (!isset($direction)) {
$column = 2;
$direction = 'DESC';
} else {
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC';
}
}
if (!in_array($column, [0, 1, 2])) {
$column = 2;
}
$type = isset($extraParams['type']) && !empty($extraParams['type']) ? $extraParams['type'] : '';
if (empty($type)) {
return [];
}
$viewUrl = '';
switch ($type) {
case Message::MESSAGE_TYPE_OUTBOX:
case Message::MESSAGE_TYPE_INBOX:
$viewUrl = api_get_path(WEB_CODE_PATH).'messages/view_message.php';
break;
case Message::MESSAGE_TYPE_PROMOTED:
$viewUrl = api_get_path(WEB_CODE_PATH).'social/view_promoted_message.php';
break;
}
$viewUrl .= '?type='.$type;
$whereConditions = self::getWhereConditions($extraParams);
if (empty($whereConditions)) {
return [];
}
$table = Database::get_main_table(TABLE_MESSAGE);
$sql = "SELECT
id as col0,
title as col1,
send_date as col2,
msg_status as col3,
user_sender_id,
user_receiver_id
FROM $table
WHERE
$whereConditions
ORDER BY col$column $direction
LIMIT $from, $numberOfItems";
$result = Database::query($sql);
$messageList = [];
$newMessageLink = api_get_path(WEB_CODE_PATH).'messages/new_message.php';
$actions = $extraParams['actions'];
$url = api_get_self();
while ($row = Database::fetch_array($result, 'ASSOC')) {
$messageId = $row['col0'];
$title = $row['col1'];
$sendDate = $row['col2'];
$status = $row['col3'];
$senderId = $row['user_sender_id'];
$receiverId = $row['user_receiver_id'];
$title = Security::remove_XSS($title, STUDENT, true);
$title = cut($title, 80, true);
$class = 'class = "read"';
if (1 == $status) {
$class = 'class = "unread"';
}
$userInfo = api_get_user_info($senderId);
if (Message::MESSAGE_TYPE_OUTBOX == $type) {
$userInfo = api_get_user_info($receiverId);
}
$message[3] = '';
if (!empty($senderId) && !empty($userInfo)) {
$message[1] = '<a '.$class.' href="'.$viewUrl.'&id='.$messageId.'">'.$title.'</a><br />';
$message[1] .= $userInfo['complete_name_with_username'];
if (in_array('reply', $actions)) {
$message[3] =
Display::url(
Display::returnFontAwesomeIcon('reply', 2),
$newMessageLink.'?re_id='.$messageId,
['title' => get_lang('Reply to this message')]
);
}
} else {
$message[1] = '<a '.$class.' href="'.$viewUrl.'&id='.$messageId.'">'.$title.'</a><br />';
$message[1] .= get_lang('Unknown user');
if (in_array('reply', $actions)) {
$message[3] =
Display::url(
Display::returnFontAwesomeIcon('reply', 2),
'#',
['title' => get_lang('Reply to this message')]
);
}
}
$message[0] = $messageId;
$message[2] = api_convert_and_format_date($sendDate, DATE_TIME_FORMAT_LONG);
// Actions
if (in_array('edit', $actions)) {
$message[3] .=
'&nbsp;&nbsp;'.
Display::url(
Display::returnFontAwesomeIcon('pencil', 2),
$newMessageLink.'?action=edit&id='.$messageId,
['title' => get_lang('Forward message')]
);
}
// Actions
if (in_array('forward', $actions)) {
$message[3] .=
'&nbsp;&nbsp;'.
Display::url(
Display::returnFontAwesomeIcon('share', 2),
$newMessageLink.'?forward_id='.$messageId,
['title' => get_lang('Forward message')]
);
}
if (in_array('delete', $actions)) {
$message[3] .= '&nbsp;&nbsp;<a title="'.addslashes(
get_lang('Delete message')
).'" onclick="javascript:if(!confirm('."'".addslashes(
api_htmlentities(get_lang('ConfirmDelete message'))
)."'".')) return false;" href="'.$url.'?action=deleteone&id='.$messageId.'">'.
Display::returnFontAwesomeIcon('trash', 2).'</a>';
}
foreach ($message as $key => $value) {
$message[$key] = api_xml_http_response_encode($value);
}
$messageList[] = $message;
}
return $messageList;
}
/**
* @param array $aboutUserInfo
* @param array $fromUserInfo
@ -546,7 +331,6 @@ class MessageManager
$parent = $repo->find($parent_id);
}
$message = null;
// Just in case we replace the and \n and \n\r while saving in the DB
if (!empty($receiverUserId) || !empty($group_id)) {
// message for user friend
@ -836,34 +620,6 @@ class MessageManager
return false;
}
/**
* @param int $user_id
* @param int $message_id
* @param int $type
*
* @return bool
*/
public static function update_message_status($user_id, $message_id, $type)
{
$user_id = (int) $user_id;
$message_id = (int) $message_id;
$type = (int) $type;
if (empty($user_id) || empty($message_id)) {
return false;
}
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql = "UPDATE $table_message SET
msg_status = '$type'
WHERE
user_receiver_id = ".$user_id." AND
id = '".$message_id."'";
$result = Database::query($sql);
return Database::affected_rows($result) > 0;
}
/**
* get messages by group id.
*
@ -984,110 +740,6 @@ class MessageManager
return $data;
}
/**
* Gets information about messages sent.
*
* @param int
* @param int
* @param string
* @param string
*
* @return array
*/
public static function get_message_data_sent(
$from,
$numberOfItems,
$column,
$direction,
$extraParams = []
) {
$from = (int) $from;
$numberOfItems = (int) $numberOfItems;
if (!isset($direction)) {
$column = 2;
$direction = 'DESC';
} else {
$column = (int) $column;
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC';
}
}
if (!in_array($column, [0, 1, 2])) {
$column = 2;
}
$table = Database::get_main_table(TABLE_MESSAGE);
$request = api_is_xml_http_request();
$keyword = isset($extraParams['keyword']) && !empty($extraParams['keyword']) ? $extraParams['keyword'] : '';
$keywordCondition = '';
if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);
$keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') ";
}
$sql = "SELECT
id as col0,
title as col1,
send_date as col2,
user_receiver_id,
msg_status,
user_sender_id
FROM $table
WHERE
user_sender_id = ".api_get_user_id()." AND
msg_status = ".MESSAGE_STATUS_OUTBOX."
$keywordCondition
ORDER BY col$column $direction
LIMIT $from, $numberOfItems";
$result = Database::query($sql);
$message_list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) {
$messageId = $row['col0'];
$title = $row['col1'];
$sendDate = $row['col2'];
$senderId = $row['user_sender_id'];
if (true === $request) {
$message[0] = '<input type="checkbox" value='.$messageId.' name="out[]">';
} else {
$message[0] = $messageId;
}
$class = 'class = "read"';
$title = Security::remove_XSS($title);
$userInfo = api_get_user_info($senderId);
if (true === $request) {
$message[1] = '<a onclick="show_sent_message('.$messageId.')" href="javascript:void(0)">'.
$userInfo['complete_name_with_username'].'</a>';
$message[2] = '<a onclick="show_sent_message('.$messageId.')" href="javascript:void(0)">'.str_replace(
"\\",
"",
$title
).'</a>';
//date stays the same
$message[3] = api_convert_and_format_date($sendDate, DATE_TIME_FORMAT_LONG);
$message[4] = '&nbsp;&nbsp;<a title="'.addslashes(
get_lang('Delete message')
).'" onclick="delete_one_message_outbox('.$messageId.')" href="javascript:void(0)" >'.
Display::returnFontAwesomeIcon('trash', 2).'</a>';
} else {
$message[1] = '<a '.$class.' onclick="show_sent_message('.$messageId.')" href="../messages/view_message.php?id_send='.$messageId.'">'.$title.'</a><br />'.$userInfo['complete_name_with_username'];
$message[2] = api_convert_and_format_date($sendDate, DATE_TIME_FORMAT_LONG);
$message[3] = '<a title="'.addslashes(
get_lang('Delete message')
).'" href="outbox.php?action=deleteone&id='.$messageId.'" onclick="javascript:if(!confirm('."'".addslashes(
api_htmlentities(get_lang('ConfirmDelete message'))
)."'".')) return false;" >'.
Display::returnFontAwesomeIcon('trash', 2).'</a>';
}
$message_list[] = $message;
}
return $message_list;
}
/**
* Displays messages of a group with nested view.
*
@ -1735,80 +1387,6 @@ class MessageManager
return $html;
}
/**
* Check whether a message has attachments.
*
* @param int $messageId The message id
*
* @return bool Whether the message has attachments return true. Otherwise return false
*/
public static function hasAttachments($messageId)
{
$messageId = (int) $messageId;
if (empty($messageId)) {
return false;
}
$messageAttachmentTable = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
$conditions = [
'where' => [
'message_id = ?' => $messageId,
],
];
$result = Database::select(
'COUNT(1) AS qty',
$messageAttachmentTable,
$conditions,
'first'
);
if (!empty($result)) {
if ($result['qty'] > 0) {
return true;
}
}
return false;
}
/**
* @param int $messageId
*
* @return array|bool
*/
public static function getAttachment($messageId)
{
$messageId = (int) $messageId;
if (empty($messageId)) {
return false;
}
$table = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
$conditions = [
'where' => [
'id = ?' => $messageId,
],
];
$result = Database::select(
'*',
$table,
$conditions,
'first'
);
if (!empty($result)) {
return $result;
}
return false;
}
/**
* @param string $url
*

Loading…
Cancel
Save