Skip to content

Commit

Permalink
Merge pull request mautic#7028 from mautic/release-2.15.0
Browse files Browse the repository at this point in the history
Release 2.15.0
  • Loading branch information
Woeler committed Dec 19, 2018
2 parents 816990f + 1abdfbd commit 6d201ac
Show file tree
Hide file tree
Showing 389 changed files with 13,104 additions and 3,367 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
2.

#### Steps to test this PR:
1.
1. Load up [this PR](https://mautibox.com)
2.

#### List deprecations along with the new alternative:
Expand All @@ -33,4 +33,4 @@

#### List backwards compatibility breaks:
1.
2.
2.
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
dist: precise

language: php

services:
- mysql

php:
- 5.6.19
- 5.6
- 7.0
- 7.1
- 7.2

cache:
directories:
- $HOME/.composer/cache

before_install:
# Create mautictest database
- mysql -e 'CREATE DATABASE mautictest;'

# increase memory limit for all PHP processes
- echo "memory_limit=4G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

# turn off XDebug
- phpenv config-rm xdebug.ini || return

Expand All @@ -32,11 +38,11 @@ install:
script:

# Run PHPUnit
- bin/phpunit -d memory_limit=2048M --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --fail-on-warning
- bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --fail-on-warning

# Run PHPSTAN analysis for PHP 7+
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then ~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse app/bundles/DashboardBundle app/bundles/ConfigBundle app/bundles/CampaignBundle app/bundles/WebhookBundle app/bundles/LeadBundle app/bundles/FormBundle; fi

# Check if the code standards weren't broken.
# Run it only on PHP 7.1 which should be the fastest. No need to run it for all PHP versions
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then bin/php-cs-fixer fix -v --dry-run --diff; fi
# Run it only on PHP 7.2 which should be the fastest. No need to run it for all PHP versions
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then bin/php-cs-fixer fix -v --dry-run --diff; fi
19 changes: 14 additions & 5 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ class AppKernel extends Kernel
*
* @const integer
*/
const MINOR_VERSION = 14;
const MINOR_VERSION = 15;

/**
* Patch version number.
*
* @const integer
*/
const PATCH_VERSION = 2;
const PATCH_VERSION = 0;

/**
* Extra version identifier.
Expand Down Expand Up @@ -92,12 +92,12 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
$base = $request->getBaseUrl();
$prefix = '';
//check to see if the .htaccess file exists or if not running under apache
if ((strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') === false
if (stripos($request->server->get('SERVER_SOFTWARE', ''), 'apache') === false
|| !file_exists(__DIR__.'../.htaccess')
&& strpos(
$base,
'index'
) === false)
) === false
) {
$prefix .= '/index.php';
}
Expand All @@ -110,6 +110,14 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
$this->boot();
}

/*
* If we've already sent the response headers, and we have a session
* set in the request, set that as the session in the container.
*/
if (headers_sent() && $request->getSession()) {
$this->getContainer()->set('session', $request->getSession());
}

// Check for an an active db connection and die with error if unable to connect
if (!defined('MAUTIC_INSTALLER')) {
$db = $this->getContainer()->get('database_connection');
Expand Down Expand Up @@ -184,6 +192,7 @@ public function registerBundles()
new LightSaml\SymfonyBridgeBundle\LightSamlSymfonyBridgeBundle(),
new LightSaml\SpBundle\LightSamlSpBundle(),
new Ivory\OrderedFormBundle\IvoryOrderedFormBundle(),
new Noxlogic\RateLimitBundle\NoxlogicRateLimitBundle(),
// These two bundles do DI based on config, so they need to be loaded after config is declared in MauticQueueBundle
new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
new Leezy\PheanstalkBundle\LeezyPheanstalkBundle(),
Expand Down Expand Up @@ -374,7 +383,7 @@ public function getCacheDir()
{
$parameters = $this->getLocalParams();
if (isset($parameters['cache_path'])) {
$envFolder = (strpos($parameters['cache_path'], -1) != '/') ? '/'.$this->environment : $this->environment;
$envFolder = (substr($parameters['cache_path'], -1) != '/') ? '/'.$this->environment : $this->environment;

return str_replace('%kernel.root_dir%', $this->getRootDir(), $parameters['cache_path'].$envFolder);
} else {
Expand Down
9 changes: 9 additions & 0 deletions app/AppTestKernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* @copyright 2017 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

class AppTestKernel extends AppKernel
{
/**
Expand Down
10 changes: 10 additions & 0 deletions app/bundles/ApiBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
'mautic.api.model.client',
],
],
'mautic.api.rate_limit_generate_key.subscriber' => [
'class' => 'Mautic\ApiBundle\EventListener\RateLimitGenerateKeySubscriber',
'arguments' => [
'mautic.helper.core_parameters',
],
],
],
'forms' => [
'mautic.form.type.apiclients' => [
Expand Down Expand Up @@ -183,5 +189,9 @@
'api_oauth2_access_token_lifetime' => 60,
'api_oauth2_refresh_token_lifetime' => 14,
'api_batch_max_limit' => 200,
'api_rate_limiter_limit' => 0,
'api_rate_limiter_cache' => [
'type' => 'file_system',
],
],
];
2 changes: 1 addition & 1 deletion app/bundles/ApiBundle/Controller/CommonApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ protected function processForm($entity, $parameters = null, $method = 'PUT')
*
* @return Response|array
*/
protected function returnError($msg, $code = Codes::HTTP_OK, $details = [])
protected function returnError($msg, $code = Codes::HTTP_INTERNAL_SERVER_ERROR, $details = [])
{
if ($this->get('translator')->hasId($msg, 'flashes')) {
$msg = $this->get('translator')->trans($msg, [], 'flashes');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* @copyright 2014 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

namespace Mautic\ApiBundle\EventListener;

use Mautic\CoreBundle\EventListener\CommonSubscriber;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Noxlogic\RateLimitBundle\Events\GenerateKeyEvent;
use Noxlogic\RateLimitBundle\Events\RateLimitEvents;

/**
* Class RateLimitGenerateKeySubscriber.
*/
class RateLimitGenerateKeySubscriber extends CommonSubscriber
{
/**
* @var CoreParametersHelper
*/
protected $coreParametersHelper;

/**
* RateLimitGenerateKeySubscriber constructor.
*
* @param \Mautic\CoreBundle\Helper\CoreParametersHelper $coreParametersHelper
*/
public function __construct(CoreParametersHelper $coreParametersHelper)
{
$this->coreParametersHelper = $coreParametersHelper;
}

/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
RateLimitEvents::GENERATE_KEY => ['onGenerateKey', 0],
];
}

/**
* @param \Noxlogic\RateLimitBundle\Events\GenerateKeyEvent $event
*/
public function onGenerateKey(GenerateKeyEvent $event)
{
$suffix = $this->coreParametersHelper->getParameter('site_url');
$event->addToKey($suffix);
}
}
20 changes: 20 additions & 0 deletions app/bundles/ApiBundle/Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ public function buildForm(FormBuilderInterface $builder, array $options)
],
]
);

$builder->add(
'api_rate_limiter_limit',
'number',
[
'label' => 'mautic.api.config.form.api.rate_limiter_limit',
'attr' => [
'tooltip' => 'mautic.api.config.form.api.rate_limiter_limit.tooltip',
'class' => 'form-control',
'data-show-on' => '{"config_apiconfig_api_enabled_1":"checked"}',
],
'constraints' => [
new NotBlank(
[
'message' => 'mautic.core.value.required',
]
),
],
]
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/ApiBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ mautic.core.error.badrequest="Bad request."
mautic.api.error.api.disabled="API disabled. You need to enable the API in the API settings page of your Mautic account."
mautic.api.error.basic.auth.disabled="Basic Auth disabled. You need to enable HTTP basic auth in the API settings page of your Mautic account."
mautic.api.error.basic.auth.invalid.credentials="Authorization denied, invalid credentials."
mautic.api.config.form.api.rate_limiter_limit="API request limit (requests per hours)"
mautic.api.config.form.api.rate_limiter_limit.tooltip="The number of allowed API calls per hour for the whole instance (sum of all API keys). Set it to 0 to remove the limit."
2 changes: 1 addition & 1 deletion app/bundles/AssetBundle/Assets/js/asset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//AssetBundle
Mautic.assetOnLoad = function (container) {
if (typeof mauticAssetUploadEndpoint !== 'undefined' && mQuery('div#dropzone').length) {
if (typeof mauticAssetUploadEndpoint !== 'undefined' && typeof Mautic.assetDropzone == 'undefined' && mQuery('div#dropzone').length) {
Mautic.initializeDropzone();
}
};
Expand Down
20 changes: 20 additions & 0 deletions app/bundles/AssetBundle/Entity/AssetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Mautic\AssetBundle\Entity;

use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Mautic\CoreBundle\Entity\CommonRepository;

Expand Down Expand Up @@ -211,4 +212,23 @@ public function upDownloadCount($id, $increaseBy = 1, $unique = false)

$q->execute();
}

/**
* @param int $categoryId
*
* @return Asset
*
* @throws NoResultException
*/
public function getLatestAssetForCategory($categoryId)
{
$q = $this->createQueryBuilder($this->getTableAlias());
$q->where($this->getTableAlias().'.category = :categoryId');
$q->andWhere($this->getTableAlias().'.isPublished = TRUE');
$q->setParameter('categoryId', $categoryId);
$q->orderBy($this->getTableAlias().'.dateAdded', 'DESC');
$q->setMaxResults(1);

return $q->getQuery()->getSingleResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Mautic\AssetBundle\Form\Type;

use Mautic\CategoryBundle\Form\Type\CategoryListType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

Expand All @@ -25,18 +26,31 @@ class FormSubmitActionDownloadFileType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('asset', 'asset_list', [
$builder->add('asset', AssetListType::class, [
'expanded' => false,
'multiple' => false,
'label' => 'mautic.asset.form.submit.assets',
'label_attr' => ['class' => 'control-label'],
'empty_value' => false,
'empty_value' => 'mautic.asset.form.submit.latest.category',
'required' => false,
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.asset.form.submit.assets_descr',
],
]);

$builder->add('category', CategoryListType::class, [
'label' => 'mautic.asset.form.submit.latest.category',
'label_attr' => ['class' => 'control-label'],
'empty_value' => false,
'required' => false,
'bundle' => 'asset',
'return_entity' => false,
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.asset.form.submit.latest.category_descr',
],
]);
}

/**
Expand Down
24 changes: 16 additions & 8 deletions app/bundles/AssetBundle/Helper/FormSubmitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Mautic\AssetBundle\Helper;

use Doctrine\ORM\NoResultException;
use Mautic\AssetBundle\Entity\Asset;
use Mautic\CoreBundle\Factory\MauticFactory;
use Mautic\FormBundle\Entity\Action;
Expand All @@ -32,20 +33,27 @@ class FormSubmitHelper
public static function onFormSubmit(Action $action, MauticFactory $factory)
{
$properties = $action->getProperties();
$assetId = $properties['asset'];
$categoryId = isset($properties['category']) ? $properties['category'] : null;
$model = $factory->getModel('asset');
$asset = null;

$assetId = $properties['asset'];

/** @var \Mautic\AssetBundle\Model\AssetModel $model */
$model = $factory->getModel('asset');
$asset = $model->getEntity($assetId);
$form = $action->getForm();
if (null !== $assetId) {
$asset = $model->getEntity($assetId);
} elseif (null !== $categoryId) {
try {
$asset = $model->getRepository()->getLatestAssetForCategory($categoryId);
} catch (NoResultException $e) {
$asset = null;
}
}

//make sure the asset still exists and is published
if ($asset != null && $asset->isPublished()) {
if ($asset !== null && $asset->isPublished()) {
//register a callback after the other actions have been fired
return [
'callback' => '\Mautic\AssetBundle\Helper\FormSubmitHelper::downloadFile',
'form' => $form,
'form' => $action->getForm(),
'asset' => $asset,
'message' => (isset($properties['message'])) ? $properties['message'] : '',
];
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/AssetBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ mautic.asset.filename.original="Original filename"
mautic.asset.filename.remote="Remote filename"
mautic.asset.form.submit.assets="Asset"
mautic.asset.form.submit.assets_descr="Choose the asset to be downloaded."
mautic.asset.form.submit.latest.category="Use the latest asset from the category"
mautic.asset.form.submit.latest.category_descr="If 'Use latest file from the category' Asset option is selected then the action will download the latest asset from the selected category."
mautic.asset.graph.line.downloads="Downloads"
mautic.asset.graph.pie.statuses="Download HTTP statuses"
mautic.asset.no_audio_support="Your browser does not support audio."
Expand Down
Loading

0 comments on commit 6d201ac

Please sign in to comment.