Browse Source

Merge remote-tracking branch 'upstream/develop' into 1701-poco

Conflicts:
	include/socgraph.php
pull/3246/head
Michael 4 years ago
parent
commit
7f61b2ee15
52 changed files with 1559 additions and 1749 deletions
  1. +24
    -91
      boot.php
  2. +64
    -76
      database.sql
  3. +3
    -3
      include/Contact.php
  4. +0
    -22
      include/create_shadowentry.php
  5. +21
    -88
      include/cron.php
  6. +5
    -37
      include/cronhooks.php
  7. +1
    -36
      include/cronjobs.php
  8. +1
    -1
      include/datetime.php
  9. +198
    -122
      include/dba.php
  10. +4
    -31
      include/dbclean.php
  11. +2
    -9
      include/dbm.php
  12. +69
    -78
      include/dbstructure.php
  13. +2
    -22
      include/dbupdate.php
  14. +5
    -53
      include/delivery.php
  15. +1
    -1
      include/dfrn.php
  16. +7
    -32
      include/directory.php
  17. +94
    -68
      include/discover_poco.php
  18. +1
    -25
      include/expire.php
  19. +3
    -30
      include/gprobe.php
  20. +1
    -1
      include/identity.php
  21. +2
    -1
      include/lock.php
  22. +3
    -2
      include/network.php
  23. +7
    -104
      include/notifier.php
  24. +4
    -35
      include/onepoll.php
  25. +36
    -25
      include/poller.php
  26. +24
    -72
      include/pubsubpublish.php
  27. +100
    -163
      include/queue.php
  28. +0
    -22
      include/remove_contact.php
  29. +1
    -1
      include/security.php
  30. +19
    -13
      include/shadowupdate.php
  31. +459
    -53
      include/socgraph.php
  32. +1
    -20
      include/spool_post.php
  33. +2
    -20
      include/tagupdate.php
  34. +3
    -3
      include/text.php
  35. +3
    -21
      include/threadupdate.php
  36. +5
    -8
      include/uimport.php
  37. +5
    -33
      include/update_gcontact.php
  38. +1
    -1
      library/Smarty/libs/plugins/modifier.date_format.php
  39. +181
    -175
      mod/admin.php
  40. +6
    -6
      mod/contacts.php
  41. +1
    -1
      mod/events.php
  42. +4
    -1
      mod/maintenance.php
  43. +121
    -91
      mod/poco.php
  44. +5
    -5
      mod/profiles.php
  45. +1
    -1
      mod/settings.php
  46. +1
    -1
      mod/worker.php
  47. +23
    -23
      update.php
  48. +27
    -7
      util/maintenance.php
  49. +4
    -12
      view/templates/admin_site.tpl
  50. +1
    -1
      view/templates/admin_summary.tpl
  51. +2
    -1
      view/templates/maintenance.tpl
  52. +1
    -1
      view/theme/frio/js/textedit.js

+ 24
- 91
boot.php View File

@ -32,7 +32,6 @@ require_once('include/cache.php');
require_once('library/Mobile_Detect/Mobile_Detect.php');
require_once('include/features.php');
require_once('include/identity.php');
require_once('include/pidfile.php');
require_once('update.php');
require_once('include/dbstructure.php');
@ -40,7 +39,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.2-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1215 );
define ( 'DB_UPDATE_VERSION', 1216 );
/**
* @brief Constant with a HTML line break.
@ -442,10 +441,17 @@ define('SR_SCOPE_ALL', 'all');
define('SR_SCOPE_TAGS', 'tags');
/* @}*/
/**
* Lowest possible date time value
*/
define ('NULL_DATE', '0001-01-01 00:00:00');
// Normally this constant is defined - but not if "pcntl" isn't installed
if (!defined("SIGTERM"))
if (!defined("SIGTERM")) {
define("SIGTERM", 15);
}
/**
*
* Reverse the effect of magic_quotes_gpc if it is enabled.
@ -1346,60 +1352,25 @@ class App {
return false;
}
/**
* @brief Checks if the process is already running
*
* @param string $taskname The name of the task that will be used for the name of the lockfile
* @param string $task The path and name of the php script
* @param int $timeout The timeout after which a task should be killed
*
* @return bool Is the process running?
*/
function is_already_running($taskname, $task = "", $timeout = 540) {
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, $taskname);
if ($pidfile->is_already_running()) {
logger("Already running");
if ($pidfile->running_time() > $timeout) {
$pidfile->kill();
logger("killed stale process");
// Calling a new instance
if ($task != "")
proc_run(PRIORITY_MEDIUM, $task);
}
return true;
}
}
return false;
}
function proc_run($args) {
if (!function_exists("proc_open")) {
return;
}
// Add the php path if it is a php call
if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) {
// If the last worker fork was less than 10 seconds before then don't fork another one.
// This should prevent the forking of masses of workers.
if (get_config("system", "worker")) {
$cachekey = "app:proc_run:started";
$result = Cache::get($cachekey);
if (!is_null($result)) {
if ((time() - $result) < 10) {
return;
}
}
// Set the timestamp of the last proc_run
Cache::set($cachekey, time(), CACHE_MINUTE);
// If the last worker fork was less than 10 seconds before then don't fork another one.
// This should prevent the forking of masses of workers.
$cachekey = "app:proc_run:started";
$result = Cache::get($cachekey);
if (!is_null($result)) {
if ((time() - $result) < 10) {
return;
}
$args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
}
// Set the timestamp of the last proc_run
Cache::set($cachekey, time(), CACHE_MINUTE);
array_unshift($args, ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
// add baseurl to args. cli scripts can't construct it
$args[] = $this->get_baseurl();
@ -1976,10 +1947,9 @@ function get_max_import_size() {
* @brief Wrap calls to proc_close(proc_open()) and call hook
* so plugins can take part in process :)
*
* @param (string|integer|array) $cmd program to run, priority or parameter array
* @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
*
* next args are passed as $cmd command line
* e.g.: proc_run("ls","-la","/tmp");
* or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
* or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id);
*
@ -2024,11 +1994,6 @@ function proc_run($cmd){
if (!$arr['run_cmd'] OR !count($args))
return;
if (!get_config("system", "worker") OR (is_string($run_parameter) AND ($run_parameter != 'php'))) {
$a->proc_run($args);
return;
}
$priority = PRIORITY_MEDIUM;
$dont_fork = get_config("system", "worker_dont_fork");
@ -2063,7 +2028,7 @@ function proc_run($cmd){
}
// Checking number of workers
$workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
$workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` > '%s'", dbesc(NULL_DATE));
// Get number of allowed number of worker threads
$queues = intval(get_config("system", "worker_queues"));
@ -2076,7 +2041,7 @@ function proc_run($cmd){
return;
// Now call the poller to execute the jobs that we just added to the queue
$args = array("php", "include/poller.php", "no_cron");
$args = array("include/poller.php", "no_cron");
$a->proc_run($args);
}
@ -2410,38 +2375,6 @@ function get_itemcachepath() {
return "";
}
function get_lockpath() {
$lockpath = get_config('system','lockpath');
if (($lockpath != "") AND App::directory_usable($lockpath)) {
// We have a lock path and it is usable
return $lockpath;
}
// We don't have a working preconfigured lock path, so we take the temp path.
$temppath = get_temppath();
if ($temppath != "") {
// To avoid any interferences with other systems we create our own directory
$lockpath = $temppath."/lock";
if (!is_dir($lockpath)) {
mkdir($lockpath);
}
if (App::directory_usable($lockpath)) {
// The new path is usable, we are happy
set_config("system", "lockpath", $lockpath);
return $lockpath;
} else {
// We can't create a subdirectory, strange.
// But the directory seems to work, so we use it but don't store it.
return $temppath;
}
}
// Reaching this point means that the operating system is configured badly.
return "";
}
/**
* @brief Returns the path where spool files are stored
*


+ 64
- 76
database.sql View File

@ -1,5 +1,5 @@
-- ------------------------------------------
-- Friendica 3.5.1-rc (Asparagus)
-- Friendica 3.5.2-dev (Asparagus)
-- DB_UPDATE_VERSION 1215
-- ------------------------------------------
@ -30,8 +30,8 @@ CREATE TABLE IF NOT EXISTS `attach` (
`filetype` varchar(64) NOT NULL DEFAULT '',
`filesize` int(11) NOT NULL DEFAULT 0,
`data` longblob NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`allow_cid` mediumtext,
`allow_gid` mediumtext,
`deny_cid` mediumtext,
@ -58,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `cache` (
`k` varbinary(255) NOT NULL,
`v` mediumtext,
`expire_mode` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`k`),
INDEX `expire_mode_updated` (`expire_mode`,`updated`)
) DEFAULT CHARSET=utf8mb4;
@ -107,7 +107,7 @@ CREATE TABLE IF NOT EXISTS `config` (
CREATE TABLE IF NOT EXISTS `contact` (
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`self` tinyint(1) NOT NULL DEFAULT 0,
`remote_self` tinyint(1) NOT NULL DEFAULT 0,
`rel` tinyint(1) NOT NULL DEFAULT 0,
@ -145,14 +145,14 @@ CREATE TABLE IF NOT EXISTS `contact` (
`usehub` tinyint(1) NOT NULL DEFAULT 0,
`subhub` tinyint(1) NOT NULL DEFAULT 0,
`hub-verify` varchar(255) NOT NULL DEFAULT '',
`last-update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`success_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`failure_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`name-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`uri-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`avatar-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`term-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last-item` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last-update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`success_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`failure_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`name-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`uri-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`avatar-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`priority` tinyint(3) NOT NULL DEFAULT 0,
`blocked` tinyint(1) NOT NULL DEFAULT 1,
`readonly` tinyint(1) NOT NULL DEFAULT 0,
@ -197,25 +197,13 @@ CREATE TABLE IF NOT EXISTS `conv` (
`recips` text,
`uid` int(11) NOT NULL DEFAULT 0,
`creator` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`subject` text,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8mb4;
--
-- TABLE deliverq
--
CREATE TABLE IF NOT EXISTS `deliverq` (
`id` int(10) unsigned NOT NULL auto_increment,
`cmd` varbinary(32) NOT NULL DEFAULT '',
`item` int(11) NOT NULL DEFAULT 0,
`contact` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
UNIQUE INDEX `cmd_item_contact` (`cmd`,`item`,`contact`)
) DEFAULT CHARSET=utf8mb4;
--
-- TABLE event
--
@ -225,10 +213,10 @@ CREATE TABLE IF NOT EXISTS `event` (
`uid` int(11) NOT NULL DEFAULT 0,
`cid` int(11) NOT NULL DEFAULT 0,
`uri` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`start` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`finish` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`start` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`finish` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`summary` text,
`desc` text,
`location` text,
@ -264,7 +252,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`network` varchar(32) NOT NULL DEFAULT '',
`alias` varchar(255) NOT NULL DEFAULT '',
`pubkey` text,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
INDEX `addr` (`addr`(32)),
INDEX `url` (`url`)
@ -305,7 +293,7 @@ CREATE TABLE IF NOT EXISTS `fsuggest` (
`request` varchar(255) NOT NULL DEFAULT '',
`photo` varchar(255) NOT NULL DEFAULT '',
`note` text,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;
@ -332,10 +320,10 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
`nurl` varchar(255) NOT NULL DEFAULT '',
`photo` varchar(255) NOT NULL DEFAULT '',
`connect` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime DEFAULT '0000-00-00 00:00:00',
`last_contact` datetime DEFAULT '0000-00-00 00:00:00',
`last_failure` datetime DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`updated` datetime DEFAULT '0001-01-01 00:00:00',
`last_contact` datetime DEFAULT '0001-01-01 00:00:00',
`last_failure` datetime DEFAULT '0001-01-01 00:00:00',
`location` varchar(255) NOT NULL DEFAULT '',
`about` text,
`keywords` text,
@ -369,7 +357,7 @@ CREATE TABLE IF NOT EXISTS `glink` (
`uid` int(11) NOT NULL DEFAULT 0,
`gcid` int(11) NOT NULL DEFAULT 0,
`zcid` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`),
INDEX `gcid` (`gcid`)
@ -417,10 +405,10 @@ CREATE TABLE IF NOT EXISTS `gserver` (
`noscrape` varchar(255) NOT NULL DEFAULT '',
`network` varchar(32) NOT NULL DEFAULT '',
`platform` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_poco_query` datetime DEFAULT '0000-00-00 00:00:00',
`last_contact` datetime DEFAULT '0000-00-00 00:00:00',
`last_failure` datetime DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`last_poco_query` datetime DEFAULT '0001-01-01 00:00:00',
`last_contact` datetime DEFAULT '0001-01-01 00:00:00',
`last_failure` datetime DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
INDEX `nurl` (`nurl`(32))
) DEFAULT CHARSET=utf8mb4;
@ -450,7 +438,7 @@ CREATE TABLE IF NOT EXISTS `intro` (
`duplex` tinyint(1) NOT NULL DEFAULT 0,
`note` text,
`hash` varchar(255) NOT NULL DEFAULT '',
`datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`blocked` tinyint(1) NOT NULL DEFAULT 1,
`ignore` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
@ -473,11 +461,11 @@ CREATE TABLE IF NOT EXISTS `item` (
`parent-uri` varchar(255) NOT NULL DEFAULT '',
`extid` varchar(255) NOT NULL DEFAULT '',
`thr-parent` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`owner-id` int(11) NOT NULL DEFAULT 0,
`owner-name` varchar(255) NOT NULL DEFAULT '',
`owner-link` varchar(255) NOT NULL DEFAULT '',
@ -576,7 +564,7 @@ CREATE TABLE IF NOT EXISTS `locks` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(128) NOT NULL DEFAULT '',
`locked` tinyint(1) NOT NULL DEFAULT 0,
`created` datetime DEFAULT '0000-00-00 00:00:00',
`created` datetime DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;
@ -600,7 +588,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
`unknown` tinyint(1) NOT NULL DEFAULT 0,
`uri` varchar(255) NOT NULL DEFAULT '',
`parent-uri` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
INDEX `uid_seen` (`uid`,`seen`),
INDEX `convid` (`convid`),
@ -624,7 +612,7 @@ CREATE TABLE IF NOT EXISTS `mailacct` (
`action` int(11) NOT NULL DEFAULT 0,
`movetofolder` varchar(255) NOT NULL DEFAULT '',
`pubmail` tinyint(1) NOT NULL DEFAULT 0,
`last_check` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;
@ -649,7 +637,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
`name` varchar(255) NOT NULL DEFAULT '',
`url` varchar(255) NOT NULL DEFAULT '',
`photo` varchar(255) NOT NULL DEFAULT '',
`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`msg` mediumtext,
`uid` int(11) NOT NULL DEFAULT 0,
`link` varchar(255) NOT NULL DEFAULT '',
@ -685,7 +673,7 @@ CREATE TABLE IF NOT EXISTS `notify-threads` (
CREATE TABLE IF NOT EXISTS `oembed` (
`url` varbinary(255) NOT NULL,
`content` mediumtext,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`url`),
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8mb4;
@ -698,7 +686,7 @@ CREATE TABLE IF NOT EXISTS `parsed_url` (
`guessing` tinyint(1) NOT NULL DEFAULT 0,
`oembed` tinyint(1) NOT NULL DEFAULT 0,
`content` mediumtext,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`url`,`guessing`,`oembed`),
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8mb4;
@ -725,8 +713,8 @@ CREATE TABLE IF NOT EXISTS `photo` (
`contact-id` int(10) unsigned NOT NULL DEFAULT 0,
`guid` varchar(64) NOT NULL DEFAULT '',
`resource-id` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`title` varchar(255) NOT NULL DEFAULT '',
`desc` text,
`album` varchar(255) NOT NULL DEFAULT '',
@ -788,7 +776,7 @@ CREATE TABLE IF NOT EXISTS `poll_result` (
CREATE TABLE IF NOT EXISTS `process` (
`pid` int(10) unsigned NOT NULL,
`command` varbinary(32) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`pid`),
INDEX `command` (`command`)
) DEFAULT CHARSET=utf8mb4;
@ -814,7 +802,7 @@ CREATE TABLE IF NOT EXISTS `profile` (
`gender` varchar(32) NOT NULL DEFAULT '',
`marital` varchar(255) NOT NULL DEFAULT '',
`with` text,
`howlong` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`howlong` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`sexual` varchar(255) NOT NULL DEFAULT '',
`politic` varchar(255) NOT NULL DEFAULT '',
`religion` varchar(255) NOT NULL DEFAULT '',
@ -866,7 +854,7 @@ CREATE TABLE IF NOT EXISTS `push_subscriber` (
`topic` varchar(255) NOT NULL DEFAULT '',
`nickname` varchar(255) NOT NULL DEFAULT '',
`push` int(11) NOT NULL DEFAULT 0,
`last_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_update` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`secret` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;
@ -878,8 +866,8 @@ CREATE TABLE IF NOT EXISTS `queue` (
`id` int(11) NOT NULL auto_increment,
`cid` int(11) NOT NULL DEFAULT 0,
`network` varchar(32) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`last` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`content` mediumtext,
`batch` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
@ -896,7 +884,7 @@ CREATE TABLE IF NOT EXISTS `queue` (
CREATE TABLE IF NOT EXISTS `register` (
`id` int(11) unsigned NOT NULL auto_increment,
`hash` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`uid` int(11) unsigned NOT NULL DEFAULT 0,
`password` varchar(255) NOT NULL DEFAULT '',
`language` varchar(16) NOT NULL DEFAULT '',
@ -950,7 +938,7 @@ CREATE TABLE IF NOT EXISTS `spam` (
`spam` int(11) NOT NULL DEFAULT 0,
`ham` int(11) NOT NULL DEFAULT 0,
`term` varchar(255) NOT NULL DEFAULT '',
`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `spam` (`spam`),
@ -969,8 +957,8 @@ CREATE TABLE IF NOT EXISTS `term` (
`term` varchar(255) NOT NULL DEFAULT '',
`url` varchar(255) NOT NULL DEFAULT '',
`guid` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`global` tinyint(1) NOT NULL DEFAULT 0,
`aid` int(10) unsigned NOT NULL DEFAULT 0,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
@ -991,11 +979,11 @@ CREATE TABLE IF NOT EXISTS `thread` (
`gcontact-id` int(11) unsigned NOT NULL DEFAULT 0,
`owner-id` int(11) unsigned NOT NULL DEFAULT 0,
`author-id` int(11) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`wall` tinyint(1) NOT NULL DEFAULT 0,
`private` tinyint(1) NOT NULL DEFAULT 0,
`pubmail` tinyint(1) NOT NULL DEFAULT 0,
@ -1047,8 +1035,8 @@ CREATE TABLE IF NOT EXISTS `user` (
`openid` varchar(255) NOT NULL DEFAULT '',
`timezone` varchar(128) NOT NULL DEFAULT '',
`language` varchar(32) NOT NULL DEFAULT 'en',
`register_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`login_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`default-location` varchar(255) NOT NULL DEFAULT '',
`allow_location` tinyint(1) NOT NULL DEFAULT 0,
`theme` varchar(255) NOT NULL DEFAULT '',
@ -1072,8 +1060,8 @@ CREATE TABLE IF NOT EXISTS `user` (
`expire` int(11) unsigned NOT NULL DEFAULT 0,
`account_removed` tinyint(1) NOT NULL DEFAULT 0,
`account_expired` tinyint(1) NOT NULL DEFAULT 0,
`account_expires_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`expire_notification_sent` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`service_class` varchar(32) NOT NULL DEFAULT '',
`def_gid` int(11) NOT NULL DEFAULT 0,
`allow_cid` mediumtext,
@ -1102,9 +1090,9 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
`id` int(11) NOT NULL auto_increment,
`parameter` text,
`priority` tinyint(3) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`pid` int(11) NOT NULL DEFAULT 0,
`executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8mb4;

+ 3
- 3
include/Contact.php View File

@ -127,7 +127,7 @@ function mark_for_death($contact) {
if($contact['archive'])
return;
if($contact['term-date'] == '0000-00-00 00:00:00') {
if ($contact['term-date'] <= NULL_DATE) {
q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()),
intval($contact['id'])
@ -185,13 +185,13 @@ function unmark_for_death($contact) {
// It's a miracle. Our dead contact has inexplicably come back to life.
q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
dbesc('0000-00-00 00:00:00'),
dbesc(NULL_DATE),
intval($contact['id'])
);
if ($contact['url'] != '') {
q("UPDATE `contact` SET `term-date` = '%s' WHERE `nurl` = '%s'",
dbesc('0000-00-00 00:00:00'),
dbesc(NULL_DATE),
dbesc(normalise_link($contact['url']))
);
}


+ 0
- 22
include/create_shadowentry.php View File

@ -6,26 +6,9 @@
* This script is started from mod/item.php to save some time when doing a post.
*/
use \Friendica\Core\Config;
require_once("boot.php");
require_once("include/threads.php");
function create_shadowentry_run($argv, $argc) {
global $a, $db;
if (is_null($a))
$a = new App;
if (is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
Config::load();
if ($argc != 2) {
return;
}
@ -34,9 +17,4 @@ function create_shadowentry_run($argv, $argc) {
add_shadow_entry($message_id);
}
if (array_search(__file__,get_included_files())===0){
create_shadowentry_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}
?>

+ 21
- 88
include/cron.php View File

@ -1,35 +1,11 @@
<?php
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
$directory = dirname($_SERVER["argv"][0]);
if (substr($directory, 0, 1) != "/")
$directory = $_SERVER["PWD"]."/".$directory;
$directory = realpath($directory."/..");
chdir($directory);
}
use \Friendica\Core\Config;
require_once("boot.php");
require_once("include/photos.php");
require_once("include/user.php");
require_once('include/photos.php');
require_once('include/user.php');
function cron_run(&$argv, &$argc){
global $a, $db;
if(is_null($a)) {
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
global $a;
require_once('include/session.php');
require_once('include/datetime.php');
@ -40,16 +16,6 @@ function cron_run(&$argv, &$argc){
require_once('mod/nodeinfo.php');
require_once('include/post_update.php');
Config::load();
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if ($a->maxload_reached())
return;
if (App::is_already_running('cron', 'include/cron.php', 540))
return;
}
$last = get_config('system','last_cron');
$poll_interval = intval(get_config('system','cron_interval'));
@ -64,10 +30,6 @@ function cron_run(&$argv, &$argc){
}
}
$a->set_baseurl(get_config('system','url'));
load_hooks();
logger('cron: start');
// run queue delivery process in the background
@ -85,34 +47,17 @@ function cron_run(&$argv, &$argc){
// Expire and remove user entries
cron_expire_and_remove_users();
// If the worker is active, split the jobs in several sub processes
if (get_config("system", "worker")) {
// Check OStatus conversations
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
// Check every conversation
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
// Call possible post update functions
proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
// Check OStatus conversations
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
// update nodeinfo data
proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
} else {
// Check OStatus conversations
// Check only conversations with mentions (for a longer time)
ostatus::check_conversations(true);
// Check every conversation
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
// Check every conversation
ostatus::check_conversations(false);
// Call possible post update functions
proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
// Call possible post update functions
// see include/post_update.php for more details
post_update();
// update nodeinfo data
nodeinfo_cron();
}
// update nodeinfo data
proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
// once daily run birthday_updates and then expire in background
@ -123,6 +68,8 @@ function cron_run(&$argv, &$argc){
update_contact_birthdays();
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
set_config('system','last_expire_day',$d2);
@ -173,8 +120,8 @@ function cron_update_photo_albums() {
function cron_expire_and_remove_users() {
// expire any expired accounts
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
AND `account_expires_on` != '0000-00-00 00:00:00'
AND `account_expires_on` < UTC_TIMESTAMP() ");
AND `account_expires_on` > '%s'
AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE));
// delete user and contact records for recently removed accounts
$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
@ -213,14 +160,6 @@ function cron_poll_contacts($argc, $argv) {
$force = true;
}
$interval = intval(get_config('system','poll_interval'));
if (!$interval)
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
// If we are using the worker we don't need a delivery interval
if (get_config("system", "worker"))
$interval = false;
$sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
reload_plugins();
@ -275,13 +214,15 @@ function cron_poll_contacts($argc, $argv) {
$xml = false;
if($manual_id)
$contact['last-update'] = '0000-00-00 00:00:00';
if ($manual_id) {
$contact['last-update'] = NULL_DATE;
}
if(in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS)))
if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
$contact['priority'] = 2;
}
if($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
// We should be getting everything via a hub. But just to be sure, let's check once a day.
// (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
// This also lets us update our subscription to the hub, and add or replace hubs in case it
@ -335,9 +276,6 @@ function cron_poll_contacts($argc, $argv) {
} else {
proc_run(PRIORITY_LOW, 'include/onepoll.php', $contact['id']);
}
if($interval)
@time_sleep_until(microtime(true) + (float) $interval);
}
}
}
@ -488,8 +426,3 @@ function cron_repair_database() {
/// - remove children when parent got lost
/// - set contact-id in item when not present
}
if (array_search(__file__,get_included_files())===0){
cron_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}

+ 5
- 37
include/cronhooks.php View File

@ -2,37 +2,11 @@
use \Friendica\Core\Config;
require_once("boot.php");
function cronhooks_run(&$argv, &$argc){
global $a, $db;
if(is_null($a)) {
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
global $a;
require_once('include/session.php');
require_once('include/datetime.php');
Config::load();
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if ($a->maxload_reached())
return;
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
return;
}
load_hooks();
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $hook)
if ($hook[1] == $argv[1]) {
@ -42,7 +16,7 @@ function cronhooks_run(&$argv, &$argc){
return;
}
$last = get_config('system','last_cronhook');
$last = get_config('system', 'last_cronhook');
$poll_interval = intval(get_config('system','cronhook_interval'));
if(! $poll_interval)
@ -62,22 +36,16 @@ function cronhooks_run(&$argv, &$argc){
$d = datetime_convert();
if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
if (is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $hook) {
logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG);
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
}
} else
call_hooks('cron', $d);
}
logger('cronhooks: end');
set_config('system','last_cronhook', time());
set_config('system', 'last_cronhook', time());
return;
}
if (array_search(__file__,get_included_files())===0){
cronhooks_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}

+ 1
- 36
include/cronjobs.php View File

@ -1,44 +1,14 @@
<?php
use \Friendica\Core\Config;
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
$directory = dirname($_SERVER["argv"][0]);
if (substr($directory, 0, 1) != "/")
$directory = $_SERVER["PWD"]."/".$directory;
$directory = realpath($directory."/..");
chdir($directory);
}
require_once("boot.php");
function cronjobs_run(&$argv, &$argc){
global $a, $db;
global $a;
if(is_null($a)) {
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once('include/session.php');
require_once('include/datetime.php');
require_once('include/ostatus.php');
require_once('include/post_update.php');
require_once('mod/nodeinfo.php');
Config::load();
$a->set_baseurl(get_config('system','url'));
// No parameter set? So return
if ($argc <= 1)
return;
@ -71,8 +41,3 @@ function cronjobs_run(&$argv, &$argc){
return;
}
if (array_search(__file__,get_included_files())===0){
cronjobs_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}

+ 1
- 1
include/datetime.php View File

@ -339,7 +339,7 @@ function relative_date($posted_date, $format = null) {
$abs = strtotime($localtime);
if (is_null($posted_date) || $posted_date === '0000-00-00 00:00:00' || $abs === False) {
if (is_null($posted_date) || $posted_date <= NULL_DATE || $abs === False) {
return t('never');
}


+ 198
- 122
include/dba.php View File

@ -1,17 +1,5 @@
<?php
require_once("dbm.php");
# if PDO is avaible for mysql, use the new database abstraction
# TODO: PDO is disabled for release 3.3. We need to investigate why
# the update from 3.2 fails with pdo
/*
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
require_once("library/dddbl2/dddbl.php");
require_once("include/dba_pdo.php");
}
*/
require_once('include/datetime.php');
/**
@ -24,13 +12,12 @@ require_once('include/datetime.php');
*
*/
if (! class_exists('dba')) {
class dba {
private $debug = 0;
private $db;
private $result;
public $mysqli = true;
private $driver;
public $connected = false;
public $error = false;
@ -53,7 +40,7 @@ class dba {
if ($install) {
if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
$this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server);
$this->error = sprintf(t('Cannot locate DNS info for database server \'%s\''), $server);
$this->connected = false;
$this->db = null;
return;
@ -61,37 +48,52 @@ class dba {
}
}
if (class_exists('mysqli')) {
$this->db = @new mysqli($server,$user,$pass,$db);
if (! mysqli_connect_errno()) {
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = 'pdo';
$connect = "mysql:host=".$server.";dbname=".$db;
if (isset($a->config["system"]["db_charset"])) {
$connect .= ";charset=".$a->config["system"]["db_charset"];
}
$this->db = @new PDO($connect, $user, $pass);
if (!$this->db->errorCode()) {
$this->connected = true;
}
if (isset($a->config["system"]["db_charset"])) {
$this->db->set_charset($a->config["system"]["db_charset"]);
} elseif (class_exists('mysqli')) {
$this->driver = 'mysqli';
$this->db = @new mysqli($server,$user,$pass,$db);
if (!mysqli_connect_errno()) {
$this->connected = true;
if (isset($a->config["system"]["db_charset"])) {
$this->db->set_charset($a->config["system"]["db_charset"]);
}
}
} else {
$this->mysqli = false;
} elseif (function_exists('mysql_connect')) {
$this->driver = 'mysql';
$this->db = mysql_connect($server,$user,$pass);
if ($this->db && mysql_select_db($db,$this->db)) {
$this->connected = true;
if (isset($a->config["system"]["db_charset"])) {
mysql_set_charset($a->config["system"]["db_charset"], $this->db);
}
}
} else {
// No suitable SQL driver was found.
if (!$install) {
system_unavailable();
}
if (isset($a->config["system"]["db_charset"]))
mysql_set_charset($a->config["system"]["db_charset"], $this->db);
}
if (!$this->connected) {
$this->db = null;
if (!$install) {
system_unavailable();
}
}
$a->save_timestamp($stamp1, "network");
}
public function getdb() {
return $this->db;
}
/**
* @brief Returns the MySQL server version string
*
@ -101,12 +103,18 @@ class dba {
* @return string
*/
public function server_info() {
if ($this->mysqli) {
$return = $this->db->server_info;
} else {
$return = mysql_get_server_info($this->db);
switch ($this->driver) {
case 'pdo':
$version = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION);
break;
case 'mysqli':
$version = $this->db->server_info;
break;
case 'mysql':
$version = mysql_get_server_info($this->db);
break;
}
return $return;
return $version;
}
/**
@ -130,12 +138,18 @@ class dba {
return 0;
}
if ($this->mysqli) {
$return = $this->result->num_rows;
} else {
$return = mysql_num_rows($this->result);
switch ($this->driver) {
case 'pdo':
$rows = $this->result->rowCount();
break;
case 'mysqli':
$rows = $this->result->num_rows;
break;
case 'mysql':
$rows = mysql_num_rows($this->result);
break;
}
return $return;
return $rows;
}
/**
@ -172,8 +186,9 @@ class dba {
if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) {
$log = (in_array($row['key'], $watchlist) AND
($row['rows'] >= intval($a->config["system"]["db_loglimit_index"])));
} else
} else {
$log = false;
}
if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) {
$log = true;
@ -203,13 +218,7 @@ class dba {
$this->error = '';
// Check the connection (This can reconnect the connection - if configured)
if ($this->mysqli) {
$connected = $this->db->ping();
} else {
$connected = mysql_ping($this->db);
}
$connstr = ($connected ? "Connected" : "Disonnected");
$connstr = ($this->connected() ? "Connected" : "Disonnected");
$stamp1 = microtime(true);
@ -219,10 +228,22 @@ class dba {
$sql = "/*".$a->callstack()." */ ".$sql;
}
if ($this->mysqli) {
$result = @$this->db->query($sql);
} else {
$result = @mysql_query($sql,$this->db);
$columns = 0;
switch ($this->driver) {
case 'pdo':
$result = @$this->db->query($sql);
// Is used to separate between queries that returning data - or not
if (!is_bool($result)) {
$columns = $result->columnCount();
}
break;
case 'mysqli':
$result = @$this->db->query($sql);
break;
case 'mysql':
$result = @mysql_query($sql,$this->db);
break;
}
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
@ -243,16 +264,27 @@ class dba {
}
}
if ($this->mysqli) {
if ($this->db->errno) {
$this->error = $this->db->error;
$this->errorno = $this->db->errno;
}
} elseif (mysql_errno($this->db)) {
$this->error = mysql_error($this->db);
$this->errorno = mysql_errno($this->db);
switch ($this->driver) {
case 'pdo':
$errorInfo = $this->db->errorInfo();
if ($errorInfo) {
$this->error = $errorInfo[2];
$this->errorno = $errorInfo[1];
}
break;
case 'mysqli':
if ($this->db->errno) {
$this->error = $this->db->error;
$this->errorno = $this->db->errno;
}
break;
case 'mysql':
if (mysql_errno($this->db)) {
$this->error = mysql_error($this->db);
$this->errorno = mysql_errno($this->db);
}
break;
}
if (strlen($this->error)) {
logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error);
}
@ -266,10 +298,16 @@ class dba {
} elseif ($result === true) {
$mesg = 'true';
} else {
if ($this->mysqli) {
$mesg = $result->num_rows . ' results' . EOL;
} else {
$mesg = mysql_num_rows($result) . ' results' . EOL;
switch ($this->driver) {
case 'pdo':
$mesg = $result->rowCount().' results'.EOL;
break;
case 'mysqli':
$mesg = $result->num_rows.' results'.EOL;
break;
case 'mysql':
$mesg = mysql_num_rows($result).' results'.EOL;
break;
}
}
@ -293,7 +331,7 @@ class dba {
}
}
if (($result === true) || ($result === false)) {
if (is_bool($result)) {
return $result;
}
if ($onlyquery) {
@ -302,18 +340,32 @@ class dba {
}
$r = array();
if ($this->mysqli) {
if ($result->num_rows) {
while($x = $result->fetch_array(MYSQLI_ASSOC))
switch ($this->driver) {
case 'pdo':
while ($x = $result->fetch(PDO::FETCH_ASSOC)) {
$r[] = $x;
}
$result->closeCursor();
break;
case 'mysqli':
while ($x = $result->fetch_array(MYSQLI_ASSOC)) {
$r[] = $x;
}
$result->free_result();
}
} else {
if (mysql_num_rows($result)) {
while($x = mysql_fetch_array($result, MYSQL_ASSOC))
break;
case 'mysql':
while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) {
$r[] = $x;
}
mysql_free_result($result);
}
break;
}
// PDO doesn't return "true" on successful operations - like mysqli does
// Emulate this behaviour by checking if the query returned data and had columns
// This should be reliable enough
if (($this->driver == 'pdo') AND (count($r) == 0) AND ($columns == 0)) {
return true;
}
//$a->save_timestamp($stamp1, "database");
@ -328,12 +380,16 @@ class dba {
$x = false;
if ($this->result) {
if ($this->mysqli) {
if ($this->result->num_rows)
switch ($this->driver) {
case 'pdo':
$x = $this->result->fetch(PDO::FETCH_ASSOC);
break;
case 'mysqli':
$x = $this->result->fetch_array(MYSQLI_ASSOC);
} else {
if (mysql_num_rows($this->result))
break;
case 'mysql':
$x = mysql_fetch_array($this->result, MYSQL_ASSOC);
break;
}
}
return($x);
@ -341,10 +397,16 @@ class dba {
public function qclose() {
if ($this->result) {
if ($this->mysqli) {
$this->result->free_result();
} else {
mysql_free_result($this->result);
switch ($this->driver) {
case 'pdo':
$this->result->closeCursor();
break;
case 'mysqli':
$this->result->free_result();
break;
case 'mysql':
mysql_free_result($this->result);
break;
}
}
}
@ -355,35 +417,65 @@ class dba {
public function escape($str) {
if ($this->db && $this->connected) {
if ($this->mysqli) {
return @$this->db->real_escape_string($str);
} else {
return @mysql_real_escape_string($str,$this->db);
switch ($this->driver) {
case 'pdo':
return substr(@$this->db->quote($str, PDO::PARAM_STR), 1, -1);
case 'mysqli':
return @$this->db->real_escape_string($str);
case 'mysql':
return @mysql_real_escape_string($str,$this->db);
}
}
}
function connected() {
if ($this->mysqli) {
$connected = $this->db->ping();
} else {
$connected = mysql_ping($this->db);
switch ($this->driver) {
case 'pdo':
// Not sure if this really is working like expected
$connected = ($this->db->getAttribute(PDO::ATTR_CONNECTION_STATUS) != "");
break;
case 'mysqli':
$connected = $this->db->ping();
break;