Skip to content
Snippets Groups Projects
Commit 956957c1 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

fix for BIESt #1077

Merge request studip/studip!645
parent cb8947e7
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,8 @@ class BlubberController extends AuthenticatedController ...@@ -9,6 +9,8 @@ class BlubberController extends AuthenticatedController
parent::before_filter($action, $args); parent::before_filter($action, $args);
PageLayout::setTitle(_('Blubber')); PageLayout::setTitle(_('Blubber'));
$this->threads_more_down = 0;
} }
public function index_action($thread_id = null) public function index_action($thread_id = null)
......
...@@ -18,6 +18,8 @@ class Course_MessengerController extends AuthenticatedController ...@@ -18,6 +18,8 @@ class Course_MessengerController extends AuthenticatedController
} }
$this->threads = BlubberThread::findByContext(Context::get()->id, true, Context::getType()); $this->threads = BlubberThread::findByContext(Context::get()->id, true, Context::getType());
$this->thread = null;
$this->threads_more_down = 0;
if (!$thread_id) { if (!$thread_id) {
$thread_id = $GLOBALS['user']->cfg->BLUBBER_DEFAULT_THREAD; $thread_id = $GLOBALS['user']->cfg->BLUBBER_DEFAULT_THREAD;
......
...@@ -7,7 +7,9 @@ class BlubberFormat extends StudipFormat ...@@ -7,7 +7,9 @@ class BlubberFormat extends StudipFormat
private static $blubber_rules = [ private static $blubber_rules = [
'hashtags' => [ 'hashtags' => [
'start' => self::REGEXP_HASHTAG, 'start' => self::REGEXP_HASHTAG,
'callback' => 'BlubberFormat::markupHashtags' 'end' => '',
'callback' => 'BlubberFormat::markupHashtags',
'before' => null
] ]
]; ];
......
...@@ -110,12 +110,12 @@ class Config implements ArrayAccess, Countable, IteratorAggregate ...@@ -110,12 +110,12 @@ class Config implements ArrayAccess, Countable, IteratorAggregate
/** /**
* returns metadata for config entry * returns metadata for config entry
* @param srting $field * @param string $field
* @return array * @return array
*/ */
public function getMetadata($field) public function getMetadata($field)
{ {
return $this->metadata[$field]; return $this->metadata[$field] ?? [];
} }
/** /**
......
...@@ -175,7 +175,7 @@ class RangeConfig extends Config ...@@ -175,7 +175,7 @@ class RangeConfig extends Config
// Otherwise convert it to an appropriate format and store it // Otherwise convert it to an appropriate format and store it
$metadata = Config::get()->getMetadata($field); $metadata = Config::get()->getMetadata($field);
$entry->value = $this->convertForDatabase($metadata['type'], $value, $field); $entry->value = $this->convertForDatabase($metadata['type'] ?? 'string', $value, $field);
$ret = $entry->store(); $ret = $entry->store();
if ($ret) { if ($ret) {
......
...@@ -22,10 +22,20 @@ ...@@ -22,10 +22,20 @@
*/ */
class SQLQuery class SQLQuery
{ {
public $settings = ['joins' => []]; public $settings = [
public $name = null; 'table' => '',
'select' => [],
'joins' => [],
'where' => [],
'parameter' => [],
'having' => [],
'order' => '',
'limit' => []
];
public static function table($table, $query_name = null) public $name = '';
public static function table(string $table, string $query_name = '')
{ {
$query = new self($table, $query_name); $query = new self($table, $query_name);
return $query; return $query;
...@@ -36,7 +46,7 @@ class SQLQuery ...@@ -36,7 +46,7 @@ class SQLQuery
* @param string $table : a database table * @param string $table : a database table
* @param string name : * @param string name :
*/ */
public function __construct($table, $query_name = null) public function __construct(string $table, string $query_name = '')
{ {
$this->settings['table'] = $table; $this->settings['table'] = $table;
$this->name = $query_name; $this->name = $query_name;
...@@ -95,12 +105,12 @@ class SQLQuery ...@@ -95,12 +105,12 @@ class SQLQuery
unset($this->settings['where'][$name]); unset($this->settings['where'][$name]);
} elseif ($parameter === null && $condition !== null) { } elseif ($parameter === null && $condition !== null) {
$this->settings['where'][$name] = $name; $this->settings['where'][$name] = $name;
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $condition); $this->settings['parameter'] = array_merge($this->settings['parameter'], $condition);
} elseif ($condition === null) { } elseif ($condition === null) {
$this->settings['where'][md5($name)] = $name; $this->settings['where'][md5($name)] = $name;
} else { } else {
$this->settings['where'][$name] = $condition; $this->settings['where'][$name] = $condition;
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $parameter); $this->settings['parameter'] = array_merge($this->settings['parameter'], $parameter);
} }
return $this; return $this;
} }
...@@ -111,12 +121,12 @@ class SQLQuery ...@@ -111,12 +121,12 @@ class SQLQuery
unset($this->settings['having'][$name]); unset($this->settings['having'][$name]);
} elseif ($parameter === null && $condition !== null) { } elseif ($parameter === null && $condition !== null) {
$this->settings['having'][$name] = $name; $this->settings['having'][$name] = $name;
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $condition); $this->settings['parameter'] = array_merge($this->settings['parameter'], $condition);
} elseif ($condition === null) { } elseif ($condition === null) {
$this->settings['having'][md5($name)] = $name; $this->settings['having'][md5($name)] = $name;
} else { } else {
$this->settings['having'][$name] = $condition; $this->settings['having'][$name] = $condition;
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $parameter); $this->settings['parameter'] = array_merge($this->settings['parameter'], $parameter);
} }
return $this; return $this;
} }
...@@ -129,7 +139,7 @@ class SQLQuery ...@@ -129,7 +139,7 @@ class SQLQuery
public function parameter($param, $value = null) public function parameter($param, $value = null)
{ {
if (is_array($param)) { if (is_array($param)) {
$this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $param); $this->settings['parameter'] = array_merge($this->settings['parameter'], $param);
} else { } else {
$this->settings['parameter'][$param] = $value; $this->settings['parameter'][$param] = $value;
} }
...@@ -196,7 +206,7 @@ class SQLQuery ...@@ -196,7 +206,7 @@ class SQLQuery
{$this->getQuery()} {$this->getQuery()}
) AS counter_table"; ) AS counter_table";
$statement = DBManager::get()->prepare($sql); $statement = DBManager::get()->prepare($sql);
$statement->execute((array) $this->settings['parameter']); $statement->execute($this->settings['parameter']);
NotificationCenter::postNotification('SQLQueryDidExecute', $this); NotificationCenter::postNotification('SQLQueryDidExecute', $this);
return (int) $statement->fetchColumn(); return (int) $statement->fetchColumn();
...@@ -218,7 +228,7 @@ class SQLQuery ...@@ -218,7 +228,7 @@ class SQLQuery
$sql = "SELECT `{$this->settings['table']}`.* "; $sql = "SELECT `{$this->settings['table']}`.* ";
} }
foreach ((array) $this->settings['select'] as $alias => $statement) { foreach ($this->settings['select'] as $alias => $statement) {
$sql .= $statement ? "{$statement} AS {$alias} " : $alias; $sql .= $statement ? "{$statement} AS {$alias} " : $alias;
} }
......
...@@ -921,7 +921,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject ...@@ -921,7 +921,7 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
'user_id' => $user_id, 'user_id' => $user_id,
'html_id' => "blubberthread_".$this->getId() 'html_id' => "blubberthread_".$this->getId()
]); ]);
$this->last_visit[$user_id] = !$this->last_visit[$user_id] $this->last_visit[$user_id] = empty($this->last_visit[$user_id])
? object_get_visit($this->getId(), "blubberthread", "last", "", $user_id) ? object_get_visit($this->getId(), "blubberthread", "last", "", $user_id)
: $this->last_visit[$user_id]; : $this->last_visit[$user_id];
UserConfig::get($user_id)->store("BLUBBERTHREAD_VISITED_".$this->getId(), time()); UserConfig::get($user_id)->store("BLUBBERTHREAD_VISITED_".$this->getId(), time());
......
...@@ -1819,6 +1819,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate ...@@ -1819,6 +1819,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
if ($this->applyCallbacks('before_store') === false) { if ($this->applyCallbacks('before_store') === false) {
return false; return false;
} }
$ret = 0;
if (!$this->isDeleted() && ($this->isDirty() || $this->isNew())) { if (!$this->isDeleted() && ($this->isDirty() || $this->isNew())) {
if ($this->isNew()) { if ($this->isNew()) {
if ($this->applyCallbacks('before_create') === false) { if ($this->applyCallbacks('before_create') === false) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment