Minor - message.user_receiver_id can have a NULL value used

pull/2650/head^2
Julio Montoya 6 years ago
parent 4b957af8e0
commit 0faf0f4fbd
  1. 8
      app/Migrations/Schema/V200/Version20.php
  2. 10
      main/inc/lib/message.lib.php
  3. 2
      src/CoreBundle/Entity/Message.php

@ -169,10 +169,12 @@ class Version20 extends AbstractMigrationChamilo
$this->addSql('UPDATE session_category SET date_end = NULL WHERE date_end = "0000-00-00"');
$this->addSql('DELETE FROM message WHERE user_sender_id IS NULL OR user_sender_id = 0');
$this->addSql('DELETE FROM message WHERE user_receiver_id IS NULL OR user_sender_id = 0');
$this->addSql('ALTER TABLE message CHANGE user_receiver_id user_receiver_id INT DEFAULT NULL');
$this->addSql('UPDATE message SET user_receiver_id = NULL WHERE user_receiver_id = 0');
$this->addSql('DELETE FROM message WHERE user_sender_id NOT IN (SELECT id FROM user)');
$this->addSql('DELETE FROM message WHERE user_receiver_id NOT IN (SELECT id FROM user)');
$this->addSql('DELETE FROM message WHERE user_receiver_id IS NOT NULL AND user_receiver_id NOT IN (SELECT id FROM user)');
$this->addSql('ALTER TABLE message ADD CONSTRAINT FK_B6BD307FF6C43E79 FOREIGN KEY (user_sender_id) REFERENCES user (id)');
$this->addSql('ALTER TABLE message ADD CONSTRAINT FK_B6BD307F64482423 FOREIGN KEY (user_receiver_id) REFERENCES user (id)');
@ -502,7 +504,7 @@ class Version20 extends AbstractMigrationChamilo
// Portfolio
if (!$schema->hasTable('portfolio')) {
$this->addSql('CREATE TABLE portfolio_category (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, title LONGTEXT NOT NULL, description LONGTEXT DEFAULT NULL, is_visible TINYINT(1) DEFAULT "1" NOT NULL, INDEX user (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;');
$this->addSql('CREATE TABLE portfolio_category (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, title LONGTEXT DEFAULT NULL, description LONGTEXT DEFAULT NULL, is_visible TINYINT(1) DEFAULT "1" NOT NULL, INDEX user (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;');
$this->addSql('CREATE TABLE portfolio (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, c_id INT DEFAULT NULL, session_id INT DEFAULT NULL, category_id INT DEFAULT NULL, title LONGTEXT NOT NULL, content LONGTEXT NOT NULL, creation_date DATETIME NOT NULL, update_date DATETIME NOT NULL, is_visible TINYINT(1) DEFAULT "1" NOT NULL, INDEX user (user_id), INDEX course (c_id), INDEX session (session_id), INDEX category (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;');
$this->addSql('ALTER TABLE portfolio_category ADD CONSTRAINT FK_7AC64359A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);');

@ -464,7 +464,7 @@ class MessageManager
return false;
} elseif ($totalFileSize > intval(api_get_setting('message_max_upload_filesize'))) {
$warning = sprintf(
get_lang("FilesSizeExceedsX"),
get_lang('FilesSizeExceedsX'),
format_file_size(api_get_setting('message_max_upload_filesize'))
);
@ -481,15 +481,14 @@ class MessageManager
//@todo it's possible to edit a message? yes, only for groups
if (!empty($editMessageId)) {
$query = " UPDATE $table SET
update_date = '".$now."',
content = '".Database::escape_string($content)."'
update_date = '".$now."',
content = '".Database::escape_string($content)."'
WHERE id = '$editMessageId' ";
Database::query($query);
$messageId = $editMessageId;
} else {
$params = [
'user_sender_id' => $user_sender_id,
'user_receiver_id' => $receiver_user_id,
'msg_status' => MESSAGE_STATUS_UNREAD,
'send_date' => $now,
'title' => $subject,
@ -498,6 +497,9 @@ class MessageManager
'parent_id' => $parent_id,
'update_date' => $now,
];
if (!empty($receiver_user_id)) {
$params['user_receiver_id'] = $receiver_user_id;
}
$messageId = Database::insert($table, $params);
}

@ -44,7 +44,7 @@ class Message
* @var User
*
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="receivedMessages")
* @ORM\JoinColumn(name="user_receiver_id", referencedColumnName="id", nullable=false)
* @ORM\JoinColumn(name="user_receiver_id", referencedColumnName="id", nullable=true)
*/
protected $userReceiver;

Loading…
Cancel
Save