本文整理汇总了PHP中db::expr方法的典型用法代码示例。如果您正苦于以下问题:PHP db::expr方法的具体用法?PHP db::expr怎么用?PHP db::expr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db
的用法示例。
在下文中一共展示了db::expr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
// Get rid of old deleted/spam comments once in a while
db::build()->delete("comments")->where("state", "IN", array("deleted", "spam"))->where("updated", "<", db::expr("UNIX_TIMESTAMP() - 86400 * 7"))->execute();
// Redirect to the appropriate queue
url::redirect("admin/manage_comments/queue/unpublished");
}
示例2: index
public function index()
{
// Get rid of old deleted/spam comments once in a while
db::build()->delete("comments")->where("state", "IN", array("deleted", "spam"))->where("updated", "<", db::expr("UNIX_TIMESTAMP() - 86400 * 7"))->execute();
$view = new Admin_View("admin.html");
$view->content = new View("admin_manage_comments.html");
$view->content->menu = $this->_menu($this->_counts());
print $view;
}
示例3: install_creates_root_item_test
public function install_creates_root_item_test()
{
$max_right_ptr = ORM::factory("item")->select(db::expr("MAX(`right_ptr`) AS `right_ptr`"))->find()->right_ptr;
$root = ORM::factory('item')->find(1);
$this->assert_equal("Gallery", $root->title);
$this->assert_equal(1, $root->left_ptr);
$this->assert_equal($max_right_ptr, $root->right_ptr);
$this->assert_equal(0, $root->parent_id);
$this->assert_equal(1, $root->level);
}
示例4: index
/**
* Show a list of all available, running and finished tasks.
*/
public function index()
{
$query = db::build()->update("tasks")->set("state", "stalled")->where("done", "=", 0)->where("state", "<>", "stalled")->where(db::expr("UNIX_TIMESTAMP(NOW()) - `updated` > 15"))->execute();
$stalled_count = $query->count();
if ($stalled_count) {
log::warning("tasks", t2("One task is stalled", "%count tasks are stalled", $stalled_count), t('<a href="%url">view</a>', array("url" => html::mark_clean(url::site("admin/maintenance")))));
}
$view = new Admin_View("admin.html");
$view->page_title = t("Maintenance tasks");
$view->content = new View("admin_maintenance.html");
$view->content->task_definitions = task::get_definitions();
$view->content->running_tasks = ORM::factory("task")->where("done", "=", 0)->order_by("updated", "DESC")->find_all();
$view->content->finished_tasks = ORM::factory("task")->where("done", "=", 1)->order_by("updated", "DESC")->find_all();
print $view;
// Do some maintenance while we're in here
db::build()->delete("caches")->where("expiration", "<>", 0)->where("expiration", "<=", time())->execute();
}
示例5: incr_var
/**
* Increment the value of a variable for this module
*
* Note: Frequently updating counters is very inefficient because it invalidates the cache value
* which has to be rebuilt every time we make a change.
*
* @todo Get rid of this and find an alternate approach for all callers (currently only Akismet)
*
* @deprecated
* @param string $module_name
* @param string $name
* @param string $increment (optional, default is 1)
*/
static function incr_var($module_name, $name, $increment = 1)
{
db::build()->update("vars")->set("value", db::expr("`value` + {$increment}"))->where("module_name", "=", $module_name)->where("name", "=", $name)->execute();
Cache::instance()->delete("var_cache");
self::$var_cache = null;
}
示例6: upgrade
//.........这里部分代码省略.........
block_manager::set_active($location, $new_blocks);
}
module::set_version("gallery", $version = 18);
}
// Rename blocks_site.sidebar to blocks_site_sidebar
if ($version == 18) {
$blocks = block_manager::get_active("site.sidebar");
block_manager::set_active("site_sidebar", $blocks);
module::clear_var("gallery", "blocks_site.sidebar");
module::set_version("gallery", $version = 19);
}
// Set a default for the number of simultaneous uploads
// Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
if ($version == 19 || $version == 20) {
module::set_var("gallery", "simultaneous_upload_limit", 5);
module::set_version("gallery", $version = 21);
}
// Update the graphics rules table so that the maximum height for resizes is 640 not 480.
// Fixes ticket #671
if ($version == 21) {
$resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
// make sure it hasn't been changed already
$args = unserialize($resize_rule->args);
if ($args["height"] == 480 && $args["width"] == 640) {
$args["height"] = 640;
$resize_rule->args = serialize($args);
$resize_rule->save();
}
module::set_version("gallery", $version = 22);
}
// Update slug values to be legal. We should have done this in the 11->12 upgrader, but I was
// lazy. Mea culpa!
if ($version == 22) {
foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
$new_slug = item::convert_filename_to_slug($row->slug);
if (empty($new_slug)) {
$new_slug = random::int();
}
db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
}
module::set_version("gallery", $version = 23);
}
if ($version == 23) {
$db->query("CREATE TABLE {failed_logins} (\n `id` int(9) NOT NULL auto_increment,\n `count` int(9) NOT NULL,\n `name` varchar(255) NOT NULL,\n `time` int(9) NOT NULL,\n PRIMARY KEY (`id`))\n DEFAULT CHARSET=utf8;");
module::set_version("gallery", $version = 24);
}
if ($version == 24) {
foreach (array("logs", "tmp", "uploads") as $dir) {
self::_protect_directory(VARPATH . $dir);
}
module::set_version("gallery", $version = 25);
}
if ($version == 25) {
db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
module::set_version("gallery", $version = 26);
}
if ($version == 26) {
if (in_array("failed_logins", Database::instance()->list_tables())) {
$db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
}
module::set_version("gallery", $version = 27);
}
if ($version == 27) {
// Set the admin area timeout to 90 minutes
module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_version("gallery", $version = 28);
示例7: upgrade
//.........这里部分代码省略.........
block_manager::set_active($location, $new_blocks);
}
module::set_version("gallery", $version = 18);
}
// Rename blocks_site.sidebar to blocks_site_sidebar
if ($version == 18) {
$blocks = block_manager::get_active("site.sidebar");
block_manager::set_active("site_sidebar", $blocks);
module::clear_var("gallery", "blocks_site.sidebar");
module::set_version("gallery", $version = 19);
}
// Set a default for the number of simultaneous uploads
// Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
if ($version == 19 || $version == 20) {
module::set_var("gallery", "simultaneous_upload_limit", 5);
module::set_version("gallery", $version = 21);
}
// Update the graphics rules table so that the maximum height for resizes is 640 not 480.
// Fixes ticket #671
if ($version == 21) {
$resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
// make sure it hasn't been changed already
$args = unserialize($resize_rule->args);
if ($args["height"] == 480 && $args["width"] == 640) {
$args["height"] = 640;
$resize_rule->args = serialize($args);
$resize_rule->save();
}
module::set_version("gallery", $version = 22);
}
// Update slug values to be legal. We should have done this in the 11->12 upgrader, but I was
// lazy. Mea culpa!
if ($version == 22) {
foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
$new_slug = item::convert_filename_to_slug($row->slug);
if (empty($new_slug)) {
$new_slug = random::int();
}
db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
}
module::set_version("gallery", $version = 23);
}
if ($version == 23) {
$db->query("CREATE TABLE {failed_logins} (\n `id` int(9) NOT NULL auto_increment,\n `count` int(9) NOT NULL,\n `name` varchar(255) NOT NULL,\n `time` int(9) NOT NULL,\n PRIMARY KEY (`id`))\n DEFAULT CHARSET=utf8;");
module::set_version("gallery", $version = 24);
}
if ($version == 24) {
foreach (array("logs", "tmp", "uploads") as $dir) {
self::_protect_directory(VARPATH . $dir);
}
module::set_version("gallery", $version = 25);
}
if ($version == 25) {
db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
module::set_version("gallery", $version = 26);
}
if ($version == 26) {
if (in_array("failed_logins", Database::instance()->list_tables())) {
$db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
}
module::set_version("gallery", $version = 27);
}
if ($version == 27) {
// Set the admin area timeout to 90 minutes
module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_version("gallery", $version = 28);
示例8: _clean_expired
private function _clean_expired()
{
db::build()->delete("digibug_proxies")->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 90 DAY)"))->limit(20)->execute();
}
示例9: rearrange
function rearrange()
{
access::verify_csrf();
$input = Input::instance();
$target = ORM::factory("item", $input->post("target_id"));
if (!$target->loaded()) {
json::reply(null);
return;
}
$album = $target->parent();
access::required("edit", $album);
if ($album->sort_column != "weight") {
// Force all the weights into the current order before changing the order to manual
$weight = 0;
foreach ($album->children() as $child) {
$child->weight = ++$weight;
$child->save();
}
$album->sort_column = "weight";
$album->sort_order = "ASC";
$album->save();
}
$source_ids = explode(",", $input->post("source_ids"));
$base_weight = $target->weight;
if ($input->post("relative") == "after") {
$base_weight++;
}
if ($source_ids) {
// Make a hole the right size
db::build()->update("items")->set("weight", db::expr("`weight` + " . count($source_ids)))->where("parent_id", "=", $album->id)->where("weight", ">=", $base_weight)->execute();
// Move all the source items to the right spots.
for ($i = 0; $i < count($source_ids); $i++) {
$source = ORM::factory("item", $source_ids[$i]);
if ($source->parent_id = $album->id) {
$source->weight = $base_weight + $i;
$source->save();
}
}
}
json::reply(null);
}
示例10: move_to
/**
* Move this item to the specified target.
*
* @chainable
* @param Item_Model $target Target node
* @return ORM_MTPP
*/
protected function move_to($target)
{
if ($this->contains($target)) {
throw new Exception("@todo INVALID_TARGET can't move item inside itself");
}
$this->lock();
$this->reload();
// Assume that the prior lock holder may have changed this entry
$target->reload();
$number_to_move = (int) (($this->right_ptr - $this->left_ptr) / 2 + 1);
$size_of_hole = $number_to_move * 2;
$original_left_ptr = $this->left_ptr;
$original_right_ptr = $this->right_ptr;
$target_right_ptr = $target->right_ptr;
$level_delta = $target->level + 1 - $this->level;
try {
if ($level_delta) {
// Update the levels for the to-be-moved items
db::build()->update($this->table_name)->set("level", db::expr("`level` + {$level_delta}"))->where("left_ptr", ">=", $original_left_ptr)->where("right_ptr", "<=", $original_right_ptr)->execute();
}
// Make a hole in the target for the move
db::build()->update($this->table_name)->set("left_ptr", db::expr("`left_ptr` + {$size_of_hole}"))->where("left_ptr", ">=", $target_right_ptr)->execute();
db::build()->update($this->table_name)->set("right_ptr", db::expr("`right_ptr` + {$size_of_hole}"))->where("right_ptr", ">=", $target_right_ptr)->execute();
// Change the parent.
db::build()->update($this->table_name)->set("parent_id", $target->id)->where("id", "=", $this->id)->execute();
// If the source is to the right of the target then we just adjusted its left_ptr and
// right_ptr above.
$left_ptr = $original_left_ptr;
$right_ptr = $original_right_ptr;
if ($original_left_ptr > $target_right_ptr) {
$left_ptr += $size_of_hole;
$right_ptr += $size_of_hole;
}
$new_offset = $target->right_ptr - $left_ptr;
db::build()->update($this->table_name)->set("left_ptr", db::expr("`left_ptr` + {$new_offset}"))->set("right_ptr", db::expr("`right_ptr` + {$new_offset}"))->where("left_ptr", ">=", $left_ptr)->where("right_ptr", "<=", $right_ptr)->execute();
// Close the hole in the source's parent after the move
db::build()->update($this->table_name)->set("left_ptr", db::expr("`left_ptr` - {$size_of_hole}"))->where("left_ptr", ">", $right_ptr)->execute();
db::build()->update($this->table_name)->set("right_ptr", db::expr("`right_ptr` - {$size_of_hole}"))->where("right_ptr", ">", $right_ptr)->execute();
} catch (Exception $e) {
$this->unlock();
throw $e;
}
$this->unlock();
// Lets reload to get the changes.
$this->reload();
$target->reload();
return $this;
}
示例11: find_dirty
public function find_dirty()
{
$gravity = module::get_var('emboss', 'gravity');
$transparency = module::get_var('emboss', 'transparency');
$q = db::build()->select()->from('emboss_mappings')->or_where('cur_overlay_id', '!=', db::expr('best_overlay_id'))->or_where('cur_gravity', '!=', $gravity)->or_where('cur_transparency', '!=', $transparency)->execute();
return $q;
}
示例12: clear_all
/**
* Delete all tags associated with an item
*/
static function clear_all($item)
{
db::build()->update("tags")->set("count", db::expr("`count` - 1"))->where("count", ">", 0)->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id))->execute();
db::build()->delete("items_tags")->where("item_id", "=", $item->id)->execute();
}
示例13: send_pending_notifications
static function send_pending_notifications()
{
foreach (db::build()->select(db::expr("DISTINCT `email`"))->from("pending_notifications")->execute() as $row) {
$email = $row->email;
$result = ORM::factory("pending_notification")->where("email", "=", $email)->find_all();
if ($result->count() == 1) {
$pending = $result->current();
Sendmail::factory()->to($email)->subject($pending->subject)->header("Mime-Version", "1.0")->header("Content-Type", "text/html; charset=UTF-8")->message($pending->body)->send();
$pending->delete();
} else {
$text = "";
$locale = null;
foreach ($result as $pending) {
$text .= $pending->text;
$locale = $pending->locale;
$pending->delete();
}
Sendmail::factory()->to($email)->subject(t("New activity for %site_name", array("site_name" => item::root()->title, "locale" => $locale)))->header("Mime-Version", "1.0")->header("Content-Type", "text/html; charset=UTF-8")->message($text)->send();
}
}
}
示例14: find_dupe_names
static function find_dupe_names()
{
return db::build()->select_distinct(array("parent_name" => db::expr("CONCAT(`parent_id`, ':', LOWER(`name`))")))->select("id")->select(array("C" => "COUNT(\"*\")"))->from("items")->where("type", "<>", "album")->having("C", ">", 1)->group_by("parent_name")->execute();
}
示例15: find_dupe_base_names
static function find_dupe_base_names()
{
// looking for photos or movies, not albums
return db::build()->select_distinct(array("parent_base_name" => db::expr("CONCAT(`parent_id`, ':', LOWER(SUBSTR(`name`, 1, LOCATE('.', `name`) - 1)))")))->select("id")->select(array("C" => "COUNT(\"*\")"))->from("items")->where("type", "<>", "album")->having("C", ">", 1)->group_by("parent_base_name")->execute();
}