Closed #46
This commit is contained in:
parent
ff3e4bc287
commit
6b55706fb4
5 changed files with 34 additions and 14 deletions
|
@ -680,7 +680,7 @@ class PostController
|
||||||
->innerJoin('tag')
|
->innerJoin('tag')
|
||||||
->on('post_tag.tag_id = tag.id')
|
->on('post_tag.tag_id = tag.id')
|
||||||
->where('post_id = post.id')
|
->where('post_id = post.id')
|
||||||
->and('tag.name = ?')->put($val)
|
->and('LOWER(tag.name) = LOWER(?)')->put($val)
|
||||||
->close();
|
->close();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
class Model_Comment extends RedBean_SimpleModel
|
class Model_Comment extends RedBean_SimpleModel
|
||||||
{
|
{
|
||||||
public static function locate($key)
|
public static function locate($key, $throw = true)
|
||||||
{
|
{
|
||||||
$comment = R::findOne('comment', 'id = ?', [$key]);
|
$comment = R::findOne('comment', 'id = ?', [$key]);
|
||||||
if (!$comment)
|
if (!$comment)
|
||||||
|
{
|
||||||
|
if ($throw)
|
||||||
throw new SimpleException('Invalid comment ID "' . $key . '"');
|
throw new SimpleException('Invalid comment ID "' . $key . '"');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
class Model_Post extends RedBean_SimpleModel
|
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)
|
if (is_numeric($key) and !$disallowNumeric)
|
||||||
{
|
{
|
||||||
$post = R::findOne('post', 'id = ?', [$key]);
|
$post = R::findOne('post', 'id = ?', [$key]);
|
||||||
if (!$post)
|
if (!$post)
|
||||||
|
{
|
||||||
|
if ($throw)
|
||||||
throw new SimpleException('Invalid post ID "' . $key . '"');
|
throw new SimpleException('Invalid post ID "' . $key . '"');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$post = R::findOne('post', 'name = ?', [$key]);
|
$post = R::findOne('post', 'name = ?', [$key]);
|
||||||
if (!$post)
|
if (!$post)
|
||||||
|
{
|
||||||
|
if ($throw)
|
||||||
throw new SimpleException('Invalid post name "' . $key . '"');
|
throw new SimpleException('Invalid post name "' . $key . '"');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
class Model_Tag extends RedBean_SimpleModel
|
class Model_Tag extends RedBean_SimpleModel
|
||||||
{
|
{
|
||||||
public static function locate($key)
|
public static function locate($key, $throw = true)
|
||||||
{
|
{
|
||||||
$user = R::findOne('tag', 'name = ?', [$key]);
|
$tag = R::findOne('tag', 'LOWER(name) = LOWER(?)', [$key]);
|
||||||
if (!$user)
|
if (!$tag)
|
||||||
|
{
|
||||||
|
if ($throw)
|
||||||
throw new SimpleException('Invalid tag name "' . $key . '"');
|
throw new SimpleException('Invalid tag name "' . $key . '"');
|
||||||
return $user;
|
return null;
|
||||||
|
}
|
||||||
|
return $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function insertOrUpdate($tags)
|
public static function insertOrUpdate($tags)
|
||||||
|
@ -14,7 +18,7 @@ class Model_Tag extends RedBean_SimpleModel
|
||||||
$dbTags = [];
|
$dbTags = [];
|
||||||
foreach ($tags as $tag)
|
foreach ($tags as $tag)
|
||||||
{
|
{
|
||||||
$dbTag = R::findOne('tag', 'name = ?', [$tag]);
|
$dbTag = self::locate($tag, false);
|
||||||
if (!$dbTag)
|
if (!$dbTag)
|
||||||
{
|
{
|
||||||
$dbTag = R::dispense('tag');
|
$dbTag = R::dispense('tag');
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
class Model_User extends RedBean_SimpleModel
|
class Model_User extends RedBean_SimpleModel
|
||||||
{
|
{
|
||||||
public static function locate($key)
|
public static function locate($key, $throw = true)
|
||||||
{
|
{
|
||||||
$user = R::findOne('user', 'name = ?', [$key]);
|
$user = R::findOne('user', 'name = ?', [$key]);
|
||||||
if (!$user)
|
if (!$user)
|
||||||
|
{
|
||||||
|
if ($throw)
|
||||||
throw new SimpleException('Invalid user name "' . $key . '"');
|
throw new SimpleException('Invalid user name "' . $key . '"');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue