Commit 4032840e authored by Thomas Löffler's avatar Thomas Löffler Committed by Stefan Busemann

Introduce test build and fix CGL issues

parent 0fe7fa63
......@@ -7,10 +7,21 @@ before_script:
stages:
- dump
- test
- build
- layout
- deploy
test:php:
stage: test
image: ekreative/php-cs-fixer:2
variables:
GIT_STRATEGY: "clone"
script:
- php-cs-fixer fix --dry-run --config=.gitlab-ci/build/.php_cs --diff
except:
- assets
build:
stage: build
image: php:7.0-alpine
......
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This file represents the configuration for Code Sniffing PSR-2-related
* automatic checks of coding guidelines
* Install @fabpot's great php-cs-fixer tool via
*
* $ composer global require friendsofphp/php-cs-fixer
*
* And then simply run
*
* $ php-cs-fixer fix --config ../Build/.php_cs
*
* inside the TYPO3 directory. Warning: This may take up to 10 minutes.
*
* For more information read:
* https://www.php-fig.org/psr/psr-2/
* https://cs.sensiolabs.org
*/
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
// Define in which folders to search and which folders to exclude
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('typo3temp')
->in(__DIR__ . '/../../');
// Return a Code Sniffing configuration using
// all sniffers needed for PSR-2
// and additionally:
// - Remove leading slashes in use clauses.
// - PHP single-line arrays should not have trailing comma.
// - Single-line whitespace before closing semicolon are prohibited.
// - Remove unused use statements in the PHP source code
// - Ensure Concatenation to have at least one whitespace around
// - Remove trailing whitespace at the end of blank lines.
return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'concat_space' => ['spacing' => 'one'],
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'single_quote' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'no_blank_lines_after_phpdoc' => true,
'array_syntax' => ['syntax' => 'short'],
'whitespace_after_comma_in_array' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'no_alias_functions' => true,
'lowercase_cast' => true,
'no_leading_namespace_whitespace' => true,
'native_function_casing' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_trim' => true,
'no_superfluous_elseif' => true,
'no_useless_else' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'cast_spaces' => ['space' => 'none'],
'declare_equal_normalize' => ['space' => 'single'],
'dir_constant' => true,
])->setFinder($finder);
......@@ -2,7 +2,6 @@
/** #ddev-generated: Automatically generated TYPO3 AdditionalConfiguration.php file.
ddev manages this file and may delete or overwrite the file unless this comment is removed.
*/
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'], [
......@@ -23,4 +22,4 @@ $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = [
];
$GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'] = '$P$CZqeoYBTHC0kXKny4tpTvBSzzV5wVY0'; /* joh316 */
$GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'normal';
\ No newline at end of file
$GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'normal';
<?php
namespace T3o\T3oSlack\Command;
use T3o\T3oSlack\Domain\Model\SlackUser;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use \TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use \T3o\T3oSlack\Domain\Service\SlackApi;
use T3o\T3oSlack\Domain\Service\SlackApi;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
/***************************************************************
* Copyright notice
......@@ -35,7 +33,6 @@ use TYPO3\CMS\Core\TypoScript\TypoScriptService;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class SlackImportCommandController extends CommandController
{
/**
......@@ -50,15 +47,15 @@ class SlackImportCommandController extends CommandController
public $settings;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
* @var \T3o\T3oSlack\Domain\Service\SlackApi;
*/
protected $configurationManager;
public $slackApi;
/**
* @var \T3o\T3oSlack\Service\SlackApi;
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
*/
public $slackApi;
protected $configurationManager;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
......@@ -68,12 +65,12 @@ class SlackImportCommandController extends CommandController
/**
* Import all Slack Users
*
* @return string '1' for success, '0' for error
* @throws \Exception
*/
public function importCommand()
{
$this->getTSConfiguration();
// delete all uses before fresh import
......@@ -82,57 +79,51 @@ class SlackImportCommandController extends CommandController
$this->persistenceManager->persistAll();
$this->slackApi = GeneralUtility::makeInstance(SlackApi::class);
$cursor='';
$cursor = '';
$limiter = 0;
$counter = 0;
do {
$response = $this->slackApi->getUsers($cursor);
if ($response['ok']) {
foreach ($response['members'] as $member ) {
if ($member['is_bot']==false) {
$slackUser = GeneralUtility::makeInstance(SlackUser::class);
$slackUser->setEmail ($member['profile']['email']);
$slackUser->setRealName ($member['real_name']);
$slackUser->setSlackId($member['id']);
$slackUser->setSlackUserName($member['name']);
$counter++;
$this->slackUserRepository->add($slackUser);
}
}
if ($response['response_metadata']['next_cursor'])
{
$cursor = $response['response_metadata']['next_cursor'];
}
else {
$cursor = '';
}
$this->persistenceManager->persistAll();
$limiter++;
if (!$response['ok']) {
throw new \Exception('Slack API error . Reason: ' . $response['error']);
}
if ($limiter>999)
{
// break loop, if we have more then 999 loops
throw new \Exception('Slack import stopped, due to many loops.');
$cursor='';
foreach ($response['members'] as $member) {
if ($member['is_bot'] == false) {
$slackUser = GeneralUtility::makeInstance(SlackUser::class);
$slackUser->setEmail($member['profile']['email']);
$slackUser->setRealName($member['real_name']);
$slackUser->setSlackId($member['id']);
$slackUser->setSlackUserName($member['name']);
$counter++;
$this->slackUserRepository->add($slackUser);
}
}
else {
throw new \Exception('Slack API error . Reason: ' . $response['error']);
if ($response['response_metadata']['next_cursor']) {
$cursor = $response['response_metadata']['next_cursor'];
} else {
$cursor = '';
}
$this->persistenceManager->persistAll();
$limiter++;
if ($limiter > 999) {
// break loop, if we have more then 999 loops
throw new \Exception('Slack import stopped, due to many loops.');
}
} while ($cursor);
$GLOBALS['BE_USER']->simplelog('Import of Slack User sucessful - imported ' . $counter . ' users', $extKey='t3o_slack', $error=0);
$GLOBALS['BE_USER']->simplelog(
'Import of Slack User sucessful - imported ' . $counter . ' users',
't3o_slack'
);
return '1';
}
/**
* @return void
*/
protected function getTSConfiguration()
{
// load complete ts
......
<?php
declare(strict_types=1);
declare(strict_types = 1);
namespace T3o\T3oSlack\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
/**
......@@ -13,7 +14,7 @@ class SlackFrontendUser extends FrontendUser
*
* @var string
*/
protected $slackId ='';
protected $slackId = '';
/**
* @return string
......
......@@ -28,13 +28,6 @@ namespace T3o\T3oSlack\Domain\Model;
use T3o\T3oSlack\Domain\Service\SlackApi;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
*
*
* @package t3o_slack
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class SlackUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
......@@ -118,22 +111,6 @@ class SlackUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
$this->realName = $realName;
}
/**
* @return string
*/
public function getSlackId(): string
{
return $this->slackId;
}
/**
* @param string $slackId
*/
public function setSlackId(string $slackId)
{
$this->slackId = $slackId;
}
/**
* @return string
*/
......@@ -157,17 +134,16 @@ class SlackUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
if ($this->presence) {
return $this->presence;
} else {
$SlackAPI = GeneralUtility::makeInstance(SlackApi::class);
$result = $SlackAPI->getUserPresence($this);
if ($result['ok'] === true) {
$this->presence = $result['presence'];
return $this->presence;
} else {
return $result['error'];
}
}
$slackApi = GeneralUtility::makeInstance(SlackApi::class);
$result = $slackApi->getUserPresence($this);
if ($result['ok'] === true) {
$this->presence = $result['presence'];
return $this->presence;
}
return $result['error'];
}
/**
......@@ -175,13 +151,29 @@ class SlackUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
public function getSlackProfile()
{
$SlackAPI = GeneralUtility::makeInstance(SlackApi::class);
$this->slackProfile = $SlackAPI->getUser($this->getSlackId());
$slackApi = GeneralUtility::makeInstance(SlackApi::class);
$this->slackProfile = $slackApi->getUser($this->getSlackId());
if (is_array($this->slackProfile)) {
return $this->slackProfile;
} else {
return array();
}
return [];
}
/**
* @return string
*/
public function getSlackId(): string
{
return $this->slackId;
}
/**
* @param string $slackId
*/
public function setSlackId(string $slackId)
{
$this->slackId = $slackId;
}
/**
......@@ -189,12 +181,12 @@ class SlackUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
public function getLink()
{
$SlackAPI = GeneralUtility::makeInstance(SlackApi::class);
$this->link = $SlackAPI->getMessageLink($this);
$slackApi = GeneralUtility::makeInstance(SlackApi::class);
$this->link = $slackApi->getMessageLink($this);
if ($this->link['ok'] === true) {
return $this->link['channel']['id'];
} else {
return '';
}
return '';
}
}
<?php
declare(strict_types=1);
declare(strict_types = 1);
namespace T3o\T3oSlack\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
......@@ -9,5 +9,4 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
*/
class SlackFrontendUserRepository extends Repository
{
}
......@@ -2,43 +2,36 @@
namespace T3o\T3oSlack\Domain\Repository;
/***************************************************************
* Copyright notice
*
* (c) 2015-2017
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Copyright notice
*
* (c) 2015-2017
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* @package t3o_slack
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class SlackUserRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* @param $email
* @return
*/
public function findByEmail($email) {
public function findByEmail($email)
{
$query = $this->createQuery();
$and = [$query->equals('email', $email)];
......@@ -50,7 +43,8 @@ class SlackUserRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
* @param $slackId
* @return
*/
public function findBySlackId($slackId) {
public function findBySlackId($slackId)
{
$query = $this->createQuery();
// this is needed, for the contecxt of the viewhelper ShowSlackLinkViewHelper, because the viewhelper is used
......
<?php
declare(strict_types=1);
declare(strict_types = 1);
namespace T3o\T3oSlack\Domain\Service;
use TYPO3\CMS\Core\SingletonInterface;
......@@ -10,7 +10,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/
class ConfigurationService implements SingletonInterface
{
/**
* @var array
*/
......@@ -21,12 +20,11 @@ class ConfigurationService implements SingletonInterface
*/
public function getTypoScriptSettings()
{
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
// get the whole ts
$extbaseFrameworkConfiguration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
return (array)$extbaseFrameworkConfiguration['plugin.']['tx_t3oslack.']['settings.'];
}
}
<?php
namespace T3o\T3oSlack\Domain\Service;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use T3o\T3oSlack\Domain\Model\SlackUser;
use T3o\T3oSlack\Domain\Service\ConfigurationService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
*
*
* @package t3o_slack
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class SlackApi
{
/**
......@@ -42,24 +34,24 @@ class SlackApi
$configurationService = $objectManager->get(ConfigurationService::class);
$settings = $configurationService->getTypoScriptSettings();
$this->token = $settings['Slack.']['token'];
$this->adb_url = $settings['Slack.']['teamUrl'];
$this->token = $settings['Slack.']['token'];
$this->adb_url = $settings['Slack.']['teamUrl'];
}
/**
* action create
*
* @param \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser
* @return void
* @return array
*/
public function createUser(SlackUser $newSlackUser)
{
$adb_handle = $this->prepareCurlInit();
$options = array(
CURLOPT_URL => $this->adb_url . '/api/users.admin.invite',
$options = [
CURLOPT_URL => $this->adb_url . '/api/users.admin.invite',
CURLOPT_CUSTOMREQUEST => 'POST', // GET POST PUT PATCH DELETE HEAD OPTIONS
CURLOPT_POSTFIELDS => 'email=' . urlencode($newSlackUser->getEmail()) . '&first_name=' . urlencode($newSlackUser->getSlackUserName()) . '&token=' . $this->token . '&set_active=true'
);
CURLOPT_POSTFIELDS => 'email=' . urlencode($newSlackUser->getEmail()) . '&first_name=' . urlencode($newSlackUser->getSlackUserName()) . '&token=' . $this->token . '&set_active=true'
];
curl_setopt_array($adb_handle, ($options + $this->adb_option_defaults));
......@@ -67,10 +59,22 @@ class SlackApi
return json_decode(curl_exec($adb_handle), true);
}
public function prepareCurlInit()
{
// Initialize options for REST interface
$this->adb_option_defaults = [
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 2
];
return curl_init();
}
/**
*
* @param string $cursor
* @return void
* @return array
*/
public function getUsers($cursor = '')
{
......@@ -82,35 +86,33 @@ class SlackApi
$curlopt_postfields = $curlopt_postfields . '&cursor=' . $cursor;
}
$options = array(
CURLOPT_URL => $this->adb_url . '/api/users.list',
CURLOPT_CUSTOMREQUEST => 'POST', // GET POST PUT PATCH DELETE HEAD OPTIONS
CURLOPT_POSTFIELDS => $curlopt_postfields
);
$options = [
CURLOPT_URL => $this->adb_url . '/api/users.list',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $curlopt_postfields
];
curl_setopt_array($adb_handle, ($options + $this->adb_option_defaults));
// send request and wait for response
return json_decode(curl_exec($adb_handle), true);
}
/**
*
* @param $slackID
* @return void
* @param $slackId