Skip to content

Commit

Permalink
fix #41 csv import
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Sep 17, 2023
1 parent cce444f commit 24b4082
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Änderungen
==========

## v1.11.3 (17.09.2023)
* fix csv import
## v1.11.2 (22.07.2023)
* fix warning in profile model used by t3sportstats

Expand Down
13 changes: 11 additions & 2 deletions Classes/Controller/Competition.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class Competition extends BaseModFunc
*/
private $selector;

/**
* @var DfbSync
*/
private $dfbSync;

public $MCONF;

/**
Expand All @@ -66,6 +71,11 @@ public function getModuleIdentifier()
return 'cfc_league';
}

public function __construct(DfbSync $dfbSync = null)
{
$this->dfbSync = $dfbSync ?: tx_rnbase::makeInstance(DfbSync::class);
}

/**
* Verwaltet die Erstellung von Spielplänen von Ligen.
*
Expand Down Expand Up @@ -134,8 +144,7 @@ protected function getContent($template, &$configurations, &$formatter, $formToo
break;
case 3:
$funcTemplate = Templates::getSubpart($template, '###FUNC_DFBSYNC###');
$mod = tx_rnbase::makeInstance(DfbSync::class);
$funcContent = $mod->main($this->getModule(), $current_league, $funcTemplate);
$funcContent = $this->dfbSync->main($this->getModule(), $current_league, $funcTemplate);

break;
}
Expand Down
19 changes: 14 additions & 5 deletions Classes/Controller/Competition/DfbSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2008-2021 Rene Nitzsche (rene@system25.de)
* (c) 2008-2023 Rene Nitzsche (rene@system25.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down Expand Up @@ -52,6 +52,16 @@ class DfbSync
protected $uploadedFiles = [];
protected $formTool;

/**
* @var Synchronizer
*/
private $synchronizer;

public function __construct(Synchronizer $synchronizer = null)
{
$this->synchronizer = $synchronizer ?: tx_rnbase::makeInstance(Synchronizer::class);
}

/**
* Verwaltet die Erstellung von Spielplänen von Ligen.
*
Expand All @@ -76,15 +86,14 @@ public function main(IModule $module, $competition, $template)
if (Parameters::getPostOrGetParameter('_upload')) {
if ($this->fileProcessor->internalUploadMap[1]) {
$markerArr['###STATUS_FILE###'] = $this->uploadedFiles[0]->getName();
/* @var $synch Synchronizer */
$synch = tx_rnbase::makeInstance(Synchronizer::class);
$info = $synch->process($this->uploadedFiles[0], $competition);
$info = $this->synchronizer->process($this->uploadedFiles[0], $competition);

$markerArr['###STATUS_MATCH_UPDATED###'] = $info['match']['updated'];
$markerArr['###STATUS_MATCH_NEW###'] = $info['match']['new'];
$markerArr['###STATUS_MATCH_SKIPPED###'] = $info['match']['skipped'];
$markerArr['###STATUS_TEAM_NEW###'] = $info['team']['new'];
$markerArr['###STATUS_TIME###'] = $synch->getStats()['total']['time'];
// FIXME: der Service sollte keinen Zustand haben
$markerArr['###STATUS_TIME###'] = $this->synchronizer->getStats()['total']['time'];
} else {
$markerArr['###STATUS_FILE###'] = '<span class="typo3-red">###LABEL_upload_failureNoFile###</span>';
$markerArr['###STATUS_MATCH_UPDATED###'] = 0;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/Competition/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function showTeamsFromPage($pid, Competition $competition)
$options['orderby']['TEAM.NAME'] = 'asc';
// $options['debug']=1;
$teams = $srv->searchTeams($fields, $options);
if (!count($teams)) {
if ($teams->isEmpty()) {
return '';
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/Dfb/CsvStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/***************************************************************
* Copyright notice
*
* (c) 2010-2020 Rene Nitzsche (rene@system25.de)
* (c) 2010-2023 Rene Nitzsche (rene@system25.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down Expand Up @@ -115,6 +115,8 @@ protected function init(array $headers)
self::COL_MATCH_ID => $this->createColData(),
self::COL_STADIUM => $this->createColData(),
self::COL_LEAGUE_IDENT => $this->createColData(),
self::COL_POSTPONE_DATE => $this->createColData(),
self::COL_POSTPONE_TIME => $this->createColData(),
];
foreach ($this->structure as $field => $data) {
if ($idx = array_search($field, $headers)) {
Expand Down
19 changes: 13 additions & 6 deletions Classes/Dfb/Synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use Sys25\RnBase\Utility\Logger;
use Sys25\RnBase\Utility\Strings;
use System25\T3sports\Model\Competition;
use System25\T3sports\Model\Repository\TeamRepository;
use System25\T3sports\Utility\ServiceRegistry;
use tx_rnbase;

/***************************************************************
* Copyright notice
*
* (c) 2010-2021 Rene Nitzsche (rene@system25.de)
* (c) 2010-2023 Rene Nitzsche (rene@system25.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand Down Expand Up @@ -56,6 +57,13 @@ class Synchronizer

private $pageUid = 0;

private $teamRepo;

public function __construct(TeamRepository $teamRepo = null)
{
$this->teamRepo = $teamRepo ?: new TeamRepository();
}

public function process(\TYPO3\CMS\Core\Resource\File $file, Competition $competition)
{
$fileContent = $this->removeBOM($file->getContents());
Expand All @@ -65,6 +73,7 @@ public function process(\TYPO3\CMS\Core\Resource\File $file, Competition $compet
$lines = explode("\n", $fileContent);
$headers = array_shift($lines);
$headers = str_getcsv($this->prepareHeaderLine($headers), "\t");
/** @var CsvStructure $structure */
$structure = tx_rnbase::makeInstance(CsvStructure::class, $headers);
$start = microtime(true);

Expand Down Expand Up @@ -185,16 +194,14 @@ protected function findTeam($extTeam, array &$data, Competition $competition, ar
$uid = 'NEW_'.$extTeamId;
if (!array_key_exists($extTeamId, $this->teamMap)) {
// Das Team ist noch nicht im Cache, also in der DB suchen
/* @var $teamSrv \tx_cfcleague_services_Teams */
$teamSrv = ServiceRegistry::getTeamService();
$fields = [];
$fields['TEAM.EXTID'][OP_EQ_NOCASE] = $extTeamId;
$fields['TEAM.PID'][OP_EQ_INT] = $competition->getPid();

$options = ['what' => 'uid'];
$ret = $teamSrv->searchTeams($fields, $options);
if (!empty($ret)) {
$this->teamMap[$extTeamId] = $ret[0]['uid'];
$ret = $this->teamRepo->search($fields, $options);
if (!$ret->isEmpty()) {
$this->teamMap[$extTeamId] = $ret->first()['uid'];
$uid = $this->teamMap[$extTeamId];
} else {
// In uid steht jetzt NEW_
Expand Down
4 changes: 2 additions & 2 deletions Classes/Service/ProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function checkReferences(Profile $profile)
'operator' => OP_INSET_INT,
];
$result = ServiceRegistry::getTeamService()->searchTeams($fields, $options);
if (count($result)) {
$ret['tx_cfcleague_teams'] = $result;
if (!$result->isEmpty()) {
$ret['tx_cfcleague_teams'] = $result->toArray();
}

$fields = [];
Expand Down
5 changes: 3 additions & 2 deletions Classes/Service/TeamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace System25\T3sports\Service;

use Sys25\RnBase\Cache\CacheManager;
use Sys25\RnBase\Domain\Collection\BaseCollection;
use Sys25\RnBase\Domain\Model\MediaModel;
use Sys25\RnBase\Search\SearchBase;
use Sys25\RnBase\Typo3Wrapper\Service\AbstractService;
Expand Down Expand Up @@ -136,7 +137,7 @@ public function getTeamNotes(Team $team, $type = false)
* @param Competition $comp
* @param bool $asArray Wenn 1 wird pro Team ein Array mit Name, Kurzname und Flag spielfrei geliefert
*
* @return array
* @return string[]
*/
public function getTeamNames(Competition $comp, $asArray = false)
{
Expand Down Expand Up @@ -235,7 +236,7 @@ public function searchTeamNotes($fields, $options)
* @param array $fields
* @param array $options
*
* @return Team[]
* @return BaseCollection<Team>
*/
public function searchTeams($fields, $options)
{
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ services:

System25\T3sports\Service\ProfileService:
public: true

System25\T3sports\Controller\Competition:
public: true
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'description' => 'Umfangreiche Extension zur Verwaltung von Sportvereinen und -wettbewerben. Extensive extension to manage sports clubs and competitions. https://github.com/digedag/cfc_league',
'category' => 'module',
'shy' => 0,
'version' => '1.11.2',
'version' => '1.11.3',
'dependencies' => 'rn_base',
'module' => 'mod1',
'state' => 'stable',
Expand Down

0 comments on commit 24b4082

Please sign in to comment.