Commit 259cfd1e authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[BUGFIX] change TYPO3_DB to doctrine

parent 3c133f96
......@@ -3,7 +3,11 @@
namespace T3o\T3oMembership\Task;
use Dropbox\Dropbox;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Scheduler\Task;
/**
* This file is part of the TYPO3 CMS project.
......@@ -17,7 +21,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*
* The TYPO3 project - inspiring people to share!
*/
class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
class ImportMembersTask extends Task
{
/**
* @var array
......@@ -50,14 +54,13 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
public function execute()
{
/** @var $logger \TYPO3\CMS\Core\Log\Logger */
$logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->debug('Execute');
$membershipRecords = $this->getDatabaseConnection()->exec_SELECTgetRows(
'uid, name',
'tx_t3omembership_domain_model_membership',
'NOT hidden AND NOT deleted'
);
$membershipRecords = $this->getDatabaseConnection()
->getConnectionForTable('tx_t3omembership_domain_model_membership')
->select(['uid', 'name'], 'tx_t3omembership_domain_model_membership')
->fetchAll();
foreach ($membershipRecords as $membershipRecord) {
$this->memberships[$membershipRecord['name']] = (int)$membershipRecord['uid'];
......@@ -102,26 +105,26 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
}
$member = array(
'name' => $fields[6],
'name' => $fields[6],
'subscription_no' => $subscriptionNo,
'external_id' => (int)$fields[0],
'address' => $fields[7] !== '' ? $fields[7] : $fields[8],
'zip' => $fields[10],
'city' => $fields[11],
'country' => $fields[13],
'end_date' => $endDate,
'endtime' => $endTime,
'hidden' => $hidden,
'starttime' => 0,
'membership' => $membershipUid,
'pid' => $this->membershipStoragePid,
'crdate' => time(),
'tstamp' => time(),
'invoice_email' => $fields[84],
'email' => $fields[79],
'url' => $fields[80],
'firstname' => $fields[82],
'lastname' => $fields[83]
'external_id' => (int)$fields[0],
'address' => $fields[7] !== '' ? $fields[7] : $fields[8],
'zip' => $fields[10],
'city' => $fields[11],
'country' => $fields[13],
'end_date' => $endDate,
'endtime' => $endTime,
'hidden' => $hidden,
'starttime' => 0,
'membership' => $membershipUid,
'pid' => $this->membershipStoragePid,
'crdate' => time(),
'tstamp' => time(),
'invoice_email' => $fields[84],
'email' => $fields[79],
'url' => $fields[80],
'firstname' => $fields[82],
'lastname' => $fields[83]
);
$memberUid = $this->createOrUpdateMember($subscriptionNo, $member);
......@@ -146,29 +149,38 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
*/
protected function createOrUpdateMember($subscriptionNo, array $memberData)
{
$existingMember = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
'uid',
'tx_t3omembership_domain_model_member',
'subscription_no=' . $subscriptionNo
);
$queryBuilder = $this->getDatabaseConnection()
->getQueryBuilderForTable('tx_t3omembership_domain_model_member');
$statement = $queryBuilder->select('uid')
->from('tx_t3omembership_domain_model_member')
->where(
$queryBuilder->expr()->eq('subscription_no',
$queryBuilder->createNamedParameter($subscriptionNo, \PDO::PARAM_INT))
)->execute();
$existingMember = $statement->fetch();
if (!empty($existingMember['uid'])) {
$memberUid = $existingMember['uid'];
$resource = $this->getDatabaseConnection()->exec_UPDATEquery(
'tx_t3omembership_domain_model_member',
'uid=' . (int)$memberUid,
$memberData
);
$this->getDatabaseConnection()
->getConnectionForTable('tx_t3omembership_domain_model_member')
->update(
'tx_t3omembership_domain_model_member',
$memberData,
['uid' => (int)$memberUid],
[Connection::PARAM_INT]
);
} else {
$resource = $this->getDatabaseConnection()->exec_INSERTquery(
$datebaseConnection = $this->getDatabaseConnection()
->getConnectionForTable('tx_t3omembership_domain_model_member');
$datebaseConnection->insert(
'tx_t3omembership_domain_model_member',
$memberData
);
$memberUid = $this->getDatabaseConnection()->sql_insert_id();
$memberUid = (int)$datebaseConnection->lastInsertId('tx_t3omembership_domain_model_member');
}
$this->getDatabaseConnection()->sql_free_result($resource);
return (int)$memberUid;
}
......@@ -238,10 +250,10 @@ class ImportMembersTask extends \TYPO3\CMS\Extbase\Scheduler\Task
}
/**
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
* @return \TYPO3\CMS\Core\Database\ConnectionPool
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
return GeneralUtility::makeInstance(ConnectionPool::class);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment