services:
- mysql
env:
- - USER=travis DB=test
+ - MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USERNAME=travis MYSQL_PASSWORD= MYSQL_DATABASE=test
install:
- composer install
before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- # In order to avoid bin/worker.php warnings
- - touch .htconfig.php
+ - mysql -utravis test < database.sql
if (!defined('CURLE_OPERATION_TIMEDOUT')) {
define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
}
-/**
- * Reverse the effect of magic_quotes_gpc if it is enabled.
- * Please disable magic_quotes_gpc so we don't have to do this.
- * See http://php.net/manual/en/security.magicquotes.disabling.php
- */
-function startup()
-{
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
-
- set_time_limit(0);
-
- // This has to be quite large to deal with embedded private photos
- ini_set('pcre.backtrack_limit', 500000);
-
- if (get_magic_quotes_gpc()) {
- $process = [&$_GET, &$_POST, &$_COOKIE, &$_REQUEST];
- while (list($key, $val) = each($process)) {
- foreach ($val as $k => $v) {
- unset($process[$key][$k]);
- if (is_array($v)) {
- $process[$key][stripslashes($k)] = $v;
- $process[] = &$process[$key][stripslashes($k)];
- } else {
- $process[$key][stripslashes($k)] = stripslashes($v);
- }
- }
- }
- unset($process);
- }
-}
/**
* @brief Retrieve the App structure
// Use environment variables for mysql if they are set beforehand
if (!empty(getenv('MYSQL_HOST'))
- && !empty(getenv('MYSQL_PORT'))
&& (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER')))
- && !empty(getenv('MYSQL_PASSWORD'))
+ && !getenv('MYSQL_PASSWORD') === false
&& !empty(getenv('MYSQL_DATABASE'))) {
- $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT');
+ $db_host = getenv('MYSQL_HOST');
+ if (!empty(getenv('MYSQL_PORT'))) {
+ $db_host .= ':' . getenv('MYSQL_PORT');
+ }
if (!empty(getenv('MYSQL_USERNAME'))) {
$db_user = getenv('MYSQL_USERNAME');
- } elseif (!empty(getenv('MYSQL_USER'))) {
+ } else {
$db_user = getenv('MYSQL_USER');
}
- $db_pass = getenv('MYSQL_PASSWORD');
+ $db_pass = (string) getenv('MYSQL_PASSWORD');
$db_data = getenv('MYSQL_DATABASE');
}
use Friendica\Core\L10n;
use Friendica\Core\NotificationsManager;
use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
}
// Support for known clients that doesn't send a source name
- if (strpos($_SERVER['HTTP_USER_AGENT'], "Twidere") !== false) {
- return "Twidere";
- }
+ if (!empty($_SERVER['HTTP_USER_AGENT'])) {
+ if(strpos($_SERVER['HTTP_USER_AGENT'], "Twidere") !== false) {
+ return "Twidere";
+ }
- logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
+ logger("Unrecognized user-agent ".$_SERVER['HTTP_USER_AGENT'], LOGGER_DEBUG);
+ } else {
+ logger("Empty user-agent", LOGGER_DEBUG);
+ }
return "api";
}
throw new UnauthorizedException("This API requires login");
}
- $user = $_SERVER['PHP_AUTH_USER'];
- $password = $_SERVER['PHP_AUTH_PW'];
+ $user = defaults($_SERVER, 'PHP_AUTH_USER', '');
+ $password = defaults($_SERVER, 'PHP_AUTH_PW', '');
// allow "user@server" login (but ignore 'server' part)
$at = strstr($user, "@", true);
if ($method == "*") {
return true;
}
- return (strpos($method, $_SERVER['REQUEST_METHOD']) !== false);
+ return (stripos($method, defaults($_SERVER, 'REQUEST_METHOD', 'GET')) !== false);
}
/**
//unset($_SERVER['PHP_AUTH_USER']);
/// @TODO should be "true ==[=] $info['auth']", if you miss only one = character, you assign a variable (only with ==). Let's make all this even.
- if ($info['auth'] === true && api_user() === false) {
+ if (!empty($info['auth']) && api_user() === false) {
api_login($a);
}
'base' => System::baseUrl(),
'updated' => api_date(null),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
- 'language' => $user_info['language'],
+ 'language' => $user_info['lang'],
'logo' => System::baseUrl() . "/images/friendica-32.png",
];
}
}
+ // $called_api is the API path exploded on / and is expected to have at least 2 elements
if (is_null($user) && ($a->argc > (count($called_api) - 1)) && (count($called_api) > 0)) {
$argid = count($called_api);
list($user, $null) = explode(".", $a->argv[$argid]);
$link_color = PConfig::get($ret['uid'], 'frio', 'link_color');
$bgcolor = PConfig::get($ret['uid'], 'frio', 'background_color');
}
- if (!$nav_bg) {
+ if (empty($nav_bg)) {
$nav_bg = "#708fa0";
}
- if (!$link_color) {
+ if (empty($link_color)) {
$link_color = "#6fdbe8";
}
- if (!$bgcolor) {
+ if (empty($bgcolor)) {
$bgcolor = "#ededed";
}
*/
function api_item_get_user(App $a, $item)
{
- $status_user = api_get_user($a, $item["author-id"]);
+ $status_user = api_get_user($a, defaults($item, 'author-id', null));
- $status_user["protected"] = $item["private"];
+ $status_user["protected"] = defaults($item, 'private', 0);
- if ($item['thr-parent'] == $item['uri']) {
- $owner_user = api_get_user($a, $item["owner-id"]);
+ if (defaults($item, 'thr-parent', '') == defaults($item, 'uri', '')) {
+ $owner_user = api_get_user($a, defaults($item, 'author-id', null));
} else {
$owner_user = $status_user;
}
{
$childname = key($data);
$data2 = array_pop($data);
- $key = key($data2);
$namespaces = ["" => "http://api.twitter.com",
"statusnet" => "http://status.net/schema/api/1/",
}
if (is_array($data2)) {
+ $key = key($data2);
api_walk_recursive($data2, "api_reformat_xml");
- }
- if ($key == "0") {
- $data4 = [];
- $i = 1;
+ if ($key == "0") {
+ $data4 = [];
+ $i = 1;
- foreach ($data2 as $item) {
- $data4[$i++ . ":" . $childname] = $item;
- }
+ foreach ($data2 as $item) {
+ $data4[$i++ . ":" . $childname] = $item;
+ }
- $data2 = $data4;
+ $data2 = $data4;
+ }
}
$data3 = [$root_element => $data2];
'in_reply_to_screen_name' => $in_reply_to['screen_name'],
'user' => $user_info,
$geo => null,
- 'coordinates' => "",
- 'place' => "",
- 'contributors' => "",
+ 'coordinates' => '',
+ 'place' => '',
+ 'contributors' => '',
'is_quote_status' => false,
'retweet_count' => 0,
'favorite_count' => 0,
'favorited' => $lastwall['starred'] ? true : false,
'retweeted' => false,
'possibly_sensitive' => false,
- 'lang' => "",
+ 'lang' => '',
'statusnet_html' => $converted["html"],
'statusnet_conversation_id' => $lastwall['parent'],
- 'external_url' => System::baseUrl() . "/display/" . $lastwall['guid'],
+ 'external_url' => System::baseUrl() . '/display/' . $lastwall['guid'],
];
if (count($converted["attachments"]) > 0) {
{
$users = [];
- if (x($_REQUEST['user_id'])) {
+ if (!empty($_REQUEST['user_id'])) {
foreach (explode(',', $_REQUEST['user_id']) as $id) {
if (!empty($id)) {
$users[] = api_get_user(get_app(), $id);
}
// params
- $id = intval($a->argv[3]);
+ $id = intval(defaults($a->argv, 3, 0));
if ($id == 0) {
- $id = intval($_REQUEST["id"]);
+ $id = intval(defaults($_REQUEST, 'id', 0));
}
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4]);
+ $id = intval(defaults($a->argv, 4, 0));
}
logger('API: api_statuses_show: ' . $id);
- $conversation = (x($_REQUEST, 'conversation') ? 1 : 0);
+ $conversation = !empty($_REQUEST['conversation']);
// try to fetch the item for the local user - or the public item, if there is no local one
$uri_item = dba::selectFirst('item', ['uri'], ['id' => $id]);
}
// params
- $id = intval($a->argv[3]);
- $count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
- $page = (x($_REQUEST, 'page') ? $_REQUEST['page'] - 1 : 0);
+ $id = intval(defaults($a->argv , 3 , 0));
+ $since_id = intval(defaults($_REQUEST, 'since_id', 0));
+ $max_id = intval(defaults($_REQUEST, 'max_id' , 0));
+ $count = intval(defaults($_REQUEST, 'count' , 20));
+ $page = intval(defaults($_REQUEST, 'page' , 1)) - 1;
if ($page < 0) {
$page = 0;
}
- $since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
- $max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0);
- $start = $page*$count;
+ $start = $page * $count;
if ($id == 0) {
- $id = intval($_REQUEST["id"]);
+ $id = intval(defaults($_REQUEST, 'id', 0));
}
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4]);
+ $id = intval(defaults($a->argv, 4, 0));
}
logger('API: api_conversation_show: '.$id);
api_get_user($a);
// params
- $id = intval($a->argv[3]);
+ $id = intval(defaults($a->argv, 3, 0));
if ($id == 0) {
- $id = intval($_REQUEST["id"]);
+ $id = intval(defaults($_REQUEST, 'id', 0));
}
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4]);
+ $id = intval(defaults($a->argv, 4, 0));
}
logger('API: api_statuses_repeat: '.$id);
api_get_user($a);
// params
- $id = intval($a->argv[3]);
+ $id = intval(defaults($a->argv, 3, 0));
if ($id == 0) {
- $id = intval($_REQUEST["id"]);
+ $id = intval(defaults($_REQUEST, 'id', 0));
}
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4]);
+ $id = intval(defaults($a->argv, 4, 0));
}
logger('API: api_statuses_destroy: '.$id);
// for versioned api.
/// @TODO We need a better global soluton
$action_argv_id = 2;
- if ($a->argv[1] == "1.1") {
+ if (count($a->argv) > 1 && $a->argv[1] == "1.1") {
$action_argv_id = 3;
}
}
$action = str_replace("." . $type, "", $a->argv[$action_argv_id]);
if ($a->argc == $action_argv_id + 2) {
- $itemid = intval($a->argv[$action_argv_id + 1]);
+ $itemid = intval(defaults($a->argv, $action_argv_id + 1, 0));
} else {
- /// @TODO use x() to check if _REQUEST contains 'id'
- $itemid = intval($_REQUEST['id']);
+ $itemid = intval(defaults($_REQUEST, 'id', 0));
}
$item = Item::selectFirstForUser(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
{
// standard meta information
$ret = [
- 'id' => $item['id'],
- 'sender_id' => $sender['id'] ,
- 'text' => "",
- 'recipient_id' => $recipient['id'],
- 'created_at' => api_date($item['created']),
- 'sender_screen_name' => $sender['screen_name'],
- 'recipient_screen_name' => $recipient['screen_name'],
- 'sender' => $sender,
- 'recipient' => $recipient,
- 'title' => "",
- 'friendica_seen' => $item['seen'],
- 'friendica_parent_uri' => $item['parent-uri'],
+ 'id' => $item['id'],
+ 'sender_id' => $sender['id'] ,
+ 'text' => "",
+ 'recipient_id' => $recipient['id'],
+ 'created_at' => api_date(defaults($item, 'created', DateTimeFormat::utcNow())),
+ 'sender_screen_name' => $sender['screen_name'],
+ 'recipient_screen_name' => $recipient['screen_name'],
+ 'sender' => $sender,
+ 'recipient' => $recipient,
+ 'title' => "",
+ 'friendica_seen' => defaults($item, 'seen', 0),
+ 'friendica_parent_uri' => defaults($item, 'parent-uri', ''),
];
// "uid" and "self" are only needed for some internal stuff, so remove it from here
- unset($ret["sender"]["uid"]);
- unset($ret["sender"]["self"]);
- unset($ret["recipient"]["uid"]);
- unset($ret["recipient"]["self"]);
+ if (isset($ret['sender']['uid'])) {
+ unset($ret['sender']['uid']);
+ }
+ if (isset($ret['sender']['self'])) {
+ unset($ret['sender']['self']);
+ }
+ if (isset($ret['recipient']['uid'])) {
+ unset($ret['recipient']['uid']);
+ }
+ if (isset($ret['recipient']['self'])) {
+ unset($ret['recipient']['self']);
+ }
//don't send title to regular StatusNET requests to avoid confusing these apps
if (x($_GET, 'getText')) {
$statustext = trim($statustitle."\n\n".$statusbody);
}
- if (($item["network"] == NETWORK_FEED) && (strlen($statustext)> 1000)) {
- $statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
+ if ((defaults($item, 'network', Protocol::PHANTOM) == Protocol::FEED) && (strlen($statustext)> 1000)) {
+ $statustext = substr($statustext, 0, 1000) . "... \n" . defaults($item, 'plink', '');
}
$statushtml = BBCode::convert(api_clean_attachments($body), false);
}
// feeds without body should contain the link
- if (($item['network'] == NETWORK_FEED) && (strlen($item['body']) == 0)) {
+ if ((defaults($item, 'network', Protocol::PHANTOM) == Protocol::FEED) && (strlen($item['body']) == 0)) {
$statushtml .= BBCode::convert($item['plink']);
}
}
}
- if (strstr($_SERVER['HTTP_USER_AGENT'], "AndStatus")) {
+ if (strstr(defaults($_SERVER, 'HTTP_USER_AGENT', ''), "AndStatus")) {
foreach ($images[0] as $orig) {
$body = str_replace($orig, "", $body);
}
{
$a = get_app();
- $name = $a->config['sitename'];
- $server = $a->get_hostname();
- $logo = System::baseUrl() . '/images/friendica-64.png';
- $email = $a->config['admin_email'];
- $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
- $private = ((Config::get('system', 'block_public')) ? 'true' : 'false');
- $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000);
- if ($a->config['api_import_size']) {
- $textlimit = (string) $a->config['api_import_size'];
- }
- $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
- $sslserver = (($ssl === 'true') ? str_replace('http:', 'https:', System::baseUrl()) : '');
+ $name = Config::get('config', 'sitename');
+ $server = $a->get_hostname();
+ $logo = System::baseUrl() . '/images/friendica-64.png';
+ $email = Config::get('config', 'admin_email');
+ $closed = Config::get('config', 'register_policy') == REGISTER_CLOSED ? 'true' : 'false';
+ $private = Config::get('system', 'block_public') ? 'true' : 'false';
+ $textlimit = (string) Config::get('config', 'api_import_size', Config::get('config', 'max_import_size', 200000));
+ $ssl = Config::get('system', 'have_ssl') ? 'true' : 'false';
+ $sslserver = Config::get('system', 'have_ssl') ? str_replace('http:', 'https:', System::baseUrl()) : '';
$config = [
'site' => ['name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
*/
function api_direct_messages_new($type)
{
-
$a = get_app();
if (api_user() === false) {
throw new ForbiddenException();
}
- if (!x($_POST, "text") || (!x($_POST, "screen_name") && !x($_POST, "user_id"))) {
+ if (empty($_POST["text"]) || empty($_POST["screen_name"]) && empty($_POST["user_id"])) {
return;
}
$sender = api_get_user($a);
- if ($_POST['screen_name']) {
+ $recipient = null;
+ if (!empty($_POST['screen_name'])) {
$r = q(
"SELECT `id`, `nurl`, `network` FROM `contact` WHERE `uid`=%d AND `nick`='%s'",
intval(api_user()),
dbesc($_POST['screen_name'])
);
- // Selecting the id by priority, friendica first
- api_best_nickname($r);
+ if (DBM::is_result($r)) {
+ // Selecting the id by priority, friendica first
+ api_best_nickname($r);
- $recipient = api_get_user($a, $r[0]['nurl']);
+ $recipient = api_get_user($a, $r[0]['nurl']);
+ }
} else {
$recipient = api_get_user($a, $_POST['user_id']);
}
+ if (empty($recipient)) {
+ throw new NotFoundException('Recipient not found');
+ }
+
$replyto = '';
$sub = '';
if (x($_REQUEST, 'replyto')) {
throw new ForbiddenException();
}
// params
- $count = (x($_GET, 'count') ? $_GET['count'] : 20);
- $page = (x($_REQUEST, 'page') ? $_REQUEST['page'] -1 : 0);
+ $count = defaults($_GET, 'count', 20);
+ $page = defaults($_REQUEST, 'page', 1) - 1;
if ($page < 0) {
$page = 0;
}
- $since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
- $max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0);
+ $since_id = defaults($_REQUEST, 'since_id', 0);
+ $max_id = defaults($_REQUEST, 'max_id', 0);
- $user_id = (x($_REQUEST, 'user_id') ? $_REQUEST['user_id'] : "");
- $screen_name = (x($_REQUEST, 'screen_name') ? $_REQUEST['screen_name'] : "");
+ $user_id = defaults($_REQUEST, 'user_id', '');
+ $screen_name = defaults($_REQUEST, 'screen_name', '');
// caller user info
unset($_REQUEST["user_id"]);
if ($box=="sentbox") {
$sql_extra = "`mail`.`from-url`='" . dbesc($profile_url) . "'";
} elseif ($box == "conversation") {
- $sql_extra = "`mail`.`parent-uri`='" . dbesc($_GET["uri"]) . "'";
+ $sql_extra = "`mail`.`parent-uri`='" . dbesc(defaults($_GET, 'uri', '')) . "'";
} elseif ($box == "all") {
$sql_extra = "true";
} elseif ($box == "inbox") {
if ($type == "xml") {
$xmlnotes = [];
- foreach ($notes as $note) {
- $xmlnotes[] = ["@attributes" => $note];
+ if (!empty($notes)) {
+ foreach ($notes as $note) {
+ $xmlnotes[] = ["@attributes" => $note];
+ }
}
$notes = $xmlnotes;
$commands = [];
// Create a key for the loop prevention
- $key = $table . ':' . implode(':', array_keys($conditions)) . ':' . implode(':', $conditions);
+ $key = $table . ':' . json_encode($conditions);
// We quit when this key already exists in the callstack.
if (isset($callstack[$key])) {
$rel_def = array_values(self::$relation[$table])[0];
// Create a key for preventing double queries
- $qkey = $field . '-' . $table . ':' . implode(':', array_keys($conditions)) . ':' . implode(':', $conditions);
+ $qkey = $field . '-' . $table . ':' . json_encode($conditions);
// When the search field is the relation field, we don't need to fetch the rows
// This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
if ($user) {
$value = json_encode(["uid" => $user["uid"],
"hash" => cookie_hash($user),
- "ip" => $_SERVER['REMOTE_ADDR']]);
+ "ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
} else {
$value = "";
}
$_SESSION['page_flags'] = $user_record['page-flags'];
$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $user_record['nickname'];
$_SESSION['my_address'] = $user_record['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
- $_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
+ $_SESSION['addr'] = defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0');
$a->user = $user_record;
$rendered_html = defaults($item, 'rendered-html', '');
if ($rendered_hash == ''
- || $item["rendered-html"] == ""
+ || $rendered_html == ""
|| $rendered_hash != hash("md5", $item["body"])
|| Config::get("system", "ignore_cache")
) {
$update = true;
}
- if ($update && ($item["id"] > 0)) {
+ if ($update && !empty($item["id"])) {
Item::update(['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
['id' => $item["id"]]);
}
return;
}
+ $categories = '';
+
if ($orig_post) {
$str_group_allow = $orig_post['allow_gid'];
$str_contact_allow = $orig_post['allow_cid'];
$str_contact_deny = perms2str($_REQUEST['contact_deny']);
}
- $title = notags(trim($_REQUEST['title']));
- $location = notags(trim($_REQUEST['location']));
- $coord = notags(trim($_REQUEST['coord']));
- $verb = notags(trim($_REQUEST['verb']));
- $emailcc = notags(trim($_REQUEST['emailcc']));
- $body = escape_tags(trim($_REQUEST['body']));
- $network = notags(trim(defaults($_REQUEST, 'network', NETWORK_DFRN)));
+ $title = notags(trim(defaults($_REQUEST, 'title' , '')));
+ $location = notags(trim(defaults($_REQUEST, 'location', '')));
+ $coord = notags(trim(defaults($_REQUEST, 'coord' , '')));
+ $verb = notags(trim(defaults($_REQUEST, 'verb' , '')));
+ $emailcc = notags(trim(defaults($_REQUEST, 'emailcc' , '')));
+ $body = escape_tags(trim(defaults($_REQUEST, 'body' , '')));
+ $network = notags(trim(defaults($_REQUEST, 'network' , NETWORK_DFRN)));
$guid = get_guid(32);
$postopts = defaults($_REQUEST, 'postopts', '');
}
}
- if (strlen($categories)) {
+ if (!empty($categories)) {
// get the "fileas" tags for this post
$filedas = file_tag_file_to_list($categories, 'file');
}
// save old and new categories, so we can determine what needs to be deleted from pconfig
$categories_old = $categories;
- $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category');
+ $categories = file_tag_list_to_file(trim(defaults($_REQUEST, 'category', '')), 'category');
$categories_new = $categories;
- if (strlen($filedas)) {
+ if (!empty($filedas)) {
// append the fileas stuff to the new categories list
$categories .= file_tag_list_to_file($filedas, 'file');
}
$filetype = $_FILES['userfile']['type'];
} elseif (x($_FILES, 'media')) {
- if (is_array($_FILES['media']['tmp_name'])) {
- $src = $_FILES['media']['tmp_name'][0];
- } else {
- $src = $_FILES['media']['tmp_name'];
+ if (!empty($_FILES['media']['tmp_name'])) {
+ if (is_array($_FILES['media']['tmp_name'])) {
+ $src = $_FILES['media']['tmp_name'][0];
+ } else {
+ $src = $_FILES['media']['tmp_name'];
+ }
}
- if (is_array($_FILES['media']['name'])) {
- $filename = basename($_FILES['media']['name'][0]);
- } else {
- $filename = basename($_FILES['media']['name']);
+ if (!empty($_FILES['media']['name'])) {
+ if (is_array($_FILES['media']['name'])) {
+ $filename = basename($_FILES['media']['name'][0]);
+ } else {
+ $filename = basename($_FILES['media']['name']);
+ }
}
- if (is_array($_FILES['media']['size'])) {
- $filesize = intval($_FILES['media']['size'][0]);
- } else {
- $filesize = intval($_FILES['media']['size']);
+ if (!empty($_FILES['media']['size'])) {
+ if (is_array($_FILES['media']['size'])) {
+ $filesize = intval($_FILES['media']['size'][0]);
+ } else {
+ $filesize = intval($_FILES['media']['size']);
+ }
}
- if (is_array($_FILES['media']['type'])) {
- $filetype = $_FILES['media']['type'][0];
- } else {
- $filetype = $_FILES['media']['type'];
+ if (!empty($_FILES['media']['type'])) {
+ if (is_array($_FILES['media']['type'])) {
+ $filetype = $_FILES['media']['type'][0];
+ } else {
+ $filetype = $_FILES['media']['type'];
+ }
}
}
<?xml version="1.0"?>
-<phpunit bootstrap="tests/bootstrap.php">
+<phpunit
+ bootstrap="tests/bootstrap.php"
+ verbose="true">
<testsuites>
<testsuite>
<directory>tests/</directory>
$this->process_id = uniqid('log', true);
- startup();
+ set_time_limit(0);
+
+ // This has to be quite large to deal with embedded private photos
+ ini_set('pcre.backtrack_limit', 500000);
$this->scheme = 'http';
$this->is_tablet = $mobile_detect->isTablet();
// Friendica-Client
- $this->is_friendica_app = ($_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)');
+ $this->is_friendica_app = isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)';
// Register template engines
$this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
return;
}
- array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));
+ array_unshift($args, $this->getConfigValue('config', 'php_path', 'php'));
for ($x = 0; $x < count($args); $x ++) {
$args[$x] = escapeshellarg($args[$x]);
return;
}
- if (Config::get('system', 'proc_windows')) {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->get_basepath());
} else {
$resource = proc_open($cmdline . ' &', [], $foo, $this->get_basepath());
}
} elseif (!in_array($func['function'], $ignore)) {
$callstack[] = $func['function'];
+ $func['class'] = '';
$previous = $func;
}
}
$field_definition = $database[$name]["fields"][$fieldname];
// Define the default collation if not given
- if (!isset($parameters['Collation']) && !is_null($field_definition['Collation'])) {
+ if (!isset($parameters['Collation']) && !empty($field_definition['Collation'])) {
$parameters['Collation'] = 'utf8mb4_general_ci';
} else {
$parameters['Collation'] = null;
private static function FieldCommand($parameters, $create = true) {
$fieldstruct = $parameters["type"];
- if (!is_null($parameters["Collation"])) {
+ if (!empty($parameters["Collation"])) {
$fieldstruct .= " COLLATE ".$parameters["Collation"];
}
- if ($parameters["not null"]) {
+ if (!empty($parameters["not null"])) {
$fieldstruct .= " NOT NULL";
}
- if (isset($parameters["default"])) {
+ if (!empty($parameters["default"])) {
if (strpos(strtolower($parameters["type"]),"int")!==false) {
$fieldstruct .= " DEFAULT ".$parameters["default"];
} else {
$fieldstruct .= " DEFAULT '".$parameters["default"]."'";
}
}
- if ($parameters["extra"] != "") {
+ if (!empty($parameters["extra"])) {
$fieldstruct .= " ".$parameters["extra"];
}
- if (!is_null($parameters["comment"])) {
+ if (!empty($parameters["comment"])) {
$fieldstruct .= " COMMENT '".dbesc($parameters["comment"])."'";
}
}
}
- if (!is_null($structure["indexes"])) {
+ if (!empty($structure["indexes"])) {
foreach ($structure["indexes"] AS $indexname => $fieldnames) {
$sql_index = self::createIndex($indexname, $fieldnames, "");
if (!is_null($sql_index)) {
}
}
- if (!is_null($structure["engine"])) {
+ if (!empty($structure["engine"])) {
$engine = " ENGINE=" . $structure["engine"];
}
- if (!is_null($structure["comment"])) {
+ if (!empty($structure["comment"])) {
$comment = " COMMENT='" . dbesc($structure["comment"]) . "'";
}
unset($old_conv['source']);
}
// Update structure data all the time but the source only when its from a better protocol.
- if (($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
+ if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
unset($conversation['protocol']);
unset($conversation['source']);
}
// If item has attachments, drop them
foreach (explode(", ", $item['attach']) as $attach) {
preg_match("|attach/(\d+)|", $attach, $matches);
- dba::delete('attach', ['id' => $matches[1], 'uid' => $item['uid']]);
+ if (is_array($matches) && count($matches) > 1) {
+ dba::delete('attach', ['id' => $matches[1], 'uid' => $item['uid']]);
+ }
}
// Delete tags that had been attached to other items
Contact::unmarkForArchival($contact);
}
- $update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
+ $update = (!$arr['private'] && ((defaults($arr, 'author-link', '') === defaults($arr, 'owner-link', '')) || ($arr["parent-uri"] === $arr["uri"])));
// Is it a forum? Then we don't care about the rules from above
if (!$update && ($arr["network"] == NETWORK_DFRN) && ($arr["parent-uri"] === $arr["uri"])) {
$redirects = 0;
logger("Probing for ".$host, LOGGER_DEBUG);
+ $xrd = null;
$ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
if ($ret['success']) {
return false;
}
$feed = $ret['body'];
+ $dummy1 = $dummy2 = $dummy3 = null;
$feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true);
if (!$feed_data) {
global $a;
parent::setUp();
+ // Reusable App object
+ $this->app = new App(__DIR__.'/../');
+ $a = $this->app;
+
// User data that the test database is populated with
$this->selfUser = [
'id' => 42,
'nick' => 'selfcontact',
'nurl' => 'http://localhost/profile/selfcontact'
];
+ $this->friendUser = [
+ 'id' => 44,
+ 'name' => 'Friend contact',
+ 'nick' => 'friendcontact',
+ 'nurl' => 'http://localhost/profile/friendcontact'
+ ];
$this->otherUser = [
'id' => 43,
'name' => 'othercontact',
'uid' => $this->selfUser['id']
];
- // Reusable App object
- $this->app = new App(__DIR__.'/../');
- $a = $this->app;
-
// Default config
Config::set('config', 'hostname', 'localhost');
Config::set('system', 'throttle_limit_day', 100);
$this->app->query_string = 'api_path.rss';
$this->assertEquals(
- '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL.
+ '<?xml version="1.0" encoding="UTF-8"?>'."\n".
'some_data',
api_call($this->app)
);
$this->app->query_string = 'api_path.atom';
$this->assertEquals(
- '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL.
+ '<?xml version="1.0" encoding="UTF-8"?>'."\n".
'some_data',
api_call($this->app)
);
public function testApiErrorWithXml()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
+ '<?xml version="1.0"?>'."\n".
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
- 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
- ' <error>error_message</error>'.PHP_EOL.
- ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
- ' <request/>'.PHP_EOL.
- '</status>'.PHP_EOL,
+ 'xmlns:georss="http://www.georss.org/georss">'."\n".
+ ' <error>error_message</error>'."\n".
+ ' <code>200 Friendica\Network\HTTP</code>'."\n".
+ ' <request/>'."\n".
+ '</status>'."\n",
api_error('xml', new HTTPException('error_message'))
);
}
public function testApiErrorWithRss()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
+ '<?xml version="1.0"?>'."\n".
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
- 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
- ' <error>error_message</error>'.PHP_EOL.
- ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
- ' <request/>'.PHP_EOL.
- '</status>'.PHP_EOL,
+ 'xmlns:georss="http://www.georss.org/georss">'."\n".
+ ' <error>error_message</error>'."\n".
+ ' <code>200 Friendica\Network\HTTP</code>'."\n".
+ ' <request/>'."\n".
+ '</status>'."\n",
api_error('rss', new HTTPException('error_message'))
);
}
public function testApiErrorWithAtom()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
+ '<?xml version="1.0"?>'."\n".
'<status xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
- 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
- ' <error>error_message</error>'.PHP_EOL.
- ' <code>200 Friendica\Network\HTTP</code>'.PHP_EOL.
- ' <request/>'.PHP_EOL.
- '</status>'.PHP_EOL,
+ 'xmlns:georss="http://www.georss.org/georss">'."\n".
+ ' <error>error_message</error>'."\n".
+ ' <code>200 Friendica\Network\HTTP</code>'."\n".
+ ' <request/>'."\n".
+ '</status>'."\n",
api_error('atom', new HTTPException('error_message'))
);
}
*/
public function testApiRssExtra()
{
- $user_info = ['url' => 'user_url'];
+ $user_info = ['url' => 'user_url', 'lang' => 'en'];
$result = api_rss_extra($this->app, [], $user_info);
$this->assertEquals($user_info, $result['$user']);
$this->assertEquals($user_info['url'], $result['$rss']['alternate']);
public function testApiGetUserWithCalledApi()
{
global $called_api;
- $called_api = ['api_path'];
+ $called_api = ['api', 'api_path'];
$this->assertSelfUser(api_get_user($this->app));
}
$this->assertSelfUser(api_get_user($this->app, 0));
}
-
/**
* Test the api_item_get_user() function.
* @return void
public function testApiCreateXml()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
+ '<?xml version="1.0"?>'."\n".
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
- 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
- ' <data>some_data</data>'.PHP_EOL.
- '</root_element>'.PHP_EOL,
+ 'xmlns:georss="http://www.georss.org/georss">'."\n".
+ ' <data>some_data</data>'."\n".
+ '</root_element>'."\n",
api_create_xml(['data' => ['some_data']], 'root_element')
);
}
public function testApiCreateXmlWithoutNamespaces()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
- '<ok>'.PHP_EOL.
- ' <data>some_data</data>'.PHP_EOL.
- '</ok>'.PHP_EOL,
+ '<?xml version="1.0"?>'."\n".
+ '<ok>'."\n".
+ ' <data>some_data</data>'."\n".
+ '</ok>'."\n",
api_create_xml(['data' => ['some_data']], 'ok')
);
}
public function testApiFormatDataWithXml()
{
$this->assertEquals(
- '<?xml version="1.0"?>'.PHP_EOL.
+ '<?xml version="1.0"?>'."\n".
'<root_element xmlns="http://api.twitter.com" xmlns:statusnet="http://status.net/schema/api/1/" '.
'xmlns:friendica="http://friendi.ca/schema/api/1/" '.
- 'xmlns:georss="http://www.georss.org/georss">'.PHP_EOL.
- ' <data>some_data</data>'.PHP_EOL.
- '</root_element>'.PHP_EOL,
+ 'xmlns:georss="http://www.georss.org/georss">'."\n".
+ ' <data>some_data</data>'."\n".
+ '</root_element>'."\n",
api_format_data('root_element', 'xml', ['data' => ['some_data']])
);
}
'width' => 666,
'height' => 666,
'tmp_name' => $this->getTempImage(),
+ 'name' => 'spacer.png',
'type' => 'image/png'
]
];
'width' => 666,
'height' => 666,
'tmp_name' => $this->getTempImage(),
+ 'name' => 'spacer.png',
'type' => 'image/png'
]
];
'width' => 666,
'height' => 666,
'tmp_name' => $this->getTempImage(),
+ 'name' => 'spacer.png',
'type' => 'image/png'
]
];
*/
public function testApiFavoritesCreateDestroy()
{
+ $this->app->argv = ['api', '1.1', 'favorites', 'create'];
+ $this->app->argc = count($this->app->argv);
api_favorites_create_destroy('json');
}
*/
public function testApiFavoritesCreateDestroyWithInvalidId()
{
- // This triggers a very specific condition ($action_argv_id + 2)
- $this->app->argv[1] = '1.1';
- $this->app->argc = 5;
+ $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
+ $this->app->argc = count($this->app->argv);
api_favorites_create_destroy('json');
}
*/
public function testApiFavoritesCreateDestroyWithInvalidAction()
{
- $this->app->argv[1] = '1.1';
- $this->app->argc = 10;
+ $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
+ $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 1;
api_favorites_create_destroy('json');
}
*/
public function testApiFavoritesCreateDestroyWithCreateAction()
{
- $this->app->argv[1] = '1.1';
- $this->app->argv[3] = 'create';
- $this->app->argc = 10;
+ $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
+ $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('json');
$this->assertStatus($result['status']);
*/
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{
- $this->app->argv[1] = '1.1';
- $this->app->argv[3] = 'create';
- $this->app->argc = 10;
+ $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
+ $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('rss');
$this->assertXml($result, 'status');
*/
public function testApiFavoritesCreateDestroyWithDestroyAction()
{
- $this->app->argv[1] = '1.1';
- $this->app->argv[3] = 'destroy';
- $this->app->argc = 10;
+ $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
+ $this->app->argc = count($this->app->argv);
$_REQUEST['id'] = 3;
$result = api_favorites_create_destroy('json');
$this->assertStatus($result['status']);
*/
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
+ $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
+ $this->app->argc = count($this->app->argv);
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
}
['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name']
);
- $this->assertEquals('item_title'.PHP_EOL.'item_body', $result['text']);
+ $this->assertEquals('item_title'."\n".'item_body', $result['text']);
$this->assertEquals(1, $result['id']);
$this->assertEquals(2, $result['recipient_id']);
$this->assertEquals(3, $result['sender_id']);
['id' => 2, 'screen_name' => 'recipient_name'],
['id' => 3, 'screen_name' => 'sender_name']
);
- $this->assertNull($result['sender']);
- $this->assertNull($result['recipient']);
+ $this->assertTrue(!isset($result['sender']));
+ $this->assertTrue(!isset($result['recipient']));
}
/**
'repellat officia illum quos impedit quam iste esse unde qui '.
'suscipit aut facilis ut inventore omnis exercitationem quo magnam '.
'consequatur maxime aut illum soluta quaerat natus unde aspernatur '.
- 'et sed beatae nihil ullam temporibus corporis ratione blanditiis'
+ 'et sed beatae nihil ullam temporibus corporis ratione blanditiis',
+ 'plink' => 'item_plink'
]
);
$this->assertStringStartsWith('item_title', $result['text']);
*/
public function testApiGetAttachmentsWithImage()
{
- $body = '[img]img_url[/img]';
+ $body = '[img]http://via.placeholder.com/1x1.png[/img]';
$this->assertInternalType('array', api_get_attachments($body));
}
public function testApiGetAttachmentsWithImageAndAndStatus()
{
$_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
- $body = '[img]img_url[/img]';
+ $body = '[img]http://via.placeholder.com/1x1.png[/img]';
$this->assertInternalType('array', api_get_attachments($body));
}
public function testApiFormatItemsEmbededImages()
{
$this->assertEquals(
- 'text http://localhost/display/item_guid',
+ 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid',
api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo')
);
}
*/
public function testApiFormatItemsActivities()
{
- $item = [];
+ $item = ['uid' => 0, 'uri' => ''];
$result = api_format_items_activities($item);
$this->assertArrayHasKey('like', $result);
$this->assertArrayHasKey('dislike', $result);
*/
public function testApiFormatItemsActivitiesWithXml()
{
- $item = [];
+ $item = ['uid' => 0, 'uri' => ''];
$result = api_format_items_activities($item, 'xml');
$this->assertArrayHasKey('friendica:like', $result);
$this->assertArrayHasKey('friendica:dislike', $result);
[
'item_network' => 'item_network',
'source' => 'web',
- 'coord' => '5 7'
+ 'coord' => '5 7',
+ 'body' => '',
+ 'verb' => '',
+ 'author-id' => 43,
+ 'author-network' => \Friendica\Core\Protocol::DFRN,
+ 'author-link' => 'http://localhost/profile/othercontact',
+ 'plink' => '',
]
];
- $result = api_format_items($items, [], true);
+ $result = api_format_items($items, ['id' => 0], true);
foreach ($result as $status) {
$this->assertStatus($status);
}
{
$items = [
[
- 'coord' => '5 7'
+ 'coord' => '5 7',
+ 'body' => '',
+ 'verb' => '',
+ 'author-id' => 43,
+ 'author-network' => \Friendica\Core\Protocol::DFRN,
+ 'author-link' => 'http://localhost/profile/othercontact',
+ 'plink' => '',
]
];
- $result = api_format_items($items, [], true, 'xml');
+ $result = api_format_items($items, ['id' => 0], true, 'xml');
foreach ($result as $status) {
$this->assertStatus($status);
}
*/
public function testApiHelpTestWithXml()
{
- $this->markTestIncomplete('Triggers this error: "key() expects parameter 1 to be array, string given"');
$result = api_help_test('xml');
$this->assertXml($result, 'ok');
}
$result = api_statusnet_config('json');
$this->assertEquals('localhost', $result['config']['site']['server']);
$this->assertEquals('default', $result['config']['site']['theme']);
- $this->assertEquals('http://localhost/images/friendica-64.png', $result['config']['site']['logo']);
+ $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']);
$this->assertTrue($result['config']['site']['fancy']);
$this->assertEquals('en', $result['config']['site']['language']);
$this->assertEquals('UTC', $result['config']['site']['timezone']);
public function testApiDirectMessagesNewWithScreenName()
{
$_POST['text'] = 'message_text';
- $_POST['screen_name'] = $this->otherUser['nick'];
+ $_POST['screen_name'] = $this->friendUser['nick'];
$result = api_direct_messages_new('json');
$this->assertEquals(1, $result['direct_message']['id']);
$this->assertContains('message_text', $result['direct_message']['text']);
public function testApiDirectMessagesNewWithTitle()
{
$_POST['text'] = 'message_text';
- $_POST['screen_name'] = $this->otherUser['nick'];
+ $_POST['screen_name'] = $this->friendUser['nick'];
$_REQUEST['title'] = 'message_title';
$result = api_direct_messages_new('json');
$this->assertEquals(1, $result['direct_message']['id']);
public function testApiDirectMessagesNewWithRss()
{
$_POST['text'] = 'message_text';
- $_POST['screen_name'] = $this->otherUser['nick'];
+ $_POST['screen_name'] = $this->friendUser['nick'];
$result = api_direct_messages_new('rss');
$this->assertXml($result, 'direct-messages');
}
*/
public function testApiShareAsRetweet()
{
- $item = [];
+ $item = ['body' => ''];
$result = api_share_as_retweet($item);
$this->assertFalse($result);
}
*/
public function testApiInReplyTo()
{
- $result = api_in_reply_to([]);
+ $result = api_in_reply_to(['id' => 0, 'parent' => 0, 'uri' => '', 'thr-parent' => '']);
$this->assertArrayHasKey('status_id', $result);
$this->assertArrayHasKey('user_id', $result);
$this->assertArrayHasKey('status_id_str', $result);
*/
public function testApiFriendicaNotificationWithArgumentCount()
{
- $this->app->argc = 3;
+ $this->app->argv = ['api', 'friendica', 'notification'];
+ $this->app->argc = count($this->app->argv);
$result = api_friendica_notification('json');
$this->assertEquals(['note' => false], $result);
}
*/
public function testApiFriendicaNotificationWithXmlResult()
{
- $this->markTestIncomplete('Fails with "Invalid argument supplied for foreach()".');
- $this->app->argc = 3;
+ $this->app->argv = ['api', 'friendica', 'notification'];
+ $this->app->argc = count($this->app->argv);
$result = api_friendica_notification('xml');
$this->assertXml($result, 'notes');
}
use TestCaseTrait;
+ /**
+ * Renames an eventually existing .htconfig.php to .htconfig.php.tmp
+ * Creates a new .htconfig.php for bin/worker.php execution
+ */
+ public static function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ $base_config_file_name = 'htconfig.php';
+ $config_file_name = '.htconfig.php';
+
+ $base_config_file_path = stream_resolve_include_path($base_config_file_name);
+ $config_file_path = dirname($base_config_file_path) . DIRECTORY_SEPARATOR . $config_file_name;
+ $config_file_path_tmp = $config_file_path . '.tmp';
+
+ if (file_exists($config_file_path)) {
+ rename($config_file_path, $config_file_path_tmp);
+ }
+
+ $config_string = file_get_contents($base_config_file_path);
+
+ $config_string = str_replace('die(', '// die(', $config_string);
+
+ file_put_contents($config_file_path, $config_string);
+ }
+
+ /**
+ * Delete the created .htconfig.php
+ * Renames an eventually existing .htconfig.php.tmp to .htconfig.php
+ */
+ public static function tearDownAfterClass()
+ {
+ $base_config_file_name = 'htconfig.php';
+ $config_file_name = '.htconfig.php';
+
+ $base_config_file_path = stream_resolve_include_path($base_config_file_name);
+ $config_file_path = dirname($base_config_file_path) . DIRECTORY_SEPARATOR . $config_file_name;
+ $config_file_path_tmp = $config_file_path . '.tmp';
+
+ if (file_exists($config_file_path)) {
+ unlink($config_file_path);
+ }
+
+ if (file_exists($config_file_path_tmp)) {
+ rename($config_file_path_tmp, $config_file_path);
+ }
+ }
+
/**
* Get database connection.
*
protected function getConnection()
{
if (!dba::$connected) {
- dba::connect('localhost', getenv('USER'), getenv('PASS'), getenv('DB'));
+ dba::connect(getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'), getenv('MYSQL_USERNAME'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE'));
if (dba::$connected) {
$app = get_app();
// We need to do this in order to disable logging
- $app->module = 'install';
+ $app->mode = \Friendica\App::MODE_INSTALL;
// Create database structure
DBStructure::update(false, true, true);
+
+ $app->mode = \Friendica\App::MODE_NORMAL;
} else {
- $this->markTestSkipped('Could not connect to the database.');
+ $this->markTestSkipped('Could not connect to the database. Please check the MYSQL_* environment variables.');
}
}
- return $this->createDefaultDBConnection(dba::get_db(), getenv('DB'));
+ return $this->createDefaultDBConnection(dba::get_db(), getenv('MYSQL_DATABASE'));
}
/**
network: dfrn
-
id: 44
- uid: 0
+ uid: 42
name: Friend contact
nick: friendcontact
self: 0