Superflous spaces

This commit is contained in:
Michael 2022-01-16 07:14:09 +00:00
parent c55c42b303
commit 8ff2cc3976
8 changed files with 35 additions and 36 deletions

View file

@ -35,27 +35,27 @@ class Create extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
// params // params
$name = $_REQUEST['name'] ?? ''; $name = $_REQUEST['name'] ?? '';
$json = json_decode($_POST['json'], true); $json = json_decode($_POST['json'], true);
$users = $json['user']; $users = $json['user'];
// error if no name specified // error if no name specified
if ($name == '') { if ($name == '') {
throw new HTTPException\BadRequestException('group name not specified'); throw new HTTPException\BadRequestException('group name not specified');
} }
// error message if specified group name already exists // error message if specified group name already exists
if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) { if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
throw new HTTPException\BadRequestException('group name already exists'); throw new HTTPException\BadRequestException('group name already exists');
} }
// Check if the group needs to be reactivated // Check if the group needs to be reactivated
if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => true])) { if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => true])) {
$reactivate_group = true; $reactivate_group = true;
} }
// create group // create group
$ret = Group::create($uid, $name); $ret = Group::create($uid, $name);
if ($ret) { if ($ret) {
@ -63,7 +63,7 @@ class Create extends BaseApi
} else { } else {
throw new HTTPException\BadRequestException('other API error'); throw new HTTPException\BadRequestException('other API error');
} }
// add members // add members
$erroraddinguser = false; $erroraddinguser = false;
$errorusers = []; $errorusers = [];
@ -76,12 +76,12 @@ class Create extends BaseApi
$errorusers[] = $cid; $errorusers[] = $cid;
} }
} }
// return success message incl. missing users in array // return success message incl. missing users in array
$status = ($erroraddinguser ? 'missing user' : ((isset($reactivate_group) && $reactivate_group) ? 'reactivated' : 'ok')); $status = ($erroraddinguser ? 'missing user' : ((isset($reactivate_group) && $reactivate_group) ? 'reactivated' : 'ok'));
$result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers]; $result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
$this->response->exit('group_create', ['$result' => $result], $this->parameters['extension'] ?? null); $this->response->exit('group_create', ['$result' => $result], $this->parameters['extension'] ?? null);
} }
} }

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Api\Friendica\Group; namespace Friendica\Module\Api\Friendica\Group;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException; use Friendica\Network\HTTPException\BadRequestException;

View file

@ -37,14 +37,14 @@ class Show extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? ''; $type = $this->parameters['extension'] ?? '';
// params // params
$gid = $_REQUEST['gid'] ?? 0; $gid = $_REQUEST['gid'] ?? 0;
// get data of the specified group id or all groups if not specified // get data of the specified group id or all groups if not specified
if ($gid != 0) { if ($gid != 0) {
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'id' => $gid]); $groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!DBA::isResult($groups)) { if (!DBA::isResult($groups)) {
throw new HTTPException\BadRequestException('gid not available'); throw new HTTPException\BadRequestException('gid not available');
@ -52,13 +52,13 @@ class Show extends BaseApi
} else { } else {
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid]); $groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid]);
} }
// loop through all groups and retrieve all members for adding data in the user array // loop through all groups and retrieve all members for adding data in the user array
$grps = []; $grps = [];
foreach ($groups as $rr) { foreach ($groups as $rr) {
$members = Contact\Group::getById($rr['id']); $members = Contact\Group::getById($rr['id']);
$users = []; $users = [];
if ($type == 'xml') { if ($type == 'xml') {
$user_element = 'users'; $user_element = 'users';
$k = 0; $k = 0;

View file

@ -53,33 +53,33 @@ class Create extends BaseApi
$this->dba = $dba; $this->dba = $dba;
$this->friendicaGroup = $friendicaGroup; $this->friendicaGroup = $friendicaGroup;
} }
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
// params // params
$name = $_REQUEST['name'] ?? ''; $name = $_REQUEST['name'] ?? '';
if ($name == '') { if ($name == '') {
throw new HTTPException\BadRequestException('group name not specified'); throw new HTTPException\BadRequestException('group name not specified');
} }
// error message if specified group name already exists // error message if specified group name already exists
if ($this->dba->exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) { if ($this->dba->exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
throw new HTTPException\BadRequestException('group name already exists'); throw new HTTPException\BadRequestException('group name already exists');
} }
$ret = Group::create($uid, $name); $ret = Group::create($uid, $name);
if ($ret) { if ($ret) {
$gid = Group::getIdByName($uid, $name); $gid = Group::getIdByName($uid, $name);
} else { } else {
throw new HTTPException\BadRequestException('other API error'); throw new HTTPException\BadRequestException('other API error');
} }
$grp = $this->friendicaGroup->createFromId($gid); $grp = $this->friendicaGroup->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }

View file

@ -53,29 +53,29 @@ class Destroy extends BaseApi
$this->dba = $dba; $this->dba = $dba;
$this->friendicaGroup = $friendicaGroup; $this->friendicaGroup = $friendicaGroup;
} }
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
// params // params
$gid = $_REQUEST['list_id'] ?? 0; $gid = $_REQUEST['list_id'] ?? 0;
// error if no gid specified // error if no gid specified
if ($gid == 0) { if ($gid == 0) {
throw new HTTPException\BadRequestException('gid not specified'); throw new HTTPException\BadRequestException('gid not specified');
} }
// get data of the specified group id // get data of the specified group id
$group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]); $group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!$group) { if (!$group) {
throw new HTTPException\BadRequestException('gid not available'); throw new HTTPException\BadRequestException('gid not available');
} }
$list = $this->friendicaGroup->createFromId($gid); $list = $this->friendicaGroup->createFromId($gid);
if (Group::remove($gid)) { if (Group::remove($gid)) {
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }

View file

@ -55,9 +55,9 @@ class Ownership extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$groups = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid]); $groups = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid]);
// loop through all groups // loop through all groups
$lists = []; $lists = [];
foreach ($groups as $group) { foreach ($groups as $group) {

View file

@ -54,7 +54,7 @@ class Statuses extends BaseApi
$this->dba = $dba; $this->dba = $dba;
$this->twitterStatus = $twitterStatus; $this->twitterStatus = $twitterStatus;
} }
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);

View file

@ -58,26 +58,26 @@ class Update extends BaseApi
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
// params // params
$gid = $_REQUEST['list_id'] ?? 0; $gid = $_REQUEST['list_id'] ?? 0;
$name = $_REQUEST['name'] ?? ''; $name = $_REQUEST['name'] ?? '';
// error if no gid specified // error if no gid specified
if ($gid == 0) { if ($gid == 0) {
throw new HTTPException\BadRequestException('gid not specified'); throw new HTTPException\BadRequestException('gid not specified');
} }
// get data of the specified group id // get data of the specified group id
$group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]); $group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database // error message if specified gid is not in database
if (!$group) { if (!$group) {
throw new HTTPException\BadRequestException('gid not available'); throw new HTTPException\BadRequestException('gid not available');
} }
if (Group::update($gid, $name)) { if (Group::update($gid, $name)) {
$list = $this->friendicaGroup->createFromId($gid); $list = $this->friendicaGroup->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); $this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
} }
} }