Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Falko Trojahn committed Oct 31, 2023
1 parent 7483cd4 commit 7cce167
Show file tree
Hide file tree
Showing 19 changed files with 371 additions and 137 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/Tests export-ignore
/.* export-ignore
/ExtensionBuilder.json export-ignore
/phpstan.neon export-ignore
52 changes: 52 additions & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release

on:
push:
tags:
- '*'

jobs:
publish:
name: Publish new version to TER
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
env:
TYPO3_API_TOKEN: ${{ secrets.TYPO3_API_TOKEN }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Check tag
run: |
if ! [[ ${{ github.ref }} =~ ^refs/tags/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$ ]]; then
exit 1
fi
- name: Get version
id: get-version
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: Get comment
id: get-comment
run: |
readonly local comment=$(git tag -n10 -l ${{ env.version }} | sed "s/^[0-9.]*[ ]*//g")
if [[ -z "${comment// }" ]]; then
echo "comment=Released version ${{ env.version }} of ${{ env.TYPO3_EXTENSION_KEY }}" >> $GITHUB_ENV
else
echo "comment=$comment" >> $GITHUB_ENV
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: intl, mbstring, json, zip, curl
tools: composer:v2

- name: Install tailor
run: composer global require typo3/tailor --prefer-dist --no-progress

- name: Publish to TER
run: php ~/.composer/vendor/bin/tailor ter:publish --comment "${{ env.comment }}" ${{ env.version }}
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Testing calendarize_external
on: [push, pull_request]
jobs:
build:
strategy:
fail-fast: false
matrix:
php: ["7.4", "8.1", "8.2"]
typo3: ["10.4","11.5"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
extensions: pdo

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Get composer cache directory
id: composercache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install the right version
run: composer require "typo3/cms-core:^${{ matrix.typo3 }}" "typo3/cms-workspaces:^${{ matrix.typo3 }}" -W

- name: Unit Tests with phpunit
run: composer run tool:phpunit --

# start db
- name: Start MySQL
run: sudo /etc/init.d/mysql start

# functional tests
- name: Functional Tests
run: |
export typo3DatabaseName="typo3";
export typo3DatabaseHost="127.0.0.1";
export typo3DatabaseUsername="root";
export typo3DatabasePassword="root";
composer run tool:phpunit:functional --
- name: Run PHP CS Fixer checks
run: composer run tool:php-cs-fixer-check

# - name: Run DepTrac
# run: composer run tool:deptrac

- name: Reset composer.json
run: git checkout composer.json;
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[TASK] prepare CI tools 0afd597 2023-10-31 Falko Trojahn

[BUGFIX] console output shows calendar and pageIds even if not run due to errors d5d778c 2023-10-30 Falko Trojahn

[TASK] tca evaluation class for error_count reset #3679 1f47a1e 2023-02-10 Falko Trojahn
Expand Down
59 changes: 25 additions & 34 deletions Classes/Command/CalImportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

class CalImportCommandController extends Command
{

/**
* @var ICalServiceInterface
*/
Expand Down Expand Up @@ -59,17 +54,16 @@ class CalImportCommandController extends Command
/**
* ImportCommandController constructor.
*
* @param ICalServiceInterface $iCalService
* @param ICalServiceInterface $iCalService
* @param EventDispatcherInterface $eventDispatcher
* @param IndexerService $indexerService
* @param IndexerService $indexerService
*/
public function __construct(
ICalServiceInterface $iCalService,
ICalServiceInterface $iCalService,
EventDispatcherInterface $eventDispatcher,
IndexerService $indexerService,
ICalUrlService $iCalUrlService
)
{
IndexerService $indexerService,
ICalUrlService $iCalUrlService
) {
$this->iCalService = $iCalService;
$this->eventDispatcher = $eventDispatcher;
$this->indexerService = $indexerService;
Expand All @@ -79,11 +73,10 @@ public function __construct(
->get('calendarize_external', 'scheduleRanges');
$this->scheduleRanges = (explode(',', $scheduleRanges));
if (empty($this->scheduleRanges[0])) {
$this->scheduleRanges = array(2, 6);
$this->scheduleRanges = [2, 6];
}

parent::__construct();

}

protected function configure()
Expand All @@ -92,7 +85,7 @@ protected function configure()
->addArgument(
'schedule',
InputArgument::REQUIRED,
"The frequency in hours must be one of: " . implode(',', $this->scheduleRanges) . " \r\n"
'The frequency in hours must be one of: ' . implode(',', $this->scheduleRanges) . " \r\n"
. "Hint: You can set the schedule ranges in the extension configuration.\r\n"
)
->addOption(
Expand All @@ -114,9 +107,9 @@ protected function configure()
}

/**
* Executes the command to import all external calendars
* Executes the command to import all external calendars.
*
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int 0 if everything went fine, or an exit code
Expand All @@ -128,15 +121,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$table = 'tx_calendarizeexternal_domain_model_calendar';


$schedule = $input->getArgument('schedule');
if (MathUtility::canBeInterpretedAsInteger($schedule)) {
$schedulemin = 0;
foreach ($this->scheduleRanges as $scheduleRange) {
if ($schedule > $scheduleRange) {
$schedulemin = $scheduleRange;
} else {
continue 1;
continue;
}
}
$io->text('Run all external calendars which have set schedule range between ' . $schedulemin . ' and <=' . $schedule . 'h.');
Expand All @@ -150,12 +142,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$since = $input->getOption('since');
$reindex = $input->getOption('reindex');
$ignoreBeforeDate = null;
$ignoreTwoYearsBeforeDate = new \DateTime("-2 years");
$ignoreTwoYearsBeforeDate = new \DateTime('-2 years');
$msgsince = '';
if (null !== $since) {
$ignoreBeforeDate = new \DateTime("-" . ltrim($since, '-'));
$ignoreBeforeDate = new \DateTime('-' . ltrim($since, '-'));
$io->text('Skipping all events before ' . $ignoreBeforeDate->format(\DateTimeInterface::ATOM));
$msgsince = $ignoreBeforeDate->format("d-m-y H:i");
$msgsince = $ignoreBeforeDate->format('d-m-y H:i');
}

$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
Expand Down Expand Up @@ -183,11 +175,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$errorcount = $record['error_count'];
if ($errorcount > 10) {
// do not run, has to be cleared manually in Backend-record
$io->warning('Not running: error count is:' . $errorcount );
$io->warning('Not running: error count is:' . $errorcount);
continue;
}
$ignoreDate = $ignoreBeforeDate; // from --since
if ($record['last_run'] == 0) {
if (0 == $record['last_run']) {
$ignoreDate = $ignoreTwoYearsBeforeDate; // default if not run
}

Expand All @@ -197,11 +189,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$icalFile = $this->iCalUrlService->getOrCreateLocalFileForUrl($record['ics_url']);
// @todo create md5 from content
$contents = GeneralUtility::getURL($icalFile);
$md5 = md5 ($contents);
$md5 = md5($contents);
} catch (UnableToGetFileForUrlException $e) {
$io->error('Invalid URL: ' . $e->getMessage());
$errormsg .= "ical: invalid url.\r\n";
$errorcount++;
++$errorcount;
$connection->update(
$table,
['last_message' => "ERROR: \r\n" . $errormsg, 'last_run' => $lastrun, 'error_count' => $errorcount],
Expand All @@ -210,8 +202,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}
if (!empty($record['md5']) && !empty($md5) && $md5 == $record['md5']
&& $record['last_run'] != 0) {
$io->text('ical file has not been changed (md5) - not importing');
&& 0 != $record['last_run']) {
$io->text('ical file has not been changed (md5) - not importing');
// Remove temporary file
GeneralUtility::unlink_tempfile($icalFile);
continue;
Expand All @@ -228,7 +220,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$errormsg .= 'Unable to process events: ' . $e->getMessage();
$errorcount++;
++$errorcount;
$connection->update(
$table,
['last_message' => "ERROR: \r\n" . $errormsg, 'last_run' => $lastrun, 'error_count' => $errorcount],
Expand All @@ -240,8 +232,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
GeneralUtility::unlink_tempfile($icalFile);
}

$io->text('Found ' . \count($events) . ' events in ' . $record['title'] );
$msg .= "Found " . \count($events) . " events. \r\n";
$io->text('Found ' . \count($events) . ' events in ' . $record['title']);
$msg .= 'Found ' . \count($events) . " events. \r\n";

$io->section('Send ImportSingleIcalEvent for each event');
$io->progressStart(\count($events));
Expand Down Expand Up @@ -277,15 +269,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($exceptionCount > 0) {
$msg .= "$exceptionCount events had errors";
// @todo event errors count as one error ?
$errorcount++;
++$errorcount;
}
$msg .= (($record['last_run'] == 0) ? " not within last two years (first run only)." : ($msgsince ? " before " . $msgsince : "")) . "\r\n";
$msg .= ((0 == $record['last_run']) ? ' not within last two years (first run only).' : ($msgsince ? ' before ' . $msgsince : '')) . "\r\n";
$connection->update(
$table,
['last_message' => $msg, 'last_run' => $lastrun, 'error_count' => $errorcount, 'md5' => $md5],
['uid' => $record['uid']]
);

}
// after all calendar imports run reindex events
if ($reindex) {
Expand Down
Loading

0 comments on commit 7cce167

Please sign in to comment.