Commit 4d31bd14 authored by Thomas Löffler's avatar Thomas Löffler

Merge branch '10-update-for-typo3-v10' into 'master'

Resolve "Update for TYPO3 v10"

Closes #10

See merge request !6
parents 458372cc 2aef730e
......@@ -14,55 +14,75 @@ namespace T3o\Randombanners\Command;
* The TYPO3 project - inspiring people to share!
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Handle click statistics and send monthly mails
*/
class MonthlyCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
class MonthlyCommand extends \Symfony\Component\Console\Command\Command {
/**
* @var \T3o\Randombanners\Domain\Repository\BannerRepository
* @inject
* Configure the command by defining the name, options and arguments
*/
protected $bannerRepository;
protected function configure()
{
$this->setDescription('Handle click statistics and send monthly mails');
//$this->setHelp('Meaningful help text');
}
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
* Executes the command
*
* @param InputInterface $input
* @param OutputInterface $output
*/
protected $configurationManager;
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title($this->getDescription());
/**
* @return void
*/
public function MonthlyCommand() {
// No storagePid
$querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(FALSE);
$this->bannerRepository->setDefaultQuerySettings($querySettings);
// Get a query builder for a query on table "tt_content"
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_randombanners_domain_model_banner');
$rows = $queryBuilder
->select('*')
->from('tx_randombanners_domain_model_banner')
->execute()
->fetchAll();
$banners = $this->bannerRepository->findAll();
foreach($banners as $banner) {
foreach($rows as $banner) {
$this->sendReport($banner);
$this->setStatistics($banner);
}
$this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->persistAll();
return TRUE;
$io->writeln('Finished.');
}
/**
* Send monthly report to sponsor
*
* @param \T3o\Randombanners\Domain\Model\Banner $banner
* @param array $banner
* @return boolean
*/
protected function sendReport(\T3o\Randombanners\Domain\Model\Banner $banner) {
if($banner->getEmail()) {
$mailObject = $this->objectManager->get(\TYPO3\CMS\Core\Mail\MailMessage::class);
protected function sendReport($banner) {
if($banner['email']) {
$settings = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('randombanners');
/* @var \TYPO3\CMS\Core\Mail\MailMessage $mailObject */
$mailObject = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
// Get email template
$standaloneViewUtility = $this->objectManager->get(\T3o\Randombanners\Utility\StandaloneViewUtility::class);
$renderer = $standaloneViewUtility->getPlainTextView('Scheduler/Email');
/** @var StandaloneView $renderer */
$renderer = GeneralUtility::makeInstance(StandaloneView::class);
$renderer->setTemplatePathAndFilename($settings['templatePathAndFilename']);
$renderer->assign('banner', $banner);
$message = $renderer->render();
$firstLinebreak = strpos($message, PHP_EOL);
......@@ -71,13 +91,13 @@ class MonthlyCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\Command
// Generate and send mail
$mailObject->setSubject($subject);
$mailObject->addPart($message, 'text/plain');
$mailObject->setFrom(['no-reply@typo3.org' => 'typo3.org Banner']);
if(\TYPO3\CMS\Core\Utility\GeneralUtility::getApplicationContext()->isDevelopment()) {
$configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$mailObject->setTo($configuration['settings']['developmentEmail'], $banner->getName());
$mailObject->text($message);
$mailObject->setFrom([$settings['senderEmail'] => $settings['senderEmail']]);
if(Environment::getContext()->isDevelopment()) {
$mailObject->setTo($settings['developmentEmail'], $banner['name']);
} else {
$mailObject->setTo($banner->getEmail(), $banner->getName());
$mailObject->setTo($banner['email'], $banner['name']);
}
return $mailObject->send();
}
......@@ -86,12 +106,18 @@ class MonthlyCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\Command
/**
* Set monthly statistics
*
* @param \T3o\Randombanners\Domain\Model\Banner $banner
* @param array $banner
*/
protected function setStatistics(\T3o\Randombanners\Domain\Model\Banner $banner) {
$banner->setClickedLastMonth($banner->getClickedThisMonth());
$banner->setClickedThisMonth(0);
$this->bannerRepository->update($banner);
protected function setStatistics($banner) {
GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_randombanners_domain_model_banner')
->update(
'tx_randombanners_domain_model_banner',
[
'clicked_last_month' => $banner['clicked_this_month'],
'clicked_this_month' => 0
], // set
[ 'uid' => $banner['uid'] ] // where
);
}
}
\ No newline at end of file
......@@ -14,17 +14,28 @@ namespace T3o\Randombanners\Eid;
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
$banner = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('banner');
class RandombannersEidController
{
public function countClick(ServerRequestInterface $request)
{
$banner = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('banner');
/* @var \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
->getQueryBuilderForTable('tx_randombanners_domain_model_banner');
$queryBuilder
->update('tx_randombanners_domain_model_banner')
->where(
$queryBuilder->expr()->eq('uid', (int)$banner)
)
->set('clicked_this_month', 'clicked_this_month + 1', false)
->execute();
/* @var \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
->getQueryBuilderForTable('tx_randombanners_domain_model_banner');
$queryBuilder
->update('tx_randombanners_domain_model_banner')
->where(
$queryBuilder->expr()->eq('uid', (int)$banner)
)
->set('clicked_this_month', 'clicked_this_month + 1', false)
->execute();
return new Response();
}
}
\ No newline at end of file
<?php
namespace T3o\Randombanners\Utility;
/*
* 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!
*/
class StandaloneViewUtility {
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
*/
protected $configurationManager;
/**
* objectManager
*
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
* @inject
*/
protected $objectManager;
/**
* Creates a stand-alone instance of the Fluid view to render a plain text template
*
* @param string $templateName: the name of the template to use
* @return \TYPO3\CMS\Fluid\View\StandaloneView: the Fluid instance
*/
public function getPlainTextView($templateName) {
$configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$standaloneView = $this->objectManager->get(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$standaloneView->getRequest()->setControllerExtensionName($configuration['extensionName']);
$standaloneView->setLayoutRootPaths($configuration['view']['layoutRootPaths']);
$standaloneView->setPartialRootPaths($configuration['view']['partialRootPaths']);
$standaloneView->setTemplateRootPaths($configuration['view']['templateRootPaths']);
$standaloneView->setTemplate($templateName);
return $standaloneView;
}
}
\ No newline at end of file
<?php
return [
'randombanners:monthly' => [
'class' => \T3o\Randombanners\Command\MonthlyCommand::class,
'schedulable' => true,
],
];
\ No newline at end of file
<?php
defined('TYPO3_MODE') or die();
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'T3o.Randombanners',
'Randombanners',
'Pi1',
'LLL:EXT:randombanners/Resources/Private/Language/locallang_be.xlf:plugin.title'
);
\ No newline at end of file
<?php
defined('TYPO3_MODE') or die();
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_randombanners_domain_model_banner');
return [
'ctrl' => [
'title' => 'LLL:EXT:randombanners/Resources/Private/Language/locallang_db.xlf:tx_randombanners_domain_model_banner',
......
Report for your banner on typo3.org for <f:format.date date="-1 month" format="F Y" />
Your banner statistics for <f:format.date date="-1 month" format="F Y" />
Clicked: {banner.clickedThisMonth} times (last month: {banner.clickedLastMonth} times)
Clicked: {banner.clicked_this_month} times (last month: {banner.clicked_last_month} times)
Thanks for sponsoring
TYPO3 Association
\ No newline at end of file
......@@ -6,9 +6,18 @@
"license": [
"GPL-2.0+"
],
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://git-t3o.typo3.org/t3o/t3o_membership.git"
}
],
"require": {
"typo3/cms-core": ">=7.6.0,<9.9.99",
"typo3/cms-scheduler": ">=7.6.0,<9.9.99"
"typo3/cms-core": ">=10.3.0,<10.9.99",
"typo3/cms-scheduler": ">=10.3.0,<10.9.99",
"t3o/t3o_membership": "dev-38-update-for-typo3-v10"
},
"keywords": [
"TYPO3 CMS"
......@@ -18,4 +27,4 @@
"T3o\\Randombanners\\": "Classes"
}
}
}
\ No newline at end of file
}
# cat=Report Command; type=string; label=Email Template
templatePathAndFilename = EXT:randombanners/Resources/Private/Templates/Scheduler/Email.html
# cat=Report Command; type=string; label=Sender Email: Use this email in monthly report as sender email
senderEmail = no-reply@typo3.org
# cat=Report Command; type=string; label=Sender Email Name: Use this name in monthly report as sender email name
senderEmailName = typo3.org Banner
# cat=Report Command; type=string; label=Development Email: Use this email in monthly report instead of banner email
developmentEmail = dev@typo3.org.ddev.site
......@@ -2,14 +2,15 @@
/************************************************************************
* Extension Manager/Repository config file for ext "randombanners".
************************************************************************/
$EM_CONF[$_EXTKEY] = array(
$EM_CONF['randombanners'] = array(
'title' => 'Random banners',
'description' => 'Random banner with click statistics and monthly report',
'category' => 'extension',
'constraints' => array(
'depends' => array(
'typo3' => '7.6.0-9.99.99',
'scheduler' => '7.6.0-9.99.99'
'typo3' => '10.3.0-10.99.99',
'scheduler' => '10.3.0-10.99.99',
't3o_membership' => '3.0.0-3.9.99'
),
'conflicts' => array(
),
......@@ -26,5 +27,5 @@ $EM_CONF[$_EXTKEY] = array(
'author' => 'Thomas Loeffler',
'author_email' => 'loeffler@spooner-web.de',
'author_company' => 'TYPO3',
'version' => '1.0.4',
'version' => '2.0.0',
);
......@@ -2,18 +2,15 @@
defined('TYPO3_MODE') or die();
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'T3o.' . $_EXTKEY,
'Randombanners',
'Pi1',
[
'Banner' => 'index',
\T3o\Randombanners\Controller\BannerController::class => 'index',
],
// non-cacheable actions
[
]
);
// Register scheduler job
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'T3o\\Randombanners\\Command\\MonthlyCommandController';
// AJAX
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['randombanners'] = 'EXT:' . $_EXTKEY . '/Classes/Eid/Count.php';
\ No newline at end of file
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['randombanners'] = \T3o\Randombanners\Eid\RandombannersEidController::class . '::countClick';
\ No newline at end of file
<?php
defined('TYPO3_MODE') || die();
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_randombanners_domain_model_banner');
......@@ -10,7 +10,4 @@ module.tx_randombanners {
10 = EXT:randombanners/Resources/Private/Layouts/
}
}
settings {
developmentEmail = sventb@gmail.com
}
}
\ No newline at end of file
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