This commit is contained in:
Marcin Kurczewski 2013-10-21 14:32:47 +02:00
parent ff3e4bc287
commit 6b55706fb4
5 changed files with 34 additions and 14 deletions

View file

@ -680,7 +680,7 @@ class PostController
->innerJoin('tag')
->on('post_tag.tag_id = tag.id')
->where('post_id = post.id')
->and('tag.name = ?')->put($val)
->and('LOWER(tag.name) = LOWER(?)')->put($val)
->close();
continue;
}

View file

@ -1,11 +1,15 @@
<?php
class Model_Comment extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$comment = R::findOne('comment', 'id = ?', [$key]);
if (!$comment)
throw new SimpleException('Invalid comment ID "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid comment ID "' . $key . '"');
return null;
}
return $comment;
}

View file

@ -1,19 +1,27 @@
<?php
class Model_Post extends RedBean_SimpleModel
{
public static function locate($key, $disallowNumeric = false)
public static function locate($key, $disallowNumeric = false, $throw = true)
{
if (is_numeric($key) and !$disallowNumeric)
{
$post = R::findOne('post', 'id = ?', [$key]);
if (!$post)
throw new SimpleException('Invalid post ID "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid post ID "' . $key . '"');
return null;
}
}
else
{
$post = R::findOne('post', 'name = ?', [$key]);
if (!$post)
throw new SimpleException('Invalid post name "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid post name "' . $key . '"');
return null;
}
}
return $post;
}

View file

@ -1,12 +1,16 @@
<?php
class Model_Tag extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$user = R::findOne('tag', 'name = ?', [$key]);
if (!$user)
throw new SimpleException('Invalid tag name "' . $key . '"');
return $user;
$tag = R::findOne('tag', 'LOWER(name) = LOWER(?)', [$key]);
if (!$tag)
{
if ($throw)
throw new SimpleException('Invalid tag name "' . $key . '"');
return null;
}
return $tag;
}
public static function insertOrUpdate($tags)
@ -14,7 +18,7 @@ class Model_Tag extends RedBean_SimpleModel
$dbTags = [];
foreach ($tags as $tag)
{
$dbTag = R::findOne('tag', 'name = ?', [$tag]);
$dbTag = self::locate($tag, false);
if (!$dbTag)
{
$dbTag = R::dispense('tag');

View file

@ -1,11 +1,15 @@
<?php
class Model_User extends RedBean_SimpleModel
{
public static function locate($key)
public static function locate($key, $throw = true)
{
$user = R::findOne('user', 'name = ?', [$key]);
if (!$user)
throw new SimpleException('Invalid user name "' . $key . '"');
{
if ($throw)
throw new SimpleException('Invalid user name "' . $key . '"');
return null;
}
return $user;
}