diff --git a/app/AppCache.php b/app/AppCache.php index bf8246246c8..ddb51db0583 100644 --- a/app/AppCache.php +++ b/app/AppCache.php @@ -1,6 +1,6 @@ getRequestUri(), 'installer') !== false || !$this->isInstalled()) { define('MAUTIC_INSTALLER', 1); } @@ -91,7 +89,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ if (strpos($uri, 'installer') === false) { $base = $request->getBaseUrl(); //check to see if the .htaccess file exists or if not running under apache - if ((strpos(strtolower($_SERVER["SERVER_SOFTWARE"]), 'apache') === false + if ((strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') === false || !file_exists(__DIR__.'../.htaccess') && strpos( $base, @@ -106,7 +104,6 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ } if (false === $this->booted) { - $this->boot(); } @@ -121,7 +118,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ $this->getContainer()->get('translator')->trans( 'mautic.core.db.connection.error', [ - '%code%' => $e->getCode() + '%code%' => $e->getCode(), ] ) ); @@ -176,7 +173,7 @@ public function registerBundles() new Mautic\SmsBundle\MauticSmsBundle(), new Mautic\StageBundle\MauticStageBundle(), new Mautic\UserBundle\MauticUserBundle(), - new Mautic\WebhookBundle\MauticWebhookBundle() + new Mautic\WebhookBundle\MauticWebhookBundle(), ]; //dynamically register Mautic Plugin Bundles @@ -229,14 +226,13 @@ public function registerBundles() public function boot() { if (true === $this->booted) { - return; } if (!defined('MAUTIC_TABLE_PREFIX')) { //set the table prefix before boot $localParams = $this->getLocalParams(); - $prefix = isset($localParams['db_table_prefix']) ? $localParams['db_table_prefix'] : ''; + $prefix = isset($localParams['db_table_prefix']) ? $localParams['db_table_prefix'] : ''; define('MAUTIC_TABLE_PREFIX', $prefix); } @@ -270,7 +266,7 @@ public function boot() } /** - * Returns a list of addon bundles that are enabled + * Returns a list of addon bundles that are enabled. * * @return array */ @@ -288,7 +284,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) } /** - * Retrieves the application's version number + * Retrieves the application's version number. * * @return string */ @@ -298,7 +294,7 @@ public function getVersion() } /** - * Checks if the application has been installed + * Checks if the application has been installed. * * @return bool */ @@ -318,6 +314,7 @@ private function isInstalled() * @param array $params * * @return \Doctrine\DBAL\Connection + * * @throws Exception * @throws \Doctrine\DBAL\DBALException */ @@ -382,7 +379,7 @@ public function getLogDir() } /** - * Get Mautic's local configuration file + * Get Mautic's local configuration file. * * @return array */ @@ -421,7 +418,7 @@ public function getLocalParams() } /** - * Get local config file + * Get local config file. * * @param bool $checkExists If true, then return false if the file doesn't exist * @@ -444,7 +441,7 @@ public function getLocalConfigFile($checkExists = true) } /** - * Get the container file name or path + * Get the container file name or path. * * @param bool|true $fullPath * diff --git a/app/autoload.php b/app/autoload.php index 3f0e4810e2e..db8e161ea18 100644 --- a/app/autoload.php +++ b/app/autoload.php @@ -6,14 +6,14 @@ require_once __DIR__.'/bootstrap.php.cache'; } -use Doctrine\Common\Annotations\AnnotationRegistry; use Composer\Autoload\ClassLoader; +use Doctrine\Common\Annotations\AnnotationRegistry; /** - * @var ClassLoader $loader + * @var ClassLoader */ $loader = require __DIR__.'/../vendor/autoload.php'; -AnnotationRegistry::registerLoader(array($loader, 'loadClass')); +AnnotationRegistry::registerLoader([$loader, 'loadClass']); return $loader; diff --git a/app/bundles/ApiBundle/ApiEvents.php b/app/bundles/ApiBundle/ApiEvents.php index 0eb40ff276f..756a595fef7 100644 --- a/app/bundles/ApiBundle/ApiEvents.php +++ b/app/bundles/ApiBundle/ApiEvents.php @@ -1,16 +1,17 @@ array( - 'public' => array( +return [ + 'routes' => [ + 'public' => [ // OAuth1.0a - 'bazinga_oauth_server_requesttoken' => array( + 'bazinga_oauth_server_requesttoken' => [ 'path' => '/oauth/v1/request_token', 'controller' => 'bazinga.oauth.controller.server:requestTokenAction', - 'method' => 'GET|POST' - ), - 'bazinga_oauth_login_allow' => array( + 'method' => 'GET|POST', + ], + 'bazinga_oauth_login_allow' => [ 'path' => '/oauth/v1/authorize', 'controller' => 'MauticApiBundle:oAuth1/Authorize:allow', - 'method' => 'GET' - ), - 'bazinga_oauth_server_authorize' => array( + 'method' => 'GET', + ], + 'bazinga_oauth_server_authorize' => [ 'path' => '/oauth/v1/authorize', 'controller' => 'bazinga.oauth.controller.server:authorizeAction', - 'method' => 'POST' - ), - 'mautic_oauth1_server_auth_login' => array( + 'method' => 'POST', + ], + 'mautic_oauth1_server_auth_login' => [ 'path' => '/oauth/v1/authorize_login', 'controller' => 'MauticApiBundle:oAuth1/Security:login', - 'method' => 'GET|POST' - ), - 'mautic_oauth1_server_auth_login_check' => array( + 'method' => 'GET|POST', + ], + 'mautic_oauth1_server_auth_login_check' => [ 'path' => '/oauth/v1/authorize_login_check', 'controller' => 'MauticApiBundle:oAuth1/Security:loginCheck', - 'method' => 'GET|POST' - ), - 'bazinga_oauth_server_accesstoken' => array( + 'method' => 'GET|POST', + ], + 'bazinga_oauth_server_accesstoken' => [ 'path' => '/oauth/v1/access_token', 'controller' => 'bazinga.oauth.controller.server:accessTokenAction', - 'method' => 'GET|POST' - ), + 'method' => 'GET|POST', + ], // OAuth2 - 'fos_oauth_server_token' => array( + 'fos_oauth_server_token' => [ 'path' => '/oauth/v2/token', 'controller' => 'fos_oauth_server.controller.token:tokenAction', - 'method' => 'GET|POST' - ), - 'fos_oauth_server_authorize' => array( + 'method' => 'GET|POST', + ], + 'fos_oauth_server_authorize' => [ 'path' => '/oauth/v2/authorize', 'controller' => 'MauticApiBundle:oAuth2/Authorize:authorize', - 'method' => 'GET|POST' - ), - 'mautic_oauth2_server_auth_login' => array( + 'method' => 'GET|POST', + ], + 'mautic_oauth2_server_auth_login' => [ 'path' => '/oauth/v2/authorize_login', 'controller' => 'MauticApiBundle:oAuth2/Security:login', - 'method' => 'GET|POST' - ), - 'mautic_oauth2_server_auth_login_check' => array( + 'method' => 'GET|POST', + ], + 'mautic_oauth2_server_auth_login_check' => [ 'path' => '/oauth/v2/authorize_login_check', 'controller' => 'MauticApiBundle:oAuth2/Security:loginCheck', - 'method' => 'GET|POST' - ), - ), - 'main' => array( + 'method' => 'GET|POST', + ], + ], + 'main' => [ // Clients - 'mautic_client_index' => array( + 'mautic_client_index' => [ 'path' => '/credentials/{page}', - 'controller' => 'MauticApiBundle:Client:index' - ), - 'mautic_client_action' => array( + 'controller' => 'MauticApiBundle:Client:index', + ], + 'mautic_client_action' => [ 'path' => '/credentials/{objectAction}/{objectId}', - 'controller' => 'MauticApiBundle:Client:execute' - ) - ) - ), + 'controller' => 'MauticApiBundle:Client:execute', + ], + ], + ], - 'menu' => array( - 'admin' => array( - 'items' => array( - 'mautic.api.client.menu.index' => array( + 'menu' => [ + 'admin' => [ + 'items' => [ + 'mautic.api.client.menu.index' => [ 'route' => 'mautic_client_index', 'iconClass' => 'fa-puzzle-piece', 'access' => 'api:clients:view', - 'checks' => array( - 'parameters' => array( - 'api_enabled' => true - ) - ) - ) - ) - ) - ), + 'checks' => [ + 'parameters' => [ + 'api_enabled' => true, + ], + ], + ], + ], + ], + ], - 'services' => array( - 'events' => array( - 'mautic.api.subscriber' => array( - 'class' => 'Mautic\ApiBundle\EventListener\ApiSubscriber', + 'services' => [ + 'events' => [ + 'mautic.api.subscriber' => [ + 'class' => 'Mautic\ApiBundle\EventListener\ApiSubscriber', 'arguments' => [ 'mautic.helper.ip_lookup', 'mautic.helper.core_parameters', - 'mautic.core.model.auditlog' - ] - ), - 'mautic.api.configbundle.subscriber' => array( - 'class' => 'Mautic\ApiBundle\EventListener\ConfigSubscriber' - ), - 'mautic.api.search.subscriber' => array( - 'class' => 'Mautic\ApiBundle\EventListener\SearchSubscriber', + 'mautic.core.model.auditlog', + ], + ], + 'mautic.api.configbundle.subscriber' => [ + 'class' => 'Mautic\ApiBundle\EventListener\ConfigSubscriber', + ], + 'mautic.api.search.subscriber' => [ + 'class' => 'Mautic\ApiBundle\EventListener\SearchSubscriber', 'arguments' => [ - 'mautic.api.model.client' - ] - ) - ), - 'forms' => array( - 'mautic.form.type.apiclients' => array( + 'mautic.api.model.client', + ], + ], + ], + 'forms' => [ + 'mautic.form.type.apiclients' => [ 'class' => 'Mautic\ApiBundle\Form\Type\ClientType', 'arguments' => 'mautic.factory', - 'alias' => 'client' - ), - 'mautic.form.type.apiconfig' => array( + 'alias' => 'client', + ], + 'mautic.form.type.apiconfig' => [ 'class' => 'Mautic\ApiBundle\Form\Type\ConfigType', - 'alias' => 'apiconfig' - ) - ), - 'other' => array( - 'mautic.api.oauth.event_listener' => array( - 'class' => 'Mautic\ApiBundle\EventListener\OAuthEventListener', - 'arguments' => [ + 'alias' => 'apiconfig', + ], + ], + 'other' => [ + 'mautic.api.oauth.event_listener' => [ + 'class' => 'Mautic\ApiBundle\EventListener\OAuthEventListener', + 'arguments' => [ 'doctrine.orm.entity_manager', 'mautic.security', - 'translator' + 'translator', ], - 'tags' => array( + 'tags' => [ + 'kernel.event_listener', 'kernel.event_listener', - 'kernel.event_listener' - ), - 'tagArguments' => array( - array( + ], + 'tagArguments' => [ + [ 'event' => 'fos_oauth_server.pre_authorization_process', - 'method' => 'onPreAuthorizationProcess' - ), - array( + 'method' => 'onPreAuthorizationProcess', + ], + [ 'event' => 'fos_oauth_server.post_authorization_process', - 'method' => 'onPostAuthorizationProcess' - ) - ) - ), - 'mautic.api.oauth1.nonce_provider' => array( + 'method' => 'onPostAuthorizationProcess', + ], + ], + ], + 'mautic.api.oauth1.nonce_provider' => [ 'class' => 'Mautic\ApiBundle\Provider\NonceProvider', - 'arguments' => 'doctrine.orm.entity_manager' - ), + 'arguments' => 'doctrine.orm.entity_manager', + ], 'bazinga.oauth.security.authentication.provider.class' => 'Mautic\ApiBundle\Security\OAuth1\Authentication\Provider\OAuthProvider', 'bazinga.oauth.security.authentication.listener.class' => 'Mautic\ApiBundle\Security\OAuth1\Firewall\OAuthListener', 'bazinga.oauth.event_listener.request.class' => 'Mautic\ApiBundle\EventListener\OAuth1\OAuthRequestListener', @@ -159,25 +160,25 @@ 'jms_serializer.metadata.annotation_driver.class' => 'Mautic\ApiBundle\Serializer\Driver\AnnotationDriver', 'jms_serializer.metadata.php_driver.class' => 'Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver', - 'mautic.validator.oauthcallback' => array( - 'class' => 'Mautic\ApiBundle\Form\Validator\Constraints\OAuthCallbackValidator', - 'tag' => 'validator.constraint_validator', - 'alias' => 'oauth_callback' - ) - ), - 'models' => array( - 'mautic.api.model.client' => array( - 'class' => 'Mautic\ApiBundle\Model\ClientModel', - 'arguments' => array( - 'request_stack' - ) - ) - ) - ), + 'mautic.validator.oauthcallback' => [ + 'class' => 'Mautic\ApiBundle\Form\Validator\Constraints\OAuthCallbackValidator', + 'tag' => 'validator.constraint_validator', + 'alias' => 'oauth_callback', + ], + ], + 'models' => [ + 'mautic.api.model.client' => [ + 'class' => 'Mautic\ApiBundle\Model\ClientModel', + 'arguments' => [ + 'request_stack', + ], + ], + ], + ], - 'parameters' => array( - "api_enabled" => false, - "api_oauth2_access_token_lifetime" => 60, - "api_oauth2_refresh_token_lifetime" => 14 - ) -); \ No newline at end of file + 'parameters' => [ + 'api_enabled' => false, + 'api_oauth2_access_token_lifetime' => 60, + 'api_oauth2_refresh_token_lifetime' => 14, + ], +]; diff --git a/app/bundles/ApiBundle/Controller/ClientController.php b/app/bundles/ApiBundle/Controller/ClientController.php index b726c983d92..e3a7aadec05 100644 --- a/app/bundles/ApiBundle/Controller/ClientController.php +++ b/app/bundles/ApiBundle/Controller/ClientController.php @@ -1,9 +1,10 @@ $limit, 'filter' => $filter, 'orderBy' => $orderBy, - 'orderByDir' => $orderByDir + 'orderByDir' => $orderByDir, ] ); @@ -69,8 +69,8 @@ public function indexAction($page = 1) 'contentTemplate' => 'MauticApiBundle:Client:index', 'passthroughVars' => [ 'activeLink' => 'mautic_client_index', - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ] ); } @@ -94,7 +94,7 @@ public function indexAction($page = 1) $apiOptions['oauth2'] = 'OAuth 2'; $filters['api_mode'] = [ 'values' => [$apiMode], - 'options' => $apiOptions + 'options' => $apiOptions, ]; $parameters = [ @@ -104,7 +104,7 @@ public function indexAction($page = 1) 'permissions' => $permissions, 'tmpl' => $tmpl, 'searchValue' => $filter, - 'filters' => $filters + 'filters' => $filters, ]; return $this->delegateView( @@ -113,8 +113,8 @@ public function indexAction($page = 1) 'contentTemplate' => 'MauticApiBundle:Client:list.html.php', 'passthroughVars' => [ 'route' => $this->generateUrl('mautic_client_index', ['page' => $page]), - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ] ); } @@ -150,7 +150,7 @@ public function revokeAction($clientId) $flashes[] = [ 'type' => 'error', 'msg' => 'mautic.api.client.error.notfound', - 'msgVars' => ['%id%' => $clientId] + 'msgVars' => ['%id%' => $clientId], ]; } else { $name = $client->getName(); @@ -161,8 +161,8 @@ public function revokeAction($clientId) 'type' => 'notice', 'msg' => 'mautic.api.client.notice.revoked', 'msgVars' => [ - '%name%' => $name - ] + '%name%' => $name, + ], ]; } } @@ -172,9 +172,9 @@ public function revokeAction($clientId) 'returnUrl' => $this->generateUrl('mautic_user_account'), 'contentTemplate' => 'MauticUserBundle:Profile:index', 'passthroughVars' => [ - 'success' => $success + 'success' => $success, ], - 'flashes' => $flashes + 'flashes' => $flashes, ] ); } @@ -231,9 +231,9 @@ public function newAction($objectId = 0) 'mautic_client_action', [ 'objectAction' => 'edit', - 'objectId' => $client->getId() + 'objectId' => $client->getId(), ] - ) + ), ] ); } @@ -246,8 +246,8 @@ public function newAction($objectId = 0) 'contentTemplate' => 'MauticApiBundle:Client:index', 'passthroughVars' => [ 'activeLink' => '#mautic_client_index', - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ] ); } elseif ($valid && !$cancelled) { @@ -257,22 +257,22 @@ public function newAction($objectId = 0) return $this->delegateView( [ - 'viewParameters' => [ + 'viewParameters' => [ 'form' => $form->createView(), - 'tmpl' => $this->request->get('tmpl', 'form') + 'tmpl' => $this->request->get('tmpl', 'form'), ], 'contentTemplate' => 'MauticApiBundle:Client:form.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_client_new', 'route' => $action, - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ] ); } /** - * Generates edit form and processes post data + * Generates edit form and processes post data. * * @param int $objectId * @param bool $ignorePost @@ -282,7 +282,6 @@ public function newAction($objectId = 0) public function editAction($objectId, $ignorePost = false) { if (!$this->get('mautic.security')->isGranted('api:clients:editother')) { - return $this->accessDenied(); } @@ -296,8 +295,8 @@ public function editAction($objectId, $ignorePost = false) 'contentTemplate' => 'MauticApiBundle:Client:index', 'passthroughVars' => [ 'activeLink' => '#mautic_client_index', - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ]; //client not found @@ -310,9 +309,9 @@ public function editAction($objectId, $ignorePost = false) [ 'type' => 'error', 'msg' => 'mautic.api.client.error.notfound', - 'msgVars' => ['%id%' => $objectId] - ] - ] + 'msgVars' => ['%id%' => $objectId], + ], + ], ] ) ); @@ -342,9 +341,9 @@ public function editAction($objectId, $ignorePost = false) 'mautic_client_action', [ 'objectAction' => 'edit', - 'objectId' => $client->getId() + 'objectId' => $client->getId(), ] - ) + ), ] ); @@ -365,22 +364,22 @@ public function editAction($objectId, $ignorePost = false) return $this->delegateView( [ - 'viewParameters' => [ + 'viewParameters' => [ 'form' => $form->createView(), - 'tmpl' => $this->request->get('tmpl', 'form') + 'tmpl' => $this->request->get('tmpl', 'form'), ], 'contentTemplate' => 'MauticApiBundle:Client:form.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_client_index', 'route' => $action, - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ] ); } /** - * Deletes the entity + * Deletes the entity. * * @param int $objectId * @@ -402,8 +401,8 @@ public function deleteAction($objectId) 'passthroughVars' => [ 'activeLink' => '#mautic_client_index', 'success' => $success, - 'mauticContent' => 'client' - ] + 'mauticContent' => 'client', + ], ]; if ($this->request->getMethod() == 'POST') { @@ -414,7 +413,7 @@ public function deleteAction($objectId) $flashes[] = [ 'type' => 'error', 'msg' => 'mautic.api.client.error.notfound', - 'msgVars' => ['%id%' => $objectId] + 'msgVars' => ['%id%' => $objectId], ]; } elseif ($model->isLocked($entity)) { //deny access if the entity is locked @@ -427,8 +426,8 @@ public function deleteAction($objectId) 'msg' => 'mautic.core.notice.deleted', 'msgVars' => [ '%name%' => $name, - '%id%' => $objectId - ] + '%id%' => $objectId, + ], ]; } } @@ -437,7 +436,7 @@ public function deleteAction($objectId) array_merge( $postActionVars, [ - 'flashes' => $flashes + 'flashes' => $flashes, ] ) ); diff --git a/app/bundles/ApiBundle/Controller/CommonApiController.php b/app/bundles/ApiBundle/Controller/CommonApiController.php index cf91d3f0221..bb830907303 100644 --- a/app/bundles/ApiBundle/Controller/CommonApiController.php +++ b/app/bundles/ApiBundle/Controller/CommonApiController.php @@ -1,11 +1,11 @@ request->get('published', 0); if ($publishedOnly) { - $this->listFilters[] = array( + $this->listFilters[] = [ 'column' => $tableAlias.'.isPublished', 'expr' => 'eq', - 'value' => true - ); + 'value' => true, + ]; } - $args = array( - 'start' => $this->request->query->get('start', 0), - 'limit' => $this->request->query->get('limit', $this->coreParametersHelper->getParameter('default_pagelimit')), - 'filter' => array( + $args = [ + 'start' => $this->request->query->get('start', 0), + 'limit' => $this->request->query->get('limit', $this->coreParametersHelper->getParameter('default_pagelimit')), + 'filter' => [ 'string' => $this->request->query->get('search', ''), - 'force' => $this->listFilters - ), + 'force' => $this->listFilters, + ], 'orderBy' => $this->request->query->get('orderBy', ''), 'orderByDir' => $this->request->query->get('orderByDir', 'ASC'), - 'withTotalCount' => true //for repositories that break free of Paginator - ); + 'withTotalCount' => true, //for repositories that break free of Paginator + ]; $results = $this->model->getEntities($args); list($entities, $totalCount) = $this->prepareEntitiesForView($results); $view = $this->view( - array( + [ 'total' => $totalCount, - $this->entityNameMulti => $entities - ), + $this->entityNameMulti => $entities, + ], Codes::HTTP_OK ); $this->setSerializationContext($view); @@ -220,7 +217,7 @@ public function getEntitiesAction() } /** - * Obtains a specific entity as defined by the API URL + * Obtains a specific entity as defined by the API URL. * * @param int $id Entity ID * @@ -238,14 +235,14 @@ public function getEntityAction($id) } $this->preSerializeEntity($entity); - $view = $this->view(array($this->entityNameOne => $entity), Codes::HTTP_OK); + $view = $this->view([$this->entityNameOne => $entity], Codes::HTTP_OK); $this->setSerializationContext($view); return $this->handleView($view); } /** - * Creates a new entity + * Creates a new entity. * * @return Response */ @@ -262,9 +259,8 @@ public function newEntityAction() return $this->processForm($entity, $parameters, 'POST'); } - /** - * Edits an existing entity or creates one on PUT if it doesn't exist + * Edits an existing entity or creates one on PUT if it doesn't exist. * * @param int $id Entity ID * @@ -297,7 +293,7 @@ public function editEntityAction($id) } /** - * Deletes an entity + * Deletes an entity. * * @param int $id Entity ID * @@ -314,7 +310,7 @@ public function deleteEntityAction($id) $this->model->deleteEntity($entity); $this->preSerializeEntity($entity); - $view = $this->view(array($this->entityNameOne => $entity), Codes::HTTP_OK); + $view = $this->view([$this->entityNameOne => $entity], Codes::HTTP_OK); $this->setSerializationContext($view); return $this->handleView($view); @@ -324,7 +320,7 @@ public function deleteEntityAction($id) } /** - * Processes API Form + * Processes API Form. * * @param $entity * @param null $parameters @@ -359,22 +355,23 @@ protected function processForm($entity, $parameters = null, $method = 'PUT') if ($form->isValid()) { $this->preSaveEntity($entity, $form, $parameters, $action); $this->model->saveEntity($entity); - $headers = array(); + $headers = []; //return the newly created entities location if applicable if (Codes::HTTP_CREATED === $statusCode) { $headers['Location'] = $this->generateUrl( 'mautic_api_get'.$this->entityNameOne, - array('id' => $entity->getId()), + ['id' => $entity->getId()], true ); } $this->preSerializeEntity($entity, $action); - $view = $this->view(array($this->entityNameOne => $entity), $statusCode, $headers); + $view = $this->view([$this->entityNameOne => $entity], $statusCode, $headers); $this->setSerializationContext($view); } else { $formErrors = $this->getFormErrorMessages($form); - $msg = $this->getFormErrorMessage($formErrors); + $msg = $this->getFormErrorMessage($formErrors); + return $this->returnError($msg, Codes::HTTP_BAD_REQUEST, $formErrors); } @@ -432,7 +429,7 @@ public function getFormErrorMessages(\Symfony\Component\Form\Form $form) } /** - * Checks if user has permission to access retrieved entity + * Checks if user has permission to access retrieved entity. * * @param mixed $entity * @param string $action view|create|edit|publish|delete @@ -452,7 +449,7 @@ protected function checkEntityAccess($entity, $action = 'view') } /** - * Creates the form instance + * Creates the form instance. * * @param $entity * @@ -464,11 +461,9 @@ protected function createEntityForm($entity) } /** - * Set serialization groups and exclusion strategies + * Set serialization groups and exclusion strategies. * * @param \FOS\RestBundle\View\View $view - * - * @return void */ protected function setSerializationContext(&$view) { @@ -489,7 +484,7 @@ protected function setSerializationContext(&$view) } /** - * Convert posted parameters into what the form needs in order to successfully bind + * Convert posted parameters into what the form needs in order to successfully bind. * * @param $parameters * @param $entity @@ -503,7 +498,7 @@ protected function prepareParametersForBinding($parameters, $entity, $action) } /** - * Give the controller an opportunity to process the entity before persisting + * Give the controller an opportunity to process the entity before persisting. * * @param $entity * @param $form @@ -517,7 +512,7 @@ protected function preSaveEntity(&$entity, $form, $parameters, $action = 'edit') } /** - * Gives child controllers opportunity to analyze and do whatever to an entity before going through serializer + * Gives child controllers opportunity to analyze and do whatever to an entity before going through serializer. * * @param $entity * @param string $action @@ -529,7 +524,7 @@ protected function preSerializeEntity(&$entity, $action = 'view') } /** - * Gives child controllers opportunity to analyze and do whatever to an entity before populating the form + * Gives child controllers opportunity to analyze and do whatever to an entity before populating the form. * * @param $entity * @param $parameters @@ -542,11 +537,11 @@ protected function prePopulateForm(&$entity, $parameters, $action = 'edit') } /** - * Returns an error + * Returns an error. * - * @param string $msg - * @param integer $code - * @param array $details + * @param string $msg + * @param int $code + * @param array $details * * @return Response */ @@ -556,9 +551,9 @@ protected function returnError($msg, $code, $details = []) [ 'error' => [ 'code' => $code, - 'message' => $this->get('translator')->trans($msg, array(), 'flashes'), - 'details' => $details - ] + 'message' => $this->get('translator')->trans($msg, [], 'flashes'), + 'details' => $details, + ], ], $code ); @@ -567,7 +562,7 @@ protected function returnError($msg, $code, $details = []) } /** - * Returns a 403 Access Denied + * Returns a 403 Access Denied. * * @param string $msg * @@ -579,7 +574,7 @@ protected function accessDenied($msg = 'mautic.core.error.accessdenied') } /** - * Returns a 404 Not Found + * Returns a 404 Not Found. * * @param string $msg * @@ -591,7 +586,7 @@ protected function notFound($msg = 'mautic.core.error.notfound') } /** - * Returns a 400 Bad Request + * Returns a 400 Bad Request. * * @param string $msg * @@ -609,9 +604,8 @@ protected function badRequest($msg = 'mautic.core.error.badrequest') * @param null $statusCode * @param array $headers */ - protected function view($data = null, $statusCode = null, array $headers = array()) + protected function view($data = null, $statusCode = null, array $headers = []) { - if ($data instanceof Paginator) { // Get iterator out of Paginator class so that the entities are properly serialized by the serializer $data = $data->getIterator()->getArrayCopy(); @@ -621,7 +615,7 @@ protected function view($data = null, $statusCode = null, array $headers = array } /** - * Prepares entities returned from repository getEntities() + * Prepares entities returned from repository getEntities(). * * @param $results * @@ -629,7 +623,6 @@ protected function view($data = null, $statusCode = null, array $headers = array */ protected function prepareEntitiesForView($results) { - if ($results instanceof Paginator) { $totalCount = count($results); } elseif (isset($results['count'])) { @@ -641,7 +634,7 @@ protected function prepareEntitiesForView($results) //we have to convert them from paginated proxy functions to entities in order for them to be //returned by the serializer/rest bundle - $entities = array(); + $entities = []; foreach ($results as $r) { if (is_array($r) && isset($r[0])) { //entity has some extra something something tacked onto the entities @@ -669,11 +662,11 @@ protected function prepareEntitiesForView($results) } } - return array($entities, $totalCount); + return [$entities, $totalCount]; } /** - * Get a model instance from the service container + * Get a model instance from the service container. * * @param $modelNameKey * @@ -689,17 +682,17 @@ protected function getModel($modelNameKey) $parts = explode('.', $modelNameKey); if (count($parts) !== 2) { - throw new \InvalidArgumentException($modelNameKey . " is not a valid model key."); + throw new \InvalidArgumentException($modelNameKey.' is not a valid model key.'); } list($bundle, $name) = $parts; - $containerKey = str_replace(array('%bundle%', '%name%'), array($bundle, $name), 'mautic.%bundle%.model.%name%'); + $containerKey = str_replace(['%bundle%', '%name%'], [$bundle, $name], 'mautic.%bundle%.model.%name%'); if ($this->container->has($containerKey)) { return $this->container->get($containerKey); } - throw new \InvalidArgumentException($containerKey . ' is not a registered container key.'); + throw new \InvalidArgumentException($containerKey.' is not a registered container key.'); } } diff --git a/app/bundles/ApiBundle/Controller/oAuth1/AuthorizeController.php b/app/bundles/ApiBundle/Controller/oAuth1/AuthorizeController.php index c058639dbd2..5b789dc4090 100644 --- a/app/bundles/ApiBundle/Controller/oAuth1/AuthorizeController.php +++ b/app/bundles/ApiBundle/Controller/oAuth1/AuthorizeController.php @@ -1,9 +1,10 @@ setUserForRequestToken($token, $securityContext->getToken()->getUser()); - return new Response($this->container->get('templating')->render('MauticApiBundle:Authorize:oAuth1/authorize.html.php', array( + return new Response($this->container->get('templating')->render('MauticApiBundle:Authorize:oAuth1/authorize.html.php', [ 'consumer' => $token->getConsumer(), 'oauth_token' => $oauth_token, - 'oauth_callback' => $oauth_callback - ))); + 'oauth_callback' => $oauth_callback, + ])); } - throw new HttpException(404); } } diff --git a/app/bundles/ApiBundle/Controller/oAuth1/SecurityController.php b/app/bundles/ApiBundle/Controller/oAuth1/SecurityController.php index 0b61a712077..11dd3234dbc 100644 --- a/app/bundles/ApiBundle/Controller/oAuth1/SecurityController.php +++ b/app/bundles/ApiBundle/Controller/oAuth1/SecurityController.php @@ -1,9 +1,10 @@ getMessage(); } - $this->addFlash($msg, array(), 'error', null, false); + $this->addFlash($msg, [], 'error', null, false); } return $this->render( 'MauticApiBundle:Security:login.html.php', - array( + [ 'last_username' => $session->get(SecurityContext::LAST_USERNAME), - 'route' => 'mautic_oauth1_server_auth_login_check' - ) + 'route' => 'mautic_oauth1_server_auth_login_check', + ] ); } @@ -60,4 +60,4 @@ public function loginCheckAction() { return new Response('', 400); } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/Controller/oAuth2/AuthorizeController.php b/app/bundles/ApiBundle/Controller/oAuth2/AuthorizeController.php index bf87ebfb9bb..5c5ad1f1495 100644 --- a/app/bundles/ApiBundle/Controller/oAuth2/AuthorizeController.php +++ b/app/bundles/ApiBundle/Controller/oAuth2/AuthorizeController.php @@ -1,10 +1,11 @@ container->get('session')->set('_fos_oauth_server.ensure_logout', true); } - $form = $this->container->get('fos_oauth_server.authorize.form'); + $form = $this->container->get('fos_oauth_server.authorize.form'); $formHandler = $this->container->get('fos_oauth_server.authorize.form.handler'); $event = $this->container->get('event_dispatcher')->dispatch( @@ -67,10 +68,10 @@ public function authorizeAction(Request $request) return $this->container->get('templating')->renderResponse( 'MauticApiBundle:Authorize:oAuth2/authorize.html.php', - array( - 'form' => $form->createView(), - 'client' => $this->getClient(), - ) + [ + 'form' => $form->createView(), + 'client' => $this->getClient(), + ] ); } } diff --git a/app/bundles/ApiBundle/Controller/oAuth2/SecurityController.php b/app/bundles/ApiBundle/Controller/oAuth2/SecurityController.php index e1a7c551253..fed39885b6d 100644 --- a/app/bundles/ApiBundle/Controller/oAuth2/SecurityController.php +++ b/app/bundles/ApiBundle/Controller/oAuth2/SecurityController.php @@ -1,9 +1,10 @@ getMessage(); } - $this->addFlash($msg, array(), 'error', null, false); + $this->addFlash($msg, [], 'error', null, false); } if ($session->has('_security.target_path')) { @@ -54,10 +54,10 @@ public function loginAction(Request $request) return $this->render( 'MauticApiBundle:Security:login.html.php', - array( + [ 'last_username' => $session->get(SecurityContext::LAST_USERNAME), - 'route' => 'mautic_oauth2_server_auth_login_check' - ) + 'route' => 'mautic_oauth2_server_auth_login_check', + ] ); } diff --git a/app/bundles/ApiBundle/DependencyInjection/Compiler/OAuthPass.php b/app/bundles/ApiBundle/DependencyInjection/Compiler/OAuthPass.php index f7f28df3620..b91988a078a 100644 --- a/app/bundles/ApiBundle/DependencyInjection/Compiler/OAuthPass.php +++ b/app/bundles/ApiBundle/DependencyInjection/Compiler/OAuthPass.php @@ -1,9 +1,10 @@ hasDefinition('bazinga.oauth.security.authentication.provider')) { //Add a addMethodCall to set factory $container->getDefinition('bazinga.oauth.security.authentication.provider')->addMethodCall( - 'setFactory', array(new Reference('mautic.factory')) + 'setFactory', [new Reference('mautic.factory')] ); } if ($container->hasDefinition('bazinga.oauth.security.authentication.listener')) { //Add a addMethodCall to set factory $container->getDefinition('bazinga.oauth.security.authentication.listener')->addMethodCall( - 'setFactory', array(new Reference('mautic.factory')) + 'setFactory', [new Reference('mautic.factory')] ); } if ($container->hasDefinition('fos_oauth_server.security.authentication.listener')) { //Add a addMethodCall to set factory $container->getDefinition('fos_oauth_server.security.authentication.listener')->addMethodCall( - 'setFactory', array(new Reference('mautic.factory')) + 'setFactory', [new Reference('mautic.factory')] ); } } diff --git a/app/bundles/ApiBundle/DependencyInjection/Factory/ApiFactory.php b/app/bundles/ApiBundle/DependencyInjection/Factory/ApiFactory.php index ca3bdc59228..19bf175a841 100644 --- a/app/bundles/ApiBundle/DependencyInjection/Factory/ApiFactory.php +++ b/app/bundles/ApiBundle/DependencyInjection/Factory/ApiFactory.php @@ -1,22 +1,23 @@ setDefinition($listenerId, new DefinitionDecorator('mautic_api.security.authentication.listener')); - return array($providerId, $listenerId, $defaultEntryPoint); + return [$providerId, $listenerId, $defaultEntryPoint]; } /** diff --git a/app/bundles/ApiBundle/Entity/oAuth1/AccessToken.php b/app/bundles/ApiBundle/Entity/oAuth1/AccessToken.php index 5b43c340de9..ec24a2850ae 100644 --- a/app/bundles/ApiBundle/Entity/oAuth1/AccessToken.php +++ b/app/bundles/ApiBundle/Entity/oAuth1/AccessToken.php @@ -1,28 +1,26 @@ setTable('oauth1_access_tokens') - ->addIndex(array('token'), 'oauth1_access_token_search'); + ->addIndex(['token'], 'oauth1_access_token_search'); $builder->createField('id', 'integer') ->isPrimaryKey() @@ -88,25 +86,25 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getId () + public function getId() { return $this->id; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getToken () + public function getToken() { return $this->token; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setToken ($token) + public function setToken($token) { $this->token = $token; @@ -114,17 +112,17 @@ public function setToken ($token) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getSecret () + public function getSecret() { return $this->secret; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setSecret ($secret) + public function setSecret($secret) { $this->secret = $secret; @@ -132,17 +130,17 @@ public function setSecret ($secret) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getExpiresAt () + public function getExpiresAt() { return $this->expiresAt; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setExpiresAt ($expiresAt) + public function setExpiresAt($expiresAt) { $this->expiresAt = $expiresAt; @@ -150,9 +148,9 @@ public function setExpiresAt ($expiresAt) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getExpiresIn () + public function getExpiresIn() { if ($this->expiresAt) { return $this->expiresAt - time(); @@ -162,9 +160,9 @@ public function getExpiresIn () } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function hasExpired () + public function hasExpired() { if ($this->expiresAt) { return time() > $this->expiresAt; @@ -174,17 +172,17 @@ public function hasExpired () } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getUser () + public function getUser() { return $this->user; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setUser (UserInterface $user) + public function setUser(UserInterface $user) { $this->user = $user; @@ -192,9 +190,9 @@ public function setUser (UserInterface $user) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setConsumer (ConsumerInterface $consumer) + public function setConsumer(ConsumerInterface $consumer) { $this->consumer = $consumer; @@ -202,9 +200,9 @@ public function setConsumer (ConsumerInterface $consumer) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getConsumer () + public function getConsumer() { return $this->consumer; } diff --git a/app/bundles/ApiBundle/Entity/oAuth1/Consumer.php b/app/bundles/ApiBundle/Entity/oAuth1/Consumer.php index 33b1c4bcf28..089ad226541 100644 --- a/app/bundles/ApiBundle/Entity/oAuth1/Consumer.php +++ b/app/bundles/ApiBundle/Entity/oAuth1/Consumer.php @@ -1,9 +1,10 @@ accessTokens = new ArrayCollection(); } @@ -66,14 +64,14 @@ public function __construct () /** * @param ORM\ClassMetadata $metadata */ - public static function loadMetadata (ORM\ClassMetadata $metadata) + public static function loadMetadata(ORM\ClassMetadata $metadata) { $builder = new ClassMetadataBuilder($metadata); $builder->setTable('oauth1_consumers') ->setCustomRepositoryClass('Mautic\ApiBundle\Entity\oAuth1\ConsumerRepository') ->addLifecycleEvent('createConsumerKeys', 'prePersist') - ->addIndex(array('consumer_key'), 'consumer_search'); + ->addIndex(['consumer_key'], 'consumer_search'); $builder->addIdColumns('name', false); @@ -97,47 +95,47 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) /** * @param ClassMetadata $metadata */ - public static function loadValidatorMetadata (ClassMetadata $metadata) + public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('name', new Assert\NotBlank( - array('message' => 'mautic.core.name.required') + ['message' => 'mautic.core.name.required'] )); } /** - * Proxy to get consumer key + * Proxy to get consumer key. * * @return mixed */ - public function getRandomId () + public function getRandomId() { return $this->consumerKey; } /** - * Proxy to consumer key + * Proxy to consumer key. * * @return mixed */ - public function getPublicId () + public function getPublicId() { return $this->consumerKey; } /** - * Proxy to consumer secret + * Proxy to consumer secret. * * @return mixed */ - public function getSecret () + public function getSecret() { return $this->consumerSecret; } /** - * Create consumer keys + * Create consumer keys. */ - public function createConsumerKeys () + public function createConsumerKeys() { if (empty($this->consumerKey)) { $this->consumerKey = Random::generateToken(); @@ -146,35 +144,35 @@ public function createConsumerKeys () } /** - * Proxy to callback + * Proxy to callback. * * @return array */ - public function getRedirectUris () + public function getRedirectUris() { - return array($this->callback); + return [$this->callback]; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getId () + public function getId() { return $this->id; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getName () + public function getName() { return $this->name; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setName ($name) + public function setName($name) { $this->name = $name; @@ -182,17 +180,17 @@ public function setName ($name) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getConsumerKey () + public function getConsumerKey() { return $this->consumerKey; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setConsumerKey ($consumerKey) + public function setConsumerKey($consumerKey) { $this->consumerKey = $consumerKey; @@ -200,17 +198,17 @@ public function setConsumerKey ($consumerKey) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getConsumerSecret () + public function getConsumerSecret() { return $this->consumerSecret; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setConsumerSecret ($consumerSecret) + public function setConsumerSecret($consumerSecret) { $this->consumerSecret = $consumerSecret; @@ -218,17 +216,17 @@ public function setConsumerSecret ($consumerSecret) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getCallback () + public function getCallback() { return $this->callback; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setCallback ($callback) + public function setCallback($callback) { $this->callback = $callback; diff --git a/app/bundles/ApiBundle/Entity/oAuth1/ConsumerRepository.php b/app/bundles/ApiBundle/Entity/oAuth1/ConsumerRepository.php index fd51cc3f278..c0dc47a9d98 100644 --- a/app/bundles/ApiBundle/Entity/oAuth1/ConsumerRepository.php +++ b/app/bundles/ApiBundle/Entity/oAuth1/ConsumerRepository.php @@ -1,24 +1,24 @@ expr()->eq('a.user', ':user') ) ) - ->setParameters(array( + ->setParameters([ 'consumer' => $consumer, - 'user' => $user - )); + 'user' => $user, + ]); $qb->getQuery()->execute(); } @@ -66,12 +64,13 @@ public function deleteAccessTokens(Consumer $consumer, User $user) /** * {@inheritdoc} */ - public function getEntities($args = array()) + public function getEntities($args = []) { $q = $this ->createQueryBuilder('c'); $query = $q->getQuery(); + return new Paginator($query); } @@ -80,8 +79,8 @@ public function getEntities($args = array()) */ protected function addCatchAllWhereClause(&$q, $filter) { - $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier - $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; + $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier + $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; $expr = $q->expr()->orX( $q->expr()->like('c.name', ':'.$unique), @@ -92,10 +91,10 @@ protected function addCatchAllWhereClause(&$q, $filter) $expr = $q->expr()->not($expr); } - return array( + return [ $expr, - array("$unique" => $string) - ); + ["$unique" => $string], + ]; } /** @@ -103,9 +102,9 @@ protected function addCatchAllWhereClause(&$q, $filter) */ protected function getDefaultOrder() { - return array( - array('c.name', 'ASC') - ); + return [ + ['c.name', 'ASC'], + ]; } /** diff --git a/app/bundles/ApiBundle/Entity/oAuth1/Nonce.php b/app/bundles/ApiBundle/Entity/oAuth1/Nonce.php index 23d39f5ac17..231f0972b14 100644 --- a/app/bundles/ApiBundle/Entity/oAuth1/Nonce.php +++ b/app/bundles/ApiBundle/Entity/oAuth1/Nonce.php @@ -1,9 +1,10 @@ nonce = $nonce; $this->timestamp = $timestamp; @@ -41,7 +39,7 @@ public function __construct ($nonce, $timestamp) /** * @param ORM\ClassMetadata $metadata */ - public static function loadMetadata (ORM\ClassMetadata $metadata) + public static function loadMetadata(ORM\ClassMetadata $metadata) { $builder = new ClassMetadataBuilder($metadata); @@ -58,7 +56,7 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) /** * @return mixed */ - public function getNonce () + public function getNonce() { return $this->nonce; } @@ -66,7 +64,7 @@ public function getNonce () /** * @return mixed */ - public function getTimestamp () + public function getTimestamp() { return $this->timestamp; } diff --git a/app/bundles/ApiBundle/Entity/oAuth1/NonceRepository.php b/app/bundles/ApiBundle/Entity/oAuth1/NonceRepository.php index ffb5ba80f3f..fa80733f8f5 100644 --- a/app/bundles/ApiBundle/Entity/oAuth1/NonceRepository.php +++ b/app/bundles/ApiBundle/Entity/oAuth1/NonceRepository.php @@ -1,9 +1,10 @@ setTable('oauth1_request_tokens') - ->addIndex(array('token'), 'oauth1_request_token_search'); + ->addIndex(['token'], 'oauth1_request_token_search'); $builder->createField('id', 'integer') ->isPrimaryKey() @@ -93,25 +91,25 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getId () + public function getId() { return $this->id; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getToken () + public function getToken() { return $this->token; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setToken ($token) + public function setToken($token) { $this->token = $token; @@ -119,17 +117,17 @@ public function setToken ($token) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getSecret () + public function getSecret() { return $this->secret; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setSecret ($secret) + public function setSecret($secret) { $this->secret = $secret; @@ -137,17 +135,17 @@ public function setSecret ($secret) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getExpiresAt () + public function getExpiresAt() { return $this->expiresAt; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setExpiresAt ($expiresAt) + public function setExpiresAt($expiresAt) { $this->expiresAt = $expiresAt; @@ -155,9 +153,9 @@ public function setExpiresAt ($expiresAt) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getExpiresIn () + public function getExpiresIn() { if ($this->expiresAt) { return $this->expiresAt - time(); @@ -167,9 +165,9 @@ public function getExpiresIn () } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function hasExpired () + public function hasExpired() { if ($this->expiresAt) { return time() > $this->expiresAt; @@ -179,17 +177,17 @@ public function hasExpired () } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getUser () + public function getUser() { return $this->user; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setUser (UserInterface $user) + public function setUser(UserInterface $user) { $this->user = $user; @@ -197,9 +195,9 @@ public function setUser (UserInterface $user) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setConsumer (ConsumerInterface $consumer) + public function setConsumer(ConsumerInterface $consumer) { $this->consumer = $consumer; @@ -207,25 +205,25 @@ public function setConsumer (ConsumerInterface $consumer) } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getConsumer () + public function getConsumer() { return $this->consumer; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function getVerifier () + public function getVerifier() { return $this->verifier; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function setVerifier ($verifier) + public function setVerifier($verifier) { $this->verifier = $verifier; } diff --git a/app/bundles/ApiBundle/Entity/oAuth2/AccessToken.php b/app/bundles/ApiBundle/Entity/oAuth2/AccessToken.php index 03452ebdfab..adb817f1dcf 100644 --- a/app/bundles/ApiBundle/Entity/oAuth2/AccessToken.php +++ b/app/bundles/ApiBundle/Entity/oAuth2/AccessToken.php @@ -1,28 +1,26 @@ setTable('oauth2_accesstokens') - ->addIndex(array('token'), 'oauth2_access_token_search'); + ->addIndex(['token'], 'oauth2_access_token_search'); $builder->createField('id', 'integer') ->isPrimaryKey() @@ -91,23 +89,23 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) } /** - * Get id + * Get id. * - * @return integer + * @return int */ - public function getId () + public function getId() { return $this->id; } /** - * Set client + * Set client. * * @param ClientInterface $client * * @return AccessToken */ - public function setClient (ClientInterface $client) + public function setClient(ClientInterface $client) { $this->client = $client; @@ -115,23 +113,23 @@ public function setClient (ClientInterface $client) } /** - * Get client + * Get client. * * @return ClientInterface */ - public function getClient () + public function getClient() { return $this->client; } /** - * Set user + * Set user. * * @param UserInterface $user * * @return AccessToken */ - public function setUser (UserInterface $user = null) + public function setUser(UserInterface $user = null) { $this->user = $user; @@ -139,11 +137,11 @@ public function setUser (UserInterface $user = null) } /** - * Get user + * Get user. * * @return UserInterface */ - public function getUser () + public function getUser() { return $this->user; } diff --git a/app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php b/app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php index df6921c7984..fd3748c26f6 100644 --- a/app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php +++ b/app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php @@ -1,28 +1,26 @@ id; } /** - * Set client + * Set client. * * @param ClientInterface $client * * @return RefreshToken */ - public function setClient (ClientInterface $client) + public function setClient(ClientInterface $client) { $this->client = $client; @@ -123,23 +121,23 @@ public function setClient (ClientInterface $client) } /** - * Get client + * Get client. * * @return ClientInterface */ - public function getClient () + public function getClient() { return $this->client; } /** - * Set user + * Set user. * * @param UserInterface $user * * @return RefreshToken */ - public function setUser (UserInterface $user = null) + public function setUser(UserInterface $user = null) { $this->user = $user; @@ -147,11 +145,11 @@ public function setUser (UserInterface $user = null) } /** - * Get user + * Get user. * * @return UserInterface */ - public function getUser () + public function getUser() { return $this->user; } diff --git a/app/bundles/ApiBundle/Entity/oAuth2/Client.php b/app/bundles/ApiBundle/Entity/oAuth2/Client.php index f32eae761ab..e66aa6b593c 100644 --- a/app/bundles/ApiBundle/Entity/oAuth2/Client.php +++ b/app/bundles/ApiBundle/Entity/oAuth2/Client.php @@ -1,17 +1,18 @@ allowedGrantTypes = array( + $this->allowedGrantTypes = [ OAuth2::GRANT_TYPE_AUTH_CODE, OAuth2::GRANT_TYPE_REFRESH_TOKEN, - ); + ]; $this->users = new ArrayCollection(); } @@ -79,13 +77,13 @@ public function __construct () /** * @param ORM\ClassMetadata $metadata */ - public static function loadMetadata (ORM\ClassMetadata $metadata) + public static function loadMetadata(ORM\ClassMetadata $metadata) { $builder = new ClassMetadataBuilder($metadata); $builder->setTable('oauth2_clients') ->setCustomRepositoryClass('Mautic\ApiBundle\Entity\oAuth2\ClientRepository') - ->addIndex(array('random_id'), 'client_id_search'); + ->addIndex(['random_id'], 'client_id_search'); $builder->addIdColumns('name', false); @@ -114,14 +112,14 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) /** * @param ClassMetadata $metadata */ - public static function loadValidatorMetadata (ClassMetadata $metadata) + public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('name', new Assert\NotBlank( - array('message' => 'mautic.core.name.required') + ['message' => 'mautic.core.name.required'] )); $metadata->addPropertyConstraint('redirectUris', new Assert\NotBlank( - array('message' => 'mautic.api.client.redirecturis.notblank') + ['message' => 'mautic.api.client.redirecturis.notblank'] )); } @@ -133,44 +131,42 @@ public static function loadValidatorMetadata (ClassMetadata $metadata) /** * @param $prop * @param $val - * - * @return void */ - protected function isChanged ($prop, $val) + protected function isChanged($prop, $val) { - $getter = "get" . ucfirst($prop); + $getter = 'get'.ucfirst($prop); $current = $this->$getter(); if ($current != $val) { - $this->changes[$prop] = array($current, $val); + $this->changes[$prop] = [$current, $val]; } } /** * @return array */ - public function getChanges () + public function getChanges() { return $this->changes; } /** - * Get id + * Get id. * - * @return integer + * @return int */ - public function getId () + public function getId() { return $this->id; } /** - * Set name + * Set name. * * @param string $name * * @return Client */ - public function setName ($name) + public function setName($name) { $this->isChanged('name', $name); @@ -180,11 +176,11 @@ public function setName ($name) } /** - * Get name + * Get name. * * @return string */ - public function getName () + public function getName() { return $this->name; } @@ -192,7 +188,7 @@ public function getName () /** * {@inheritdoc} */ - public function setRedirectUris (array $redirectUris) + public function setRedirectUris(array $redirectUris) { $this->isChanged('redirectUris', $redirectUris); @@ -200,13 +196,13 @@ public function setRedirectUris (array $redirectUris) } /** - * Add authCodes + * Add authCodes. * * @param AuthCode $authCodes * * @return Client */ - public function addAuthCode (AuthCode $authCodes) + public function addAuthCode(AuthCode $authCodes) { $this->authCodes[] = $authCodes; @@ -214,33 +210,33 @@ public function addAuthCode (AuthCode $authCodes) } /** - * Remove authCodes + * Remove authCodes. * * @param AuthCode $authCodes */ - public function removeAuthCode (AuthCode $authCodes) + public function removeAuthCode(AuthCode $authCodes) { $this->authCodes->removeElement($authCodes); } /** - * Get authCodes + * Get authCodes. * * @return \Doctrine\Common\Collections\Collection */ - public function getAuthCodes () + public function getAuthCodes() { return $this->authCodes; } /** - * Determines if a client attempting API access is already authorized by the user + * Determines if a client attempting API access is already authorized by the user. * * @param User $user * * @return bool */ - public function isAuthorizedClient (User $user) + public function isAuthorizedClient(User $user) { $users = $this->getUsers(); @@ -248,13 +244,13 @@ public function isAuthorizedClient (User $user) } /** - * Add users + * Add users. * * @param \Mautic\UserBundle\Entity\User $users * * @return Client */ - public function addUser (\Mautic\UserBundle\Entity\User $users) + public function addUser(\Mautic\UserBundle\Entity\User $users) { $this->users[] = $users; @@ -262,21 +258,21 @@ public function addUser (\Mautic\UserBundle\Entity\User $users) } /** - * Remove users + * Remove users. * * @param \Mautic\UserBundle\Entity\User $users */ - public function removeUser (\Mautic\UserBundle\Entity\User $users) + public function removeUser(\Mautic\UserBundle\Entity\User $users) { $this->users->removeElement($users); } /** - * Get users + * Get users. * * @return \Doctrine\Common\Collections\Collection */ - public function getUsers () + public function getUsers() { return $this->users; } diff --git a/app/bundles/ApiBundle/Entity/oAuth2/ClientRepository.php b/app/bundles/ApiBundle/Entity/oAuth2/ClientRepository.php index 9c82eadf1ab..882a1295eaf 100644 --- a/app/bundles/ApiBundle/Entity/oAuth2/ClientRepository.php +++ b/app/bundles/ApiBundle/Entity/oAuth2/ClientRepository.php @@ -1,24 +1,24 @@ createQueryBuilder('c'); $query = $q->getQuery(); + return new Paginator($query); } @@ -52,8 +53,8 @@ public function getEntities($args = array()) */ protected function addCatchAllWhereClause(&$q, $filter) { - $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier - $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; + $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier + $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; $expr = $q->expr()->orX( $q->expr()->like('c.name', ':'.$unique), @@ -64,10 +65,10 @@ protected function addCatchAllWhereClause(&$q, $filter) $expr = $q->expr()->not($expr); } - return array( + return [ $expr, - array("$unique" => $string) - ); + ["$unique" => $string], + ]; } /** @@ -75,9 +76,9 @@ protected function addCatchAllWhereClause(&$q, $filter) */ protected function getDefaultOrder() { - return array( - array('c.name', 'ASC') - ); + return [ + ['c.name', 'ASC'], + ]; } /** diff --git a/app/bundles/ApiBundle/Entity/oAuth2/RefreshToken.php b/app/bundles/ApiBundle/Entity/oAuth2/RefreshToken.php index 8254f85358e..f3a857bae54 100644 --- a/app/bundles/ApiBundle/Entity/oAuth2/RefreshToken.php +++ b/app/bundles/ApiBundle/Entity/oAuth2/RefreshToken.php @@ -1,28 +1,26 @@ setTable('oauth2_refreshtokens') - ->addIndex(array('token'), 'oauth2_refresh_token_search'); + ->addIndex(['token'], 'oauth2_refresh_token_search'); $builder->createField('id', 'integer') ->isPrimaryKey() @@ -91,23 +89,23 @@ public static function loadMetadata (ORM\ClassMetadata $metadata) } /** - * Get id + * Get id. * - * @return integer + * @return int */ - public function getId () + public function getId() { return $this->id; } /** - * Set client + * Set client. * * @param ClientInterface $client * * @return RefreshToken */ - public function setClient (ClientInterface $client) + public function setClient(ClientInterface $client) { $this->client = $client; @@ -115,23 +113,23 @@ public function setClient (ClientInterface $client) } /** - * Get client + * Get client. * * @return ClientInterface */ - public function getClient () + public function getClient() { return $this->client; } /** - * Set user + * Set user. * * @param UserInterface $user * * @return RefreshToken */ - public function setUser (UserInterface $user = null) + public function setUser(UserInterface $user = null) { $this->user = $user; @@ -139,12 +137,12 @@ public function setUser (UserInterface $user = null) } /** - * Get user + * Get user. * * @return UserInterface */ - public function getUser () + public function getUser() { return $this->user; } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/Event/ClientEvent.php b/app/bundles/ApiBundle/Event/ClientEvent.php index 53bd69d3c01..69482cbe335 100644 --- a/app/bundles/ApiBundle/Event/ClientEvent.php +++ b/app/bundles/ApiBundle/Event/ClientEvent.php @@ -1,25 +1,25 @@ apiMode = ($client instanceof Client) ? 'oauth2' : 'oauth1'; @@ -42,7 +42,7 @@ public function __construct($client, $isNew = false) } /** - * Returns the Client entity + * Returns the Client entity. * * @return Client */ @@ -52,7 +52,7 @@ public function getClient() } /** - * Returns the api mode + * Returns the api mode. * * @return string */ diff --git a/app/bundles/ApiBundle/EventListener/ApiSubscriber.php b/app/bundles/ApiBundle/EventListener/ApiSubscriber.php index 333c4b543d4..d7b5ceecdd0 100644 --- a/app/bundles/ApiBundle/EventListener/ApiSubscriber.php +++ b/app/bundles/ApiBundle/EventListener/ApiSubscriber.php @@ -1,16 +1,16 @@ ipLookupHelper = $ipLookupHelper; + $this->ipLookupHelper = $ipLookupHelper; $this->coreParametersHelper = $coreParametersHelper; - $this->auditLogModel = $auditLogModel; + $this->auditLogModel = $auditLogModel; } /** @@ -59,15 +59,15 @@ public function __construct(IpLookupHelper $ipLookupHelper, CoreParametersHelper */ public static function getSubscribedEvents() { - return array( - KernelEvents::REQUEST => array('onKernelRequest', 255), - ApiEvents::CLIENT_POST_SAVE => array('onClientPostSave', 0), - ApiEvents::CLIENT_POST_DELETE => array('onClientDelete', 0) - ); + return [ + KernelEvents::REQUEST => ['onKernelRequest', 255], + ApiEvents::CLIENT_POST_SAVE => ['onClientPostSave', 0], + ApiEvents::CLIENT_POST_DELETE => ['onClientDelete', 0], + ]; } /** - * Check for API requests and throw denied access if API is disabled + * Check for API requests and throw denied access if API is disabled. * * @param GetResponseEvent $event */ @@ -86,20 +86,19 @@ public function onKernelRequest(GetResponseEvent $event) defined('MAUTIC_API_REQUEST') or define('MAUTIC_API_REQUEST', $isApiRequest); if ($isApiRequest && !$apiEnabled) { - throw new AccessDeniedHttpException( $this->translator->trans( 'mautic.core.url.error.401', - array( - '%url%' => $request->getRequestUri() - ) + [ + '%url%' => $request->getRequestUri(), + ] ) ); } } /** - * Add a client change entry to the audit log + * Add a client change entry to the audit log. * * @param Events\ClientEvent $event */ @@ -107,34 +106,34 @@ public function onClientPostSave(Events\ClientEvent $event) { $client = $event->getClient(); if ($details = $event->getChanges()) { - $log = array( + $log = [ 'bundle' => 'api', 'object' => 'client', 'objectId' => $client->getId(), 'action' => ($event->isNew()) ? 'create' : 'update', 'details' => $details, - 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest() - ); + 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), + ]; $this->auditLogModel->writeToLog($log); } } /** - * Add a role delete entry to the audit log + * Add a role delete entry to the audit log. * * @param Events\ClientEvent $event */ public function onClientDelete(Events\ClientEvent $event) { $client = $event->getClient(); - $log = array( - 'bundle' => 'api', - 'object' => 'client', - 'objectId' => $client->deletedId, - 'action' => 'delete', - 'details' => array('name' => $client->getName()), - 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest() - ); + $log = [ + 'bundle' => 'api', + 'object' => 'client', + 'objectId' => $client->deletedId, + 'action' => 'delete', + 'details' => ['name' => $client->getName()], + 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), + ]; $this->auditLogModel->writeToLog($log); } } diff --git a/app/bundles/ApiBundle/EventListener/ConfigSubscriber.php b/app/bundles/ApiBundle/EventListener/ConfigSubscriber.php index 8fb6844224d..0f9b7d2888f 100644 --- a/app/bundles/ApiBundle/EventListener/ConfigSubscriber.php +++ b/app/bundles/ApiBundle/EventListener/ConfigSubscriber.php @@ -1,42 +1,41 @@ array('onConfigGenerate', 0) - ); + return [ + ConfigEvents::CONFIG_ON_GENERATE => ['onConfigGenerate', 0], + ]; } - public function onConfigGenerate (ConfigBuilderEvent $event) + public function onConfigGenerate(ConfigBuilderEvent $event) { - $event->addForm(array( + $event->addForm([ 'bundle' => 'ApiBundle', 'formAlias' => 'apiconfig', 'formTheme' => 'MauticApiBundle:FormTheme\Config', - 'parameters' => $event->getParametersFromConfig('MauticApiBundle') - )); + 'parameters' => $event->getParametersFromConfig('MauticApiBundle'), + ]); } } diff --git a/app/bundles/ApiBundle/EventListener/OAuth1/OAuthRequestListener.php b/app/bundles/ApiBundle/EventListener/OAuth1/OAuthRequestListener.php index 40c4a2938b9..9c31326d6ba 100644 --- a/app/bundles/ApiBundle/EventListener/OAuth1/OAuthRequestListener.php +++ b/app/bundles/ApiBundle/EventListener/OAuth1/OAuthRequestListener.php @@ -1,9 +1,10 @@ getUser($event)) { //check to see if user has api access - if (!$this->mauticSecurity->isGranted("api:access:full")) { - throw new AccessDeniedException($this->translator->trans('mautic.core.error.accessdenied', array(), 'flashes')); + if (!$this->mauticSecurity->isGranted('api:access:full')) { + throw new AccessDeniedException($this->translator->trans('mautic.core.error.accessdenied', [], 'flashes')); } $client = $event->getClient(); $event->setAuthorizedClient( @@ -68,8 +68,6 @@ public function onPreAuthorizationProcess(OAuthEvent $event) /** * @param OAuthEvent $event - * - * @return void */ public function onPostAuthorizationProcess(OAuthEvent $event) { diff --git a/app/bundles/ApiBundle/EventListener/SearchSubscriber.php b/app/bundles/ApiBundle/EventListener/SearchSubscriber.php index afe01ea3f86..b8eb62e37c4 100644 --- a/app/bundles/ApiBundle/EventListener/SearchSubscriber.php +++ b/app/bundles/ApiBundle/EventListener/SearchSubscriber.php @@ -1,23 +1,22 @@ array('onGlobalSearch', 0), - CoreEvents::BUILD_COMMAND_LIST => array('onBuildCommandList', 0) - ); + return [ + CoreEvents::GLOBAL_SEARCH => ['onGlobalSearch', 0], + CoreEvents::BUILD_COMMAND_LIST => ['onBuildCommandList', 0], + ]; } /** @@ -59,31 +58,31 @@ public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event) } $clients = $this->apiClientModel->getEntities( - array( + [ 'limit' => 5, - 'filter' => $str - )); + 'filter' => $str, + ]); if (count($clients) > 0) { - $clientResults = array(); - $canEdit = $this->security->isGranted('api:clients:edit'); + $clientResults = []; + $canEdit = $this->security->isGranted('api:clients:edit'); foreach ($clients as $client) { $clientResults[] = $this->templating->renderResponse( 'MauticApiBundle:SubscribedEvents\Search:global.html.php', - array( + [ 'client' => $client, - 'canEdit' => $canEdit - ) + 'canEdit' => $canEdit, + ] )->getContent(); } if (count($clients) > 5) { $clientResults[] = $this->templating->renderResponse( 'MauticApiBundle:SubscribedEvents\Search:global.html.php', - array( + [ 'showMore' => true, 'searchString' => $str, - 'remaining' => (count($clients) - 5) - ) + 'remaining' => (count($clients) - 5), + ] )->getContent(); } $clientResults['count'] = count($clients); @@ -97,7 +96,7 @@ public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event) */ public function onBuildCommandList(MauticEvents\CommandListEvent $event) { - $security = $this->security; + $security = $this->security; if ($security->isGranted('api:clients:view')) { $event->addCommands( 'mautic.api.client.header.index', @@ -105,4 +104,4 @@ public function onBuildCommandList(MauticEvents\CommandListEvent $event) ); } } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/Form/Type/ClientType.php b/app/bundles/ApiBundle/Form/Type/ClientType.php index 4a10e0b92d6..17e46d7efda 100644 --- a/app/bundles/ApiBundle/Form/Type/ClientType.php +++ b/app/bundles/ApiBundle/Form/Type/ClientType.php @@ -1,9 +1,10 @@ add( 'api_mode', 'choice', - array( - 'mapped' => false, - 'label' => 'mautic.api.client.form.auth_protocol', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + [ + 'mapped' => false, + 'label' => 'mautic.api.client.form.auth_protocol', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', - 'onchange' => 'Mautic.refreshApiClientForm(\'' . $this->router->generate('mautic_client_action', array('objectAction' => 'new')) . '\', this)' - ), - 'choices' => array( + 'onchange' => 'Mautic.refreshApiClientForm(\''.$this->router->generate('mautic_client_action', ['objectAction' => 'new']).'\', this)', + ], + 'choices' => [ 'oauth1a' => 'OAuth 1.0a', - 'oauth2' => 'OAuth 2' - ), + 'oauth2' => 'OAuth 2', + ], 'required' => false, 'empty_value' => false, - 'data' => $this->apiMode - ) + 'data' => $this->apiMode, + ] ); } $builder->add( 'name', 'text', - array( + [ 'label' => 'mautic.core.name', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array('class' => 'form-control') - ) + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + ] ); if ($this->apiMode == 'oauth2') { @@ -106,14 +105,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->create( 'redirectUris', 'text', - array( + [ 'label' => 'mautic.api.client.redirecturis', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', 'tooltip' => 'mautic.api.client.form.help.requesturis', - ) - ) + ], + ] ) ->addViewTransformer($arrayStringTransformer) ); @@ -121,27 +120,27 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publicId', 'text', - array( + [ 'label' => 'mautic.api.client.form.clientid', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array('class' => 'form-control'), + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], 'disabled' => true, 'required' => false, 'mapped' => false, - 'data' => $options['data']->getPublicId() - ) + 'data' => $options['data']->getPublicId(), + ] ); $builder->add( 'secret', 'text', - array( + [ 'label' => 'mautic.api.client.form.clientsecret', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array('class' => 'form-control'), + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], 'disabled' => true, - 'required' => false - ) + 'required' => false, + ] ); $translator = $this->translator; @@ -155,10 +154,10 @@ function (FormEvent $event) use ($translator, $validator) { if ($form->has('redirectUris')) { foreach ($data->getRedirectUris() as $uri) { - $urlConstraint = new OAuthCallback(); + $urlConstraint = new OAuthCallback(); $urlConstraint->message = $translator->trans( 'mautic.api.client.redirecturl.invalid', - array('%url%' => $uri), + ['%url%' => $uri], 'validators' ); @@ -181,48 +180,48 @@ function (FormEvent $event) use ($translator, $validator) { $builder->create( 'callback', 'text', - array( + [ 'label' => 'mautic.api.client.form.callback', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', 'tooltip' => 'mautic.api.client.form.help.callback', - ), - 'required' => false - ) + ], + 'required' => false, + ] )->addModelTransformer(new Transformers\NullToEmptyTransformer()) ); $builder->add( 'consumerKey', 'text', - array( + [ 'label' => 'mautic.api.client.form.consumerkey', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', - 'onclick' => 'this.setSelectionRange(0, this.value.length);' - ), - 'read_only' => true, - 'required' => false, - 'mapped' => false, - 'data' => $options['data']->getConsumerKey() - ) + 'onclick' => 'this.setSelectionRange(0, this.value.length);', + ], + 'read_only' => true, + 'required' => false, + 'mapped' => false, + 'data' => $options['data']->getConsumerKey(), + ] ); $builder->add( 'consumerSecret', 'text', - array( + [ 'label' => 'mautic.api.client.form.consumersecret', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', - 'onclick' => 'this.setSelectionRange(0, this.value.length);' - ), - 'read_only' => true, - 'required' => false - ) + 'onclick' => 'this.setSelectionRange(0, this.value.length);', + ], + 'read_only' => true, + 'required' => false, + ] ); $translator = $this->translator; @@ -235,9 +234,9 @@ function (FormEvent $event) use ($translator, $validator) { $data = $event->getData(); if ($form->has('callback')) { - $uri = $data->getCallback(); - $urlConstraint = new OAuthCallback(); - $urlConstraint->message = $translator->trans('mautic.api.client.redirecturl.invalid', array('%url%' => $uri), 'validators'); + $uri = $data->getCallback(); + $urlConstraint = new OAuthCallback(); + $urlConstraint->message = $translator->trans('mautic.api.client.redirecturl.invalid', ['%url%' => $uri], 'validators'); $errors = $validator->validateValue( $uri, @@ -256,8 +255,8 @@ function (FormEvent $event) use ($translator, $validator) { $builder->add('buttons', 'form_buttons'); - if (!empty($options["action"])) { - $builder->setAction($options["action"]); + if (!empty($options['action'])) { + $builder->setAction($options['action']); } } @@ -268,9 +267,9 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) { $dataClass = ($this->apiMode == 'oauth2') ? 'Mautic\ApiBundle\Entity\oAuth2\Client' : 'Mautic\ApiBundle\Entity\oAuth1\Consumer'; $resolver->setDefaults( - array( - 'data_class' => $dataClass - ) + [ + 'data_class' => $dataClass, + ] ); } @@ -279,6 +278,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) */ public function getName() { - return "client"; + return 'client'; } } diff --git a/app/bundles/ApiBundle/Form/Type/ConfigType.php b/app/bundles/ApiBundle/Form/Type/ConfigType.php index 8a01f75b62a..aa8e61e6925 100644 --- a/app/bundles/ApiBundle/Form/Type/ConfigType.php +++ b/app/bundles/ApiBundle/Form/Type/ConfigType.php @@ -1,23 +1,21 @@ add( 'api_enabled', 'yesno_button_group', - array( + [ 'label' => 'mautic.api.config.form.api.enabled', 'data' => (bool) $options['data']['api_enabled'], - 'attr' => array( - 'tooltip' => 'mautic.api.config.form.api.enabled.tooltip' - ) - ) + 'attr' => [ + 'tooltip' => 'mautic.api.config.form.api.enabled.tooltip', + ], + ] ); $builder->add( 'api_oauth2_access_token_lifetime', 'number', - array( - 'label' => 'mautic.api.config.form.api.oauth2_access_token_lifetime', - 'attr' => array( + [ + 'label' => 'mautic.api.config.form.api.oauth2_access_token_lifetime', + 'attr' => [ 'tooltip' => 'mautic.api.config.form.api.oauth2_access_token_lifetime.tooltip', 'class' => 'form-control', 'data-show-on' => '{"config_apiconfig_api_enabled_1":"checked"}', - ), - 'constraints' => array( + ], + 'constraints' => [ new NotBlank( - array( - 'message' => 'mautic.core.value.required' - ) - ) - ) - ) + [ + 'message' => 'mautic.core.value.required', + ] + ), + ], + ] ); $builder->add( 'api_oauth2_refresh_token_lifetime', 'number', - array( - 'label' => 'mautic.api.config.form.api.oauth2_refresh_token_lifetime', - 'attr' => array( + [ + 'label' => 'mautic.api.config.form.api.oauth2_refresh_token_lifetime', + 'attr' => [ 'tooltip' => 'mautic.api.config.form.api.oauth2_refresh_token_lifetime.tooltip', 'class' => 'form-control', 'data-show-on' => '{"config_apiconfig_api_enabled_1":"checked"}', - ), - 'constraints' => array( + ], + 'constraints' => [ new NotBlank( - array( - 'message' => 'mautic.core.value.required' - ) - ) - ) - ) + [ + 'message' => 'mautic.core.value.required', + ] + ), + ], + ] ); } @@ -87,4 +85,4 @@ public function getName() { return 'apiconfig'; } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/Form/Validator/Constraints/OAuthCallback.php b/app/bundles/ApiBundle/Form/Validator/Constraints/OAuthCallback.php index ae36a55a1e3..44b50b21e3d 100644 --- a/app/bundles/ApiBundle/Form/Validator/Constraints/OAuthCallback.php +++ b/app/bundles/ApiBundle/Form/Validator/Constraints/OAuthCallback.php @@ -1,9 +1,10 @@ addViolation(); } } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/MauticApiBundle.php b/app/bundles/ApiBundle/MauticApiBundle.php index 0fd96c5163b..9a9600b4504 100644 --- a/app/bundles/ApiBundle/MauticApiBundle.php +++ b/app/bundles/ApiBundle/MauticApiBundle.php @@ -1,9 +1,10 @@ $action) : array(); + $params = (!empty($action)) ? ['action' => $action] : []; + return $formFactory->create('client', $entity, $params); } @@ -117,7 +118,6 @@ public function getEntity($id = null) return parent::getEntity($id); } - /** * {@inheritdoc} * @@ -126,14 +126,14 @@ public function getEntity($id = null) protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null) { if (!$entity instanceof Client && !$entity instanceof Consumer) { - throw new MethodNotAllowedHttpException(array('Client', 'Consumer')); + throw new MethodNotAllowedHttpException(['Client', 'Consumer']); } switch ($action) { - case "post_save": + case 'post_save': $name = ApiEvents::CLIENT_POST_SAVE; break; - case "post_delete": + case 'post_delete': $name = ApiEvents::CLIENT_POST_DELETE; break; default: @@ -146,6 +146,7 @@ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event $event->setEntityManager($this->em); } $this->dispatcher->dispatch($name, $event); + return $event; } @@ -164,13 +165,11 @@ public function getUserClients(User $user) /** * @param $entity - * - * @return void */ public function revokeAccess($entity) { if (!$entity instanceof Client && !$entity instanceof Consumer) { - throw new MethodNotAllowedHttpException(array('Client', 'Consumer')); + throw new MethodNotAllowedHttpException(['Client', 'Consumer']); } //remove the user from the client diff --git a/app/bundles/ApiBundle/Provider/NonceProvider.php b/app/bundles/ApiBundle/Provider/NonceProvider.php index e5032adc877..ab816fc8a06 100644 --- a/app/bundles/ApiBundle/Provider/NonceProvider.php +++ b/app/bundles/ApiBundle/Provider/NonceProvider.php @@ -1,9 +1,10 @@ = $lastFifteen) { //make sure nonce has not been used before - $usedNonces = $this->repo->findBy(array('nonce' => $nonce)); + $usedNonces = $this->repo->findBy(['nonce' => $nonce]); if (count($usedNonces) === 0) { $notUsed = true; @@ -82,11 +82,11 @@ public function checkNonceAndTimestampUnicity($nonce, $timestamp, ConsumerInterf } /** - * @param $nonce - * @param $timestamp - * @param \Bazinga\OAuthServerBundle\Model\ConsumerInterface $consumer + * @param $nonce + * @param $timestamp + * @param \Bazinga\OAuthServerBundle\Model\ConsumerInterface $consumer * - * @return boolean + * @return bool */ public function registerNonceAndTimestamp($nonce, $timestamp, ConsumerInterface $consumer) { diff --git a/app/bundles/ApiBundle/Security/OAuth1/Authentication/Provider/OAuthProvider.php b/app/bundles/ApiBundle/Security/OAuth1/Authentication/Provider/OAuthProvider.php index 27d817da42b..44e2abb1e85 100644 --- a/app/bundles/ApiBundle/Security/OAuth1/Authentication/Provider/OAuthProvider.php +++ b/app/bundles/ApiBundle/Security/OAuth1/Authentication/Provider/OAuthProvider.php @@ -1,9 +1,10 @@ permissions = array( - 'access' => array( - 'full' => 1024 - ) - ); + $this->permissions = [ + 'access' => [ + 'full' => 1024, + ], + ]; $this->addStandardPermissions('clients', false); } @@ -47,15 +46,15 @@ public function getName() */ public function buildForm(FormBuilderInterface &$builder, array $options, array $data) { - $builder->add('api:access', 'permissionlist', array( - 'choices' => array( - 'full' => 'mautic.api.permissions.granted', - ), - 'label' => 'mautic.api.permissions.apiaccess', - 'data' => (!empty($data['access']) ? $data['access'] : array()), - 'bundle' => 'api', - 'level' => 'access' - )); + $builder->add('api:access', 'permissionlist', [ + 'choices' => [ + 'full' => 'mautic.api.permissions.granted', + ], + 'label' => 'mautic.api.permissions.apiaccess', + 'data' => (!empty($data['access']) ? $data['access'] : []), + 'bundle' => 'api', + 'level' => 'access', + ]); $this->addStandardFormFields('api', 'clients', $builder, $data, false); } @@ -87,7 +86,7 @@ public function isEnabled() protected function getSynonym($name, $level) { if ($name == 'access' && $level == 'granted') { - return array($name, 'full'); + return [$name, 'full']; } return parent::getSynonym($name, $level); diff --git a/app/bundles/ApiBundle/Serializer/Driver/AnnotationDriver.php b/app/bundles/ApiBundle/Serializer/Driver/AnnotationDriver.php index a8616945960..db8e22012cf 100644 --- a/app/bundles/ApiBundle/Serializer/Driver/AnnotationDriver.php +++ b/app/bundles/ApiBundle/Serializer/Driver/AnnotationDriver.php @@ -1,9 +1,10 @@ hasMethod('loadApiMetadata')) { - $this->metadata = new ClassMetadata($class->getName()); + $this->metadata = new ClassMetadata($class->getName()); - $this->properties = array(); + $this->properties = []; $this->defaultVersion = '1.0'; $this->groupPrefix = ''; @@ -66,7 +67,7 @@ protected function loadMetadataFromFile(\ReflectionClass $class, $file) } /** - * Set the root (base key) + * Set the root (base key). * * @param $root * @@ -80,7 +81,7 @@ public function setRoot($root) } /** - * Set prefix for the List and Details groups + * Set prefix for the List and Details groups. * * @param $name * @@ -94,7 +95,7 @@ public function setGroupPrefix($name) } /** - * Set the default version for the properties if different than 1.0 + * Set the default version for the properties if different than 1.0. * * @param $version * @@ -108,7 +109,7 @@ public function setDefaultVersion($version) } /** - * Create a new property + * Create a new property. * * @param $name * @@ -123,7 +124,7 @@ public function createProperty($name) } /** - * Add property and set default version and Details group + * Add property and set default version and Details group. * * @param $name * @@ -140,14 +141,14 @@ public function addProperty($name) if ($this->groupPrefix !== null) { // Auto add to the Details group - $this->addGroup($this->groupPrefix . 'Details'); + $this->addGroup($this->groupPrefix.'Details'); } return $this; } /** - * Create properties + * Create properties. * * @param array $properties * @param bool|false $addToListGroup @@ -168,7 +169,7 @@ public function addProperties(array $properties, $addToListGroup = false) } /** - * Create properties and add to the List group + * Create properties and add to the List group. * * @param array $properties * @@ -233,17 +234,17 @@ public function setSerializedName($name, $property = null) } /** - * Set the groups a property belongs to + * Set the groups a property belongs to. * - * @param $groups - * @param $property + * @param $groups + * @param $property * * @return $this */ public function setGroups($groups, $property = null) { if (!is_array($groups)) { - $groups = array($groups); + $groups = [$groups]; } if ($property === null) { @@ -256,7 +257,7 @@ public function setGroups($groups, $property = null) } /** - * Add a group the property belongs to + * Add a group the property belongs to. * * @param $group * @param null $property @@ -275,7 +276,7 @@ public function addGroup($group, $property = null) } /** - * Add property to the List group + * Add property to the List group. * * @return $this */ @@ -288,7 +289,7 @@ public function inListGroup() } /** - * Set max depth for the property if an association + * Set max depth for the property if an association. * * @param $depth * @param null $property @@ -307,7 +308,7 @@ public function setMaxDepth($depth, $property = null) } /** - * Push the properties into ClassMetadata + * Push the properties into ClassMetadata. */ public function build() { @@ -316,6 +317,6 @@ public function build() } $this->currentPropertyName = null; - $this->properties = array(); + $this->properties = []; } -} \ No newline at end of file +} diff --git a/app/bundles/ApiBundle/Serializer/Exclusion/PublishDetailsExclusionStrategy.php b/app/bundles/ApiBundle/Serializer/Exclusion/PublishDetailsExclusionStrategy.php index 4ec4a0f9b28..9bbc4151df1 100644 --- a/app/bundles/ApiBundle/Serializer/Exclusion/PublishDetailsExclusionStrategy.php +++ b/app/bundles/ApiBundle/Serializer/Exclusion/PublishDetailsExclusionStrategy.php @@ -1,47 +1,47 @@ fields = array( + $this->fields = [ 'isPublished', 'dateAdded', 'createdBy', 'dateModified', 'modifiedBy', 'checkedOut', - 'checkedOutBy' - ); + 'checkedOutBy', + ]; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext) { @@ -49,7 +49,7 @@ public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorConte } /** - * {@inheritDoc} + * {@inheritdoc} */ public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext) { diff --git a/app/bundles/ApiBundle/Views/Authorize/oAuth1/authorize.html.php b/app/bundles/ApiBundle/Views/Authorize/oAuth1/authorize.html.php index 51e4196edb4..c1ff0fbb64d 100644 --- a/app/bundles/ApiBundle/Views/Authorize/oAuth1/authorize.html.php +++ b/app/bundles/ApiBundle/Views/Authorize/oAuth1/authorize.html.php @@ -1,16 +1,16 @@ extend('MauticUserBundle:Security:base.html.php'); $view['slots']->set('header', $view['translator']->trans('mautic.api.oauth.header')); $name = $consumer->getName(); -$msg = (!empty($name)) ? $view['translator']->trans('mautic.api.oauth.clientwithname', array('%name%' => $name)) : +$msg = (!empty($name)) ? $view['translator']->trans('mautic.api.oauth.clientwithname', ['%name%' => $name]) : $view['translator']->trans('mautic.api.oauth.clientnoname'); ?>

diff --git a/app/bundles/ApiBundle/Views/Authorize/oAuth2/authorize.html.php b/app/bundles/ApiBundle/Views/Authorize/oAuth2/authorize.html.php index 62dce422659..a810edf46d2 100644 --- a/app/bundles/ApiBundle/Views/Authorize/oAuth2/authorize.html.php +++ b/app/bundles/ApiBundle/Views/Authorize/oAuth2/authorize.html.php @@ -1,16 +1,16 @@ extend('MauticUserBundle:Security:base.html.php'); $view['slots']->set('header', $view['translator']->trans('mautic.api.oauth.header')); $name = $client->getName(); -$msg = (!empty($name)) ? $view['translator']->trans('mautic.api.oauth.clientwithname', array('%name%' => $name)) : +$msg = (!empty($name)) ? $view['translator']->trans('mautic.api.oauth.clientwithname', ['%name%' => $name]) : $view['translator']->trans('mautic.api.oauth.clientnoname'); ?>

diff --git a/app/bundles/ApiBundle/Views/Client/authorized.html.php b/app/bundles/ApiBundle/Views/Client/authorized.html.php index 7a2aa2b838d..f97a858fa30 100644 --- a/app/bundles/ApiBundle/Views/Client/authorized.html.php +++ b/app/bundles/ApiBundle/Views/Client/authorized.html.php @@ -1,9 +1,10 @@ @@ -19,14 +20,14 @@ render('MauticCoreBundle:Helper:confirm.html.php', - array( + [ 'btnClass' => 'btn btn-danger btn-xs', - 'message' => $view["translator"]->trans("mautic.api.client.form.confirmrevoke", array("%name%" => $k->getName())), - 'confirmText' => $view["translator"]->trans("mautic.api.client.form.revoke"), - 'confirmAction' => $view['router']->path('mautic_client_action',array("objectAction" => "revoke", "objectId" => $k->getId())), + 'message' => $view['translator']->trans('mautic.api.client.form.confirmrevoke', ['%name%' => $k->getName()]), + 'confirmText' => $view['translator']->trans('mautic.api.client.form.revoke'), + 'confirmAction' => $view['router']->path('mautic_client_action', ['objectAction' => 'revoke', 'objectId' => $k->getId()]), 'iconClass' => 'fa fa-trash-o', - 'btnText' => $view["translator"]->trans("mautic.api.client.form.revoke") - ) + 'btnText' => $view['translator']->trans('mautic.api.client.form.revoke'), + ] ); ?> getName(); ?> diff --git a/app/bundles/ApiBundle/Views/Client/form.html.php b/app/bundles/ApiBundle/Views/Client/form.html.php index fc6e224185a..3b4c02d900f 100644 --- a/app/bundles/ApiBundle/Views/Client/form.html.php +++ b/app/bundles/ApiBundle/Views/Client/form.html.php @@ -1,22 +1,22 @@ extend('MauticCoreBundle:Default:content.html.php'); $view['slots']->set('mauticContent', 'client'); $id = $form->vars['data']->getId(); if (!empty($id)) { $name = $form->vars['data']->getName(); - $header = $view['translator']->trans('mautic.api.client.header.edit', array("%name%" => $name)); + $header = $view['translator']->trans('mautic.api.client.header.edit', ['%name%' => $name]); } else { $header = $view['translator']->trans('mautic.api.client.header.new'); } -$view['slots']->set("headerTitle", $header); +$view['slots']->set('headerTitle', $header); ?>
diff --git a/app/bundles/ApiBundle/Views/Client/index.html.php b/app/bundles/ApiBundle/Views/Client/index.html.php index f437a6ddc6e..f4c3eec8061 100644 --- a/app/bundles/ApiBundle/Views/Client/index.html.php +++ b/app/bundles/ApiBundle/Views/Client/index.html.php @@ -1,34 +1,34 @@ extend('MauticCoreBundle:Default:content.html.php'); $view['slots']->set('mauticContent', 'client'); -$view['slots']->set("headerTitle", $view['translator']->trans('mautic.api.client.header.index')); +$view['slots']->set('headerTitle', $view['translator']->trans('mautic.api.client.header.index')); -$view['slots']->set('actions', $view->render('MauticCoreBundle:Helper:page_actions.html.php', array( - 'templateButtons' => array( - 'new' => $permissions['create'] - ), +$view['slots']->set('actions', $view->render('MauticCoreBundle:Helper:page_actions.html.php', [ + 'templateButtons' => [ + 'new' => $permissions['create'], + ], 'routeBase' => 'client', - 'langVar' => 'api.client' -))); + 'langVar' => 'api.client', +])); ?>
- render('MauticCoreBundle:Helper:list_toolbar.html.php', array( - 'searchValue' => $searchValue, - 'searchHelp' => 'mautic.api.client.help.searchcommands', - 'action' => $currentRoute, - 'routeBase' => 'client', - 'templateButtons' => array(), - 'filters' => $filters - )); ?> + render('MauticCoreBundle:Helper:list_toolbar.html.php', [ + 'searchValue' => $searchValue, + 'searchHelp' => 'mautic.api.client.help.searchcommands', + 'action' => $currentRoute, + 'routeBase' => 'client', + 'templateButtons' => [], + 'filters' => $filters, + ]); ?>
output('_content'); ?>
diff --git a/app/bundles/ApiBundle/Views/Client/list.html.php b/app/bundles/ApiBundle/Views/Client/list.html.php index 62f8be5ec3c..a96d465a33e 100644 --- a/app/bundles/ApiBundle/Views/Client/list.html.php +++ b/app/bundles/ApiBundle/Views/Client/list.html.php @@ -1,9 +1,10 @@ render('MauticCoreBundle:Helper:tableheader.html.php', array( + echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'checkall' => 'true', - 'target' => '.client-list' - )); + 'target' => '.client-list', + ]); - echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', array( + echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'sessionVar' => 'client', 'orderBy' => 'c.name', 'text' => 'mautic.core.name', 'default' => true, - 'class' => 'col-client-name' - )); + 'class' => 'col-client-name', + ]); ?> trans('mautic.api.client.thead.publicid'); ?> trans('mautic.api.client.thead.secret'); ?> render('MauticCoreBundle:Helper:tableheader.html.php', array( + echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'sessionVar' => 'client', 'orderBy' => 'c.id', 'text' => 'mautic.core.id', - 'class' => 'visible-md visible-lg col-client-id' - )); + 'class' => 'visible-md visible-lg col-client-id', + ]); ?> @@ -47,16 +48,16 @@ render('MauticCoreBundle:Helper:list_actions.html.php', array( - 'item' => $item, - 'templateButtons' => array( - 'edit' => $permissions['edit'], - 'delete' => $permissions['delete'] - ), + echo $view->render('MauticCoreBundle:Helper:list_actions.html.php', [ + 'item' => $item, + 'templateButtons' => [ + 'edit' => $permissions['edit'], + 'delete' => $permissions['delete'], + ], 'routeBase' => 'client', 'langVar' => 'api.client', - 'pull' => 'left' - )); + 'pull' => 'left', + ]); ?> @@ -74,13 +75,13 @@
\ No newline at end of file diff --git a/app/bundles/ApiBundle/Views/FormTheme/Config/_config_apiconfig_widget.html.php b/app/bundles/ApiBundle/Views/FormTheme/Config/_config_apiconfig_widget.html.php index f607c5c5c6f..a998f1b8439 100644 --- a/app/bundles/ApiBundle/Views/FormTheme/Config/_config_apiconfig_widget.html.php +++ b/app/bundles/ApiBundle/Views/FormTheme/Config/_config_apiconfig_widget.html.php @@ -1,9 +1,10 @@ diff --git a/app/bundles/ApiBundle/Views/Security/login.html.php b/app/bundles/ApiBundle/Views/Security/login.html.php index f0e9ccbdef3..988789b8531 100644 --- a/app/bundles/ApiBundle/Views/Security/login.html.php +++ b/app/bundles/ApiBundle/Views/Security/login.html.php @@ -1,12 +1,12 @@ extend('MauticUserBundle:Security:base.html.php'); $view['slots']->set('header', $view['translator']->trans('mautic.api.oauth.header')); ?> diff --git a/app/bundles/ApiBundle/Views/SubscribedEvents/Search/global.html.php b/app/bundles/ApiBundle/Views/SubscribedEvents/Search/global.html.php index 6a2c090ff0e..cfb72d35ef0 100644 --- a/app/bundles/ApiBundle/Views/SubscribedEvents/Search/global.html.php +++ b/app/bundles/ApiBundle/Views/SubscribedEvents/Search/global.html.php @@ -1,21 +1,22 @@ - - trans('mautic.core.search.more', array("%count%" => $remaining)); ?> + + trans('mautic.core.search.more', ['%count%' => $remaining]); ?> - - getName();?> + + getName(); ?> getName(); ?> diff --git a/app/bundles/AssetBundle/AssetEvents.php b/app/bundles/AssetBundle/AssetEvents.php index ae399a91adf..017e18666ce 100644 --- a/app/bundles/AssetBundle/AssetEvents.php +++ b/app/bundles/AssetBundle/AssetEvents.php @@ -1,9 +1,10 @@ [ 'main' => [ 'mautic_asset_buildertoken_index' => [ - 'path' => '/asset/buildertokens/{page}', - 'controller' => 'MauticAssetBundle:SubscribedEvents\BuilderToken:index' + 'path' => '/asset/buildertokens/{page}', + 'controller' => 'MauticAssetBundle:SubscribedEvents\BuilderToken:index', ], 'mautic_asset_index' => [ - 'path' => '/assets/{page}', - 'controller' => 'MauticAssetBundle:Asset:index' + 'path' => '/assets/{page}', + 'controller' => 'MauticAssetBundle:Asset:index', ], 'mautic_asset_remote' => [ - 'path' => '/assets/remote', + 'path' => '/assets/remote', 'controller' => 'MauticAssetBundle:Asset:remote', ], 'mautic_asset_action' => [ - 'path' => '/assets/{objectAction}/{objectId}', + 'path' => '/assets/{objectAction}/{objectId}', 'controller' => 'MauticAssetBundle:Asset:execute', - ] + ], ], 'api' => [ 'mautic_api_getassets' => [ - 'path' => '/assets', - 'controller' => 'MauticAssetBundle:Api\AssetApi:getEntities' + 'path' => '/assets', + 'controller' => 'MauticAssetBundle:Api\AssetApi:getEntities', ], 'mautic_api_getasset' => [ - 'path' => '/assets/{id}', - 'controller' => 'MauticAssetBundle:Api\AssetApi:getEntity' - ] + 'path' => '/assets/{id}', + 'controller' => 'MauticAssetBundle:Api\AssetApi:getEntity', + ], ], 'public' => [ 'mautic_asset_download' => [ - 'path' => '/asset/{slug}', + 'path' => '/asset/{slug}', 'controller' => 'MauticAssetBundle:Public:download', - 'defaults' => [ - "slug" => '' - ] - ] - ] + 'defaults' => [ + 'slug' => '', + ], + ], + ], ], 'menu' => [ 'main' => [ - 'items' => [ + 'items' => [ 'mautic.asset.assets' => [ - 'route' => 'mautic_asset_index', - 'access' => ['asset:assets:viewown', 'asset:assets:viewother'], - 'parent' => 'mautic.core.components', - 'priority' => 300, - ] - ] - ] + 'route' => 'mautic_asset_index', + 'access' => ['asset:assets:viewown', 'asset:assets:viewother'], + 'parent' => 'mautic.core.components', + 'priority' => 300, + ], + ], + ], ], 'categories' => [ - 'asset' => null + 'asset' => null, ], 'services' => [ 'events' => [ 'mautic.asset.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\AssetSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\AssetSubscriber', 'arguments' => [ 'mautic.helper.ip_lookup', - 'mautic.core.model.auditlog' - ] + 'mautic.core.model.auditlog', + ], ], 'mautic.asset.pointbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\PointSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\PointSubscriber', 'arguments' => [ - 'mautic.point.model.point' - ] + 'mautic.point.model.point', + ], ], 'mautic.asset.formbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\FormSubscriber' + 'class' => 'Mautic\AssetBundle\EventListener\FormSubscriber', ], 'mautic.asset.campaignbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\CampaignSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\CampaignSubscriber', 'arguments' => [ - 'mautic.campaign.model.event' - ] + 'mautic.campaign.model.event', + ], ], 'mautic.asset.reportbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\ReportSubscriber' + 'class' => 'Mautic\AssetBundle\EventListener\ReportSubscriber', ], 'mautic.asset.builder.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\BuilderSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\BuilderSubscriber', 'arguments' => [ 'mautic.asset.helper.token', - 'mautic.lead.model.lead' - ] + 'mautic.lead.model.lead', + ], ], 'mautic.asset.leadbundle.subscriber' => [ 'class' => 'Mautic\AssetBundle\EventListener\LeadSubscriber', 'arguments' => [ - 'mautic.asset.model.asset' - ] + 'mautic.asset.model.asset', + ], ], 'mautic.asset.pagebundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\PageSubscriber' + 'class' => 'Mautic\AssetBundle\EventListener\PageSubscriber', ], 'mautic.asset.emailbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\EmailSubscriber' + 'class' => 'Mautic\AssetBundle\EventListener\EmailSubscriber', ], 'mautic.asset.configbundle.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\ConfigSubscriber' + 'class' => 'Mautic\AssetBundle\EventListener\ConfigSubscriber', ], 'mautic.asset.search.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\SearchSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\SearchSubscriber', 'arguments' => [ - 'mautic.asset.model.asset' - ] + 'mautic.asset.model.asset', + ], ], 'oneup_uploader.pre_upload' => [ - 'class' => 'Mautic\AssetBundle\EventListener\UploadSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\UploadSubscriber', 'arguments' => [ 'translator', 'mautic.helper.core_parameters', - 'mautic.asset.model.asset' - ] + 'mautic.asset.model.asset', + ], ], 'mautic.asset.dashboard.subscriber' => [ - 'class' => 'Mautic\AssetBundle\EventListener\DashboardSubscriber', + 'class' => 'Mautic\AssetBundle\EventListener\DashboardSubscriber', 'arguments' => [ - 'mautic.asset.model.asset' - ] - ] + 'mautic.asset.model.asset', + ], + ], ], 'forms' => [ 'mautic.form.type.asset' => [ - 'class' => 'Mautic\AssetBundle\Form\Type\AssetType', + 'class' => 'Mautic\AssetBundle\Form\Type\AssetType', 'arguments' => [ 'translator', 'mautic.helper.theme', - 'mautic.asset.model.asset' + 'mautic.asset.model.asset', ], - 'alias' => 'asset' + 'alias' => 'asset', ], 'mautic.form.type.pointaction_assetdownload' => [ 'class' => 'Mautic\AssetBundle\Form\Type\PointActionAssetDownloadType', - 'alias' => 'pointaction_assetdownload' + 'alias' => 'pointaction_assetdownload', ], 'mautic.form.type.campaignevent_assetdownload' => [ 'class' => 'Mautic\AssetBundle\Form\Type\CampaignEventAssetDownloadType', - 'alias' => 'campaignevent_assetdownload' + 'alias' => 'campaignevent_assetdownload', ], 'mautic.form.type.formsubmit_assetdownload' => [ 'class' => 'Mautic\AssetBundle\Form\Type\FormSubmitActionDownloadFileType', - 'alias' => 'asset_submitaction_downloadfile' + 'alias' => 'asset_submitaction_downloadfile', ], 'mautic.form.type.assetlist' => [ - 'class' => 'Mautic\AssetBundle\Form\Type\AssetListType', + 'class' => 'Mautic\AssetBundle\Form\Type\AssetListType', 'arguments' => 'mautic.factory', - 'alias' => 'asset_list' + 'alias' => 'asset_list', ], 'mautic.form.type.assetconfig' => [ - 'class' => 'Mautic\AssetBundle\Form\Type\ConfigType', + 'class' => 'Mautic\AssetBundle\Form\Type\ConfigType', 'arguments' => 'mautic.factory', - 'alias' => 'assetconfig' + 'alias' => 'assetconfig', ], 'mautic.form.type.asset_dashboard_downloads_in_time_widget' => [ - 'class' => 'Mautic\AssetBundle\Form\Type\DashboardDownloadsInTimeWidgetType', - 'alias' => 'asset_dashboard_downloads_in_time_widget' - ] + 'class' => 'Mautic\AssetBundle\Form\Type\DashboardDownloadsInTimeWidgetType', + 'alias' => 'asset_dashboard_downloads_in_time_widget', + ], ], 'others' => [ 'mautic.asset.upload.error.handler' => [ - 'class' => 'Mautic\AssetBundle\ErrorHandler\DropzoneErrorHandler', - 'arguments' => 'mautic.factory' + 'class' => 'Mautic\AssetBundle\ErrorHandler\DropzoneErrorHandler', + 'arguments' => 'mautic.factory', ], // Override the DropzoneController 'oneup_uploader.controller.dropzone.class' => 'Mautic\AssetBundle\Controller\UploadController', - 'mautic.asset.helper.token' => [ + 'mautic.asset.helper.token' => [ 'class' => 'Mautic\AssetBundle\Helper\TokenHelper', - 'arguments' => 'mautic.asset.model.asset' - ] + 'arguments' => 'mautic.asset.model.asset', + ], ], - 'models' => [ + 'models' => [ 'mautic.asset.model.asset' => [ - 'class' => 'Mautic\AssetBundle\Model\AssetModel', + 'class' => 'Mautic\AssetBundle\Model\AssetModel', 'arguments' => [ 'mautic.lead.model.lead', 'mautic.category.model.category', 'request_stack', 'mautic.helper.ip_lookup', - 'mautic.helper.core_parameters' - ] - ] - ] + 'mautic.helper.core_parameters', + ], + ], + ], ], 'parameters' => [ - 'upload_dir' => '%kernel.root_dir%/../media/files', - 'max_size' => '6', - 'allowed_extensions' => ['csv', 'doc', 'docx', 'epub', 'gif', 'jpg', 'jpeg', 'mpg', 'mpeg', 'mp3', 'odt', 'odp', 'ods', 'pdf', 'png', 'ppt', 'pptx', 'tif', 'tiff', 'txt', 'xls', 'xlsx', 'wav'] - ] + 'upload_dir' => '%kernel.root_dir%/../media/files', + 'max_size' => '6', + 'allowed_extensions' => ['csv', 'doc', 'docx', 'epub', 'gif', 'jpg', 'jpeg', 'mpg', 'mpeg', 'mp3', 'odt', 'odp', 'ods', 'pdf', 'png', 'ppt', 'pptx', 'tif', 'tiff', 'txt', 'xls', 'xlsx', 'wav'], + ], ]; diff --git a/app/bundles/AssetBundle/Controller/AjaxController.php b/app/bundles/AssetBundle/Controller/AjaxController.php index cddc894b8d3..17e80b93159 100644 --- a/app/bundles/AssetBundle/Controller/AjaxController.php +++ b/app/bundles/AssetBundle/Controller/AjaxController.php @@ -1,9 +1,10 @@ query->get('filter')); $results = $this->getModel('asset')->getLookupResults('category', $filter, 10); - $dataArray = array(); + $dataArray = []; foreach ($results as $r) { - $dataArray[] = array( - "label" => $r['title'] . " ({$r['id']})", - "value" => $r['id'] - ); + $dataArray[] = [ + 'label' => $r['title']." ({$r['id']})", + 'value' => $r['id'], + ]; } + return $this->sendJsonResponse($dataArray); } /** * @param Request $request + * * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function fetchRemoteFilesAction(Request $request) @@ -53,7 +55,7 @@ protected function fetchRemoteFilesAction(Request $request) $name = AssetEvents::ASSET_ON_REMOTE_BROWSE; if (!$dispatcher->hasListeners($name)) { - return $this->sendJsonResponse(array('success' => 0)); + return $this->sendJsonResponse(['success' => 0]); } /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ @@ -67,20 +69,20 @@ protected function fetchRemoteFilesAction(Request $request) $dispatcher->dispatch($name, $event); if (!$adapter = $event->getAdapter()) { - return $this->sendJsonResponse(array('success' => 0)); + return $this->sendJsonResponse(['success' => 0]); } $connector = new Filesystem($adapter); $output = $this->renderView( 'MauticAssetBundle:Remote:list.html.php', - array( - 'connector' => $connector, + [ + 'connector' => $connector, 'integration' => $integration, - 'items' => $connector->listKeys($path) - ) + 'items' => $connector->listKeys($path), + ] ); - return $this->sendJsonResponse(array('success' => 1, 'output' => $output)); + return $this->sendJsonResponse(['success' => 1, 'output' => $output]); } } diff --git a/app/bundles/AssetBundle/Controller/Api/AssetApiController.php b/app/bundles/AssetBundle/Controller/Api/AssetApiController.php index 9425318aced..03da90848c4 100644 --- a/app/bundles/AssetBundle/Controller/Api/AssetApiController.php +++ b/app/bundles/AssetBundle/Controller/Api/AssetApiController.php @@ -1,9 +1,10 @@ model = $this->getModel('asset'); @@ -28,29 +26,29 @@ public function initialize (FilterControllerEvent $event) $this->entityNameOne = 'asset'; $this->entityNameMulti = 'assets'; $this->permissionBase = 'asset:assets'; - $this->serializerGroups = array("assetDetails", "categoryList", "publishDetails"); + $this->serializerGroups = ['assetDetails', 'categoryList', 'publishDetails']; } /** - * Obtains a list of assets + * Obtains a list of assets. * * @return \Symfony\Component\HttpFoundation\Response */ - public function getEntitiesAction () + public function getEntitiesAction() { if (!$this->security->isGranted('asset:assets:viewother')) { - $this->listFilters[] = array( + $this->listFilters[] = [ 'column' => 'a.createdBy', 'expr' => 'eq', - 'value' => $this->user->getId() - ); + 'value' => $this->user->getId(), + ]; } return parent::getEntitiesAction(); } /** - * Gives child controllers opportunity to analyze and do whatever to an entity before going through serializer + * Gives child controllers opportunity to analyze and do whatever to an entity before going through serializer. * * @param $entity * @param string $action diff --git a/app/bundles/AssetBundle/Controller/AssetController.php b/app/bundles/AssetBundle/Controller/AssetController.php index 02c6d4bc091..0e2a968be1e 100644 --- a/app/bundles/AssetBundle/Controller/AssetController.php +++ b/app/bundles/AssetBundle/Controller/AssetController.php @@ -1,9 +1,10 @@ getModel('asset'); @@ -39,8 +38,8 @@ public function indexAction ($page = 1) 'asset:assets:deleteown', 'asset:assets:deleteother', 'asset:assets:publishown', - 'asset:assets:publishother' - ], "RETURN_ARRAY"); + 'asset:assets:publishother', + ], 'RETURN_ARRAY'); if (!$permissions['asset:assets:viewown'] && !$permissions['asset:assets:viewother']) { return $this->accessDenied(); @@ -76,7 +75,7 @@ public function indexAction ($page = 1) 'limit' => $limit, 'filter' => $filter, 'orderBy' => $orderBy, - 'orderByDir' => $orderByDir + 'orderByDir' => $orderByDir, ] ); @@ -97,8 +96,8 @@ public function indexAction ($page = 1) 'contentTemplate' => 'MauticAssetBundle:Asset:index', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]); } @@ -111,7 +110,7 @@ public function indexAction ($page = 1) $categories = $this->getModel('asset')->getLookupResults('category', '', 0); return $this->delegateView([ - 'viewParameters' => [ + 'viewParameters' => [ 'searchValue' => $search, 'items' => $assets, 'categories' => $categories, @@ -120,25 +119,25 @@ public function indexAction ($page = 1) 'model' => $model, 'tmpl' => $tmpl, 'page' => $page, - 'security' => $this->get('mautic.security') + 'security' => $this->get('mautic.security'), ], 'contentTemplate' => 'MauticAssetBundle:Asset:list.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', 'mauticContent' => 'asset', - 'route' => $this->generateUrl('mautic_asset_index', ['page' => $page]) - ] + 'route' => $this->generateUrl('mautic_asset_index', ['page' => $page]), + ], ]); } /** - * Loads a specific form into the detailed panel + * Loads a specific form into the detailed panel. * * @param int $objectId * * @return JsonResponse|\Symfony\Component\HttpFoundation\Response */ - public function viewAction ($objectId) + public function viewAction($objectId) { $model = $this->getModel('asset'); $security = $this->get('mautic.security'); @@ -164,15 +163,15 @@ public function viewAction ($objectId) 'contentTemplate' => 'MauticAssetBundle:Asset:index', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', - 'mauticContent' => 'asset' + 'mauticContent' => 'asset', ], - 'flashes' => [ + 'flashes' => [ [ 'type' => 'error', 'msg' => 'mautic.asset.asset.error.notfound', - 'msgVars' => ['%id%' => $objectId] - ] - ] + 'msgVars' => ['%id%' => $objectId], + ], + ], ]); } elseif (!$this->get('mautic.security')->hasEntityAccess('asset:assets:viewown', 'asset:assets:viewother', $activeAsset->getCreatedBy())) { return $this->accessDenied(); @@ -182,11 +181,11 @@ public function viewAction ($objectId) $logs = $this->getModel('core.auditLog')->getLogForObject('asset', $activeAsset->getId(), $activeAsset->getDateAdded()); return $this->delegateView([ - 'returnUrl' => $action, - 'viewParameters' => [ - 'activeAsset' => $activeAsset, - 'tmpl' => $tmpl, - 'permissions' => $security->isGranted([ + 'returnUrl' => $action, + 'viewParameters' => [ + 'activeAsset' => $activeAsset, + 'tmpl' => $tmpl, + 'permissions' => $security->isGranted([ 'asset:assets:viewown', 'asset:assets:viewother', 'asset:assets:create', @@ -195,9 +194,9 @@ public function viewAction ($objectId) 'asset:assets:deleteown', 'asset:assets:deleteother', 'asset:assets:publishown', - 'asset:assets:publishother' - ], "RETURN_ARRAY"), - 'stats' => [ + 'asset:assets:publishother', + ], 'RETURN_ARRAY'), + 'stats' => [ 'downloads' => [ 'total' => $activeAsset->getDownloadCount(), 'unique' => $activeAsset->getUniqueDownloadCount(), @@ -207,30 +206,30 @@ public function viewAction ($objectId) new \DateTime($dateRangeForm->get('date_to')->getData()), null, ['asset_id' => $activeAsset->getId()] - ) - ] + ), + ], ], 'security' => $security, 'assetDownloadUrl' => $model->generateUrl($activeAsset, true), 'logs' => $logs, - 'dateRangeForm' => $dateRangeForm->createView() + 'dateRangeForm' => $dateRangeForm->createView(), ], - 'contentTemplate' => 'MauticAssetBundle:Asset:' . $tmpl . '.html.php', + 'contentTemplate' => 'MauticAssetBundle:Asset:'.$tmpl.'.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]); } /** - * Show a preview of the file + * Show a preview of the file. * * @param $objectId * * @return JsonResponse|\Symfony\Component\HttpFoundation\Response */ - public function previewAction ($objectId) + public function previewAction($objectId) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $this->getModel('asset'); @@ -241,23 +240,23 @@ public function previewAction ($objectId) } return $this->delegateView([ - 'viewParameters' => [ + 'viewParameters' => [ 'activeAsset' => $activeAsset, - 'assetDownloadUrl' => $model->generateUrl($activeAsset) + 'assetDownloadUrl' => $model->generateUrl($activeAsset), ], 'contentTemplate' => 'MauticAssetBundle:Asset:preview.html.php', 'passthroughVars' => [ - 'route' => false - ] + 'route' => false, + ], ]); } /** - * Generates new form and processes post data + * Generates new form and processes post data. * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function newAction ($entity = null) + public function newAction($entity = null) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $this->getModel('asset'); @@ -266,7 +265,7 @@ public function newAction ($entity = null) if (null == $entity) { $entity = $model->getEntity(); } - $entity->setMaxSize(Asset::convertSizeToBytes($this->get('mautic.helper.core_parameters')->getParameter('max_size') . 'M')); // convert from MB to B + $entity->setMaxSize(Asset::convertSizeToBytes($this->get('mautic.helper.core_parameters')->getParameter('max_size').'M')); // convert from MB to B $method = $this->request->getMethod(); $session = $this->get('session'); @@ -274,16 +273,16 @@ public function newAction ($entity = null) return $this->accessDenied(); } - $maxSize = $model->getMaxUploadSize(); - $extensions = '.' . implode(', .', $this->get('mautic.helper.core_parameters')->getParameter('allowed_extensions')); + $maxSize = $model->getMaxUploadSize(); + $extensions = '.'.implode(', .', $this->get('mautic.helper.core_parameters')->getParameter('allowed_extensions')); $maxSizeError = $this->get('translator')->trans('mautic.asset.asset.error.file.size', [ '%fileSize%' => '{{filesize}}', - '%maxSize%' => '{{maxFilesize}}' + '%maxSize%' => '{{maxFilesize}}', ], 'validators'); $extensionError = $this->get('translator')->trans('mautic.asset.asset.error.file.extension.js', [ - '%extensions%' => $extensions + '%extensions%' => $extensions, ], 'validators'); // Create temporary asset ID @@ -306,7 +305,6 @@ public function newAction ($entity = null) $valid = false; if (!$cancelled = $this->isFormCancelled($form)) { if ($valid = $this->isFormValid($form)) { - $entity->setUploadDir($this->get('mautic.helper.core_parameters')->getParameter('upload_dir')); $entity->preUpload(); $entity->upload(); @@ -322,8 +320,8 @@ public function newAction ($entity = null) '%menu_link%' => 'mautic_asset_index', '%url%' => $this->generateUrl('mautic_asset_action', [ 'objectAction' => 'edit', - 'objectId' => $entity->getId() - ]) + 'objectId' => $entity->getId(), + ]), ]); if (!$form->get('buttons')->get('save')->isClicked()) { @@ -333,10 +331,10 @@ public function newAction ($entity = null) $viewParameters = [ 'objectAction' => 'view', - 'objectId' => $entity->getId() + 'objectId' => $entity->getId(), ]; - $returnUrl = $this->generateUrl('mautic_asset_action', $viewParameters); - $template = 'MauticAssetBundle:Asset:view'; + $returnUrl = $this->generateUrl('mautic_asset_action', $viewParameters); + $template = 'MauticAssetBundle:Asset:view'; } } else { $viewParameters = ['page' => $page]; @@ -351,8 +349,8 @@ public function newAction ($entity = null) 'contentTemplate' => $template, 'passthroughVars' => [ 'activeLink' => 'mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]); } } @@ -364,7 +362,7 @@ public function newAction ($entity = null) $integrations = $integrationHelper->getIntegrationObjects(null, ['cloud_storage']); return $this->delegateView([ - 'viewParameters' => [ + 'viewParameters' => [ 'form' => $form->createView(), 'activeAsset' => $entity, 'assetDownloadUrl' => $model->generateUrl($entity), @@ -374,46 +372,46 @@ public function newAction ($entity = null) 'maxSize' => $maxSize, 'maxSizeError' => $maxSizeError, 'extensions' => $extensions, - 'extensionError' => $extensionError + 'extensionError' => $extensionError, ], 'contentTemplate' => 'MauticAssetBundle:Asset:form.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', 'mauticContent' => 'asset', 'route' => $this->generateUrl('mautic_asset_action', [ - 'objectAction' => 'new' - ]) - ] + 'objectAction' => 'new', + ]), + ], ]); } /** - * Generates edit form and processes post data + * Generates edit form and processes post data. * * @param int $objectId * @param bool $ignorePost * * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function editAction ($objectId, $ignorePost = false) + public function editAction($objectId, $ignorePost = false) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $this->getModel('asset'); $entity = $model->getEntity($objectId); - $entity->setMaxSize(Asset::convertSizeToBytes($this->get('mautic.helper.core_parameters')->getParameter('max_size') . 'M')); // convert from MB to B + $entity->setMaxSize(Asset::convertSizeToBytes($this->get('mautic.helper.core_parameters')->getParameter('max_size').'M')); // convert from MB to B $session = $this->get('session'); $page = $session->get('mautic.asset.page', 1); $method = $this->request->getMethod(); $maxSize = $model->getMaxUploadSize(); - $extensions = '.' . implode(', .', $this->get('mautic.helper.core_parameters')->getParameter('allowed_extensions')); + $extensions = '.'.implode(', .', $this->get('mautic.helper.core_parameters')->getParameter('allowed_extensions')); $maxSizeError = $this->get('translator')->trans('mautic.asset.asset.error.file.size', [ '%fileSize%' => '{{filesize}}', - '%maxSize%' => '{{maxFilesize}}' + '%maxSize%' => '{{maxFilesize}}', ], 'validators'); $extensionError = $this->get('translator')->trans('mautic.asset.asset.error.file.extension.js', [ - '%extensions%' => $extensions + '%extensions%' => $extensions, ], 'validators'); //set the return URL @@ -429,8 +427,8 @@ public function editAction ($objectId, $ignorePost = false) 'contentTemplate' => 'MauticAssetBundle:Asset:index', 'passthroughVars' => [ 'activeLink' => 'mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]; //not found @@ -441,9 +439,9 @@ public function editAction ($objectId, $ignorePost = false) [ 'type' => 'error', 'msg' => 'mautic.asset.asset.error.notfound', - 'msgVars' => ['%id%' => $objectId] - ] - ] + 'msgVars' => ['%id%' => $objectId], + ], + ], ]) ); } elseif (!$this->get('mautic.security')->hasEntityAccess( @@ -484,20 +482,20 @@ public function editAction ($objectId, $ignorePost = false) '%menu_link%' => 'mautic_asset_index', '%url%' => $this->generateUrl('mautic_asset_action', [ 'objectAction' => 'edit', - 'objectId' => $entity->getId() - ]) + 'objectId' => $entity->getId(), + ]), ]); - $returnUrl = $this->generateUrl('mautic_asset_action', [ + $returnUrl = $this->generateUrl('mautic_asset_action', [ 'objectAction' => 'view', - 'objectId' => $entity->getId() + 'objectId' => $entity->getId(), ]); $viewParams = ['objectId' => $entity->getId()]; $template = 'MauticAssetBundle:Asset:view'; } } else { //clear any modified content - $session->remove('mautic.asestbuilder.' . $objectId . '.content'); + $session->remove('mautic.asestbuilder.'.$objectId.'.content'); //unlock the entity $model->unlockEntity($entity); @@ -511,7 +509,7 @@ public function editAction ($objectId, $ignorePost = false) array_merge($postActionVars, [ 'returnUrl' => $returnUrl, 'viewParameters' => $viewParams, - 'contentTemplate' => $template + 'contentTemplate' => $template, ]) ); } @@ -527,7 +525,7 @@ public function editAction ($objectId, $ignorePost = false) $integrations = $integrationHelper->getIntegrationObjects(null, ['cloud_storage']); return $this->delegateView([ - 'viewParameters' => [ + 'viewParameters' => [ 'form' => $form->createView(), 'activeAsset' => $entity, 'assetDownloadUrl' => $model->generateUrl($entity), @@ -537,7 +535,7 @@ public function editAction ($objectId, $ignorePost = false) 'maxSize' => $maxSize, 'maxSizeError' => $maxSizeError, 'extensions' => $extensions, - 'extensionError' => $extensionError + 'extensionError' => $extensionError, ], 'contentTemplate' => 'MauticAssetBundle:Asset:form.html.php', 'passthroughVars' => [ @@ -545,20 +543,20 @@ public function editAction ($objectId, $ignorePost = false) 'mauticContent' => 'asset', 'route' => $this->generateUrl('mautic_asset_action', [ 'objectAction' => 'edit', - 'objectId' => $entity->getId() - ]) - ] + 'objectId' => $entity->getId(), + ]), + ], ]); } /** - * Clone an entity + * Clone an entity. * * @param int $objectId * * @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response */ - public function cloneAction ($objectId) + public function cloneAction($objectId) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $this->getModel('asset'); @@ -584,13 +582,13 @@ public function cloneAction ($objectId) } /** - * Deletes the entity + * Deletes the entity. * * @param int $objectId * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ - public function deleteAction ($objectId) + public function deleteAction($objectId) { $page = $this->get('session')->get('mautic.asset.page', 1); $returnUrl = $this->generateUrl('mautic_asset_index', ['page' => $page]); @@ -602,8 +600,8 @@ public function deleteAction ($objectId) 'contentTemplate' => 'MauticAssetBundle:Asset:index', 'passthroughVars' => [ 'activeLink' => 'mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]; if ($this->request->getMethod() == 'POST') { @@ -615,7 +613,7 @@ public function deleteAction ($objectId) $flashes[] = [ 'type' => 'error', 'msg' => 'mautic.asset.asset.error.notfound', - 'msgVars' => ['%id%' => $objectId] + 'msgVars' => ['%id%' => $objectId], ]; } elseif (!$this->get('mautic.security')->hasEntityAccess( 'asset:assets:deleteown', @@ -636,24 +634,24 @@ public function deleteAction ($objectId) 'msg' => 'mautic.core.notice.deleted', 'msgVars' => [ '%name%' => $entity->getTitle(), - '%id%' => $objectId - ] + '%id%' => $objectId, + ], ]; } //else don't do anything return $this->postActionRedirect( array_merge($postActionVars, [ - 'flashes' => $flashes + 'flashes' => $flashes, ]) ); } /** - * Deletes a group of entities + * Deletes a group of entities. * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ - public function batchDeleteAction () + public function batchDeleteAction() { $page = $this->get('session')->get('mautic.asset.page', 1); $returnUrl = $this->generateUrl('mautic_asset_index', ['page' => $page]); @@ -665,8 +663,8 @@ public function batchDeleteAction () 'contentTemplate' => 'MauticAssetBundle:Asset:index', 'passthroughVars' => [ 'activeLink' => 'mautic_asset_index', - 'mauticContent' => 'asset' - ] + 'mauticContent' => 'asset', + ], ]; if ($this->request->getMethod() == 'POST') { @@ -683,7 +681,7 @@ public function batchDeleteAction () $flashes[] = [ 'type' => 'error', 'msg' => 'mautic.asset.asset.error.notfound', - 'msgVars' => ['%id%' => $objectId] + 'msgVars' => ['%id%' => $objectId], ]; } elseif (!$this->get('mautic.security')->hasEntityAccess( 'asset:assets:deleteown', 'asset:assets:deleteother', $entity->getCreatedBy() @@ -705,25 +703,25 @@ public function batchDeleteAction () 'type' => 'notice', 'msg' => 'mautic.asset.asset.notice.batch_deleted', 'msgVars' => [ - '%count%' => count($entities) - ] + '%count%' => count($entities), + ], ]; } } //else don't do anything return $this->postActionRedirect( array_merge($postActionVars, [ - 'flashes' => $flashes + 'flashes' => $flashes, ]) ); } /** - * Renders the container for the remote file browser + * Renders the container for the remote file browser. * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ - public function remoteAction () + public function remoteAction() { // Check for integrations to cloud providers /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ @@ -734,16 +732,16 @@ public function remoteAction () $tmpl = $this->request->isXmlHttpRequest() ? $this->request->get('tmpl', 'index') : 'index'; return $this->delegateView([ - 'viewParameters' => [ + 'viewParameters' => [ 'integrations' => $integrations, - 'tmpl' => $tmpl + 'tmpl' => $tmpl, ], 'contentTemplate' => 'MauticAssetBundle:Remote:browse.html.php', 'passthroughVars' => [ 'activeLink' => '#mautic_asset_index', 'mauticContent' => 'asset', - 'route' => $this->generateUrl('mautic_asset_index', ['page' => $this->get('session')->get('mautic.asset.page', 1)]) - ] + 'route' => $this->generateUrl('mautic_asset_index', ['page' => $this->get('session')->get('mautic.asset.page', 1)]), + ], ]); } } diff --git a/app/bundles/AssetBundle/Controller/PublicController.php b/app/bundles/AssetBundle/Controller/PublicController.php index a145dd66fd7..9bacd79ef58 100644 --- a/app/bundles/AssetBundle/Controller/PublicController.php +++ b/app/bundles/AssetBundle/Controller/PublicController.php @@ -1,22 +1,23 @@ get('mautic.security'); + $security = $this->get('mautic.security'); /** @var \Mautic\AssetBundle\Model\AssetModel $model */ - $model = $this->getModel('asset'); + $model = $this->getModel('asset'); /** @var \Mautic\AssetBundle\Entity\Asset $entity */ - $entity = $model->getEntityBySlugs($slug); + $entity = $model->getEntityBySlugs($slug); if (!empty($entity)) { - $published = $entity->isPublished(); + $published = $entity->isPublished(); //make sure the asset is published or deny access if not if ((!$published) && (!$security->hasEntityAccess('asset:assets:viewown', 'asset:assets:viewother', $entity->getCreatedBy()))) { @@ -50,7 +51,7 @@ public function downloadAction($slug) $url = $model->generateUrl($entity, false); $requestUri = $this->request->getRequestUri(); //remove query - $query = $this->request->getQueryString(); + $query = $this->request->getQueryString(); if (!empty($query)) { $requestUri = str_replace("?{$query}", '', $url); @@ -59,6 +60,7 @@ public function downloadAction($slug) //redirect if they don't match if ($requestUri != $url) { $model->trackDownload($entity, $this->request, 301); + return $this->redirect($url, 301); } @@ -98,7 +100,6 @@ public function downloadAction($slug) } return $response; - } $model->trackDownload($entity, $this->request, 404); diff --git a/app/bundles/AssetBundle/Controller/SubscribedEvents/BuilderTokenController.php b/app/bundles/AssetBundle/Controller/SubscribedEvents/BuilderTokenController.php index cab7a728ead..c87823ce08e 100644 --- a/app/bundles/AssetBundle/Controller/SubscribedEvents/BuilderTokenController.php +++ b/app/bundles/AssetBundle/Controller/SubscribedEvents/BuilderTokenController.php @@ -1,16 +1,17 @@ container->get('request'); + $request = $this->container->get('request'); $response = new EmptyResponse(); - $files = $this->getFiles($request->files); + $files = $this->getFiles($request->files); if (!empty($files)) { foreach ($files as $file) { @@ -45,4 +45,4 @@ public function upload() return $this->createSupportedJsonResponse($response->assemble()); } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/DataFixtures/ORM/LoadAssetData.php b/app/bundles/AssetBundle/DataFixtures/ORM/LoadAssetData.php index d9195626756..e0ce3b2282d 100644 --- a/app/bundles/AssetBundle/DataFixtures/ORM/LoadAssetData.php +++ b/app/bundles/AssetBundle/DataFixtures/ORM/LoadAssetData.php @@ -1,9 +1,10 @@ container = $container; diff --git a/app/bundles/AssetBundle/Entity/Asset.php b/app/bundles/AssetBundle/Entity/Asset.php index deb8a6f52c6..3f9c6f41e50 100644 --- a/app/bundles/AssetBundle/Entity/Asset.php +++ b/app/bundles/AssetBundle/Entity/Asset.php @@ -1,9 +1,10 @@ setTable('assets') ->setCustomRepositoryClass('Mautic\AssetBundle\Entity\AssetRepository') - ->addIndex(array('alias'), 'asset_alias_search'); + ->addIndex(['alias'], 'asset_alias_search'); $builder->addIdColumns('title'); @@ -223,7 +222,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) } /** - * Prepares the metadata for API usage + * Prepares the metadata for API usage. * * @param $metadata */ @@ -231,16 +230,16 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata) { $metadata->setGroupPrefix('asset') ->addListProperties( - array( + [ 'id', 'title', 'alias', 'category', - 'description' - ) + 'description', + ] ) ->addProperties( - array( + [ 'language', 'publishUp', 'publishDown', @@ -250,14 +249,14 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata) 'extension', 'mime', 'size', - 'downloadUrl' - ) + 'downloadUrl', + ] ) ->build(); } /** - * Clone magic function + * Clone magic function. */ public function __clone() { @@ -267,9 +266,9 @@ public function __clone() } /** - * Get id + * Get id. * - * @return integer + * @return int */ public function getId() { @@ -313,7 +312,7 @@ public function getFile() } /** - * Set title + * Set title. * * @param string $title * @@ -328,7 +327,7 @@ public function setTitle($title) } /** - * Get title + * Get title. * * @return string */ @@ -370,7 +369,7 @@ public function setMime($mime) } /** - * Set originalFileName + * Set originalFileName. * * @param string $originalFileName * @@ -385,7 +384,7 @@ public function setOriginalFileName($originalFileName) } /** - * Get originalFileName + * Get originalFileName. * * @return string */ @@ -395,7 +394,7 @@ public function getOriginalFileName() } /** - * Set storage location + * Set storage location. * * @param string $storageLocation * @@ -410,7 +409,7 @@ public function setStorageLocation($storageLocation) } /** - * Get storage location + * Get storage location. * * @return string */ @@ -424,7 +423,7 @@ public function getStorageLocation() } /** - * Set path + * Set path. * * @param string $path * @@ -439,7 +438,7 @@ public function setPath($path) } /** - * Get path + * Get path. * * @return string */ @@ -449,7 +448,7 @@ public function getPath() } /** - * Set remote path + * Set remote path. * * @param string $remotePath * @@ -464,7 +463,7 @@ public function setRemotePath($remotePath) } /** - * Get remote path + * Get remote path. * * @return string */ @@ -474,7 +473,7 @@ public function getRemotePath() } /** - * Set alias + * Set alias. * * @param string $alias * @@ -489,7 +488,7 @@ public function setAlias($alias) } /** - * Get alias + * Get alias. * * @return string */ @@ -499,7 +498,7 @@ public function getAlias() } /** - * Set publishUp + * Set publishUp. * * @param \DateTime $publishUp * @@ -514,7 +513,7 @@ public function setPublishUp($publishUp) } /** - * Get publishUp + * Get publishUp. * * @return \DateTime */ @@ -524,7 +523,7 @@ public function getPublishUp() } /** - * Set publishDown + * Set publishDown. * * @param \DateTime $publishDown * @@ -539,7 +538,7 @@ public function setPublishDown($publishDown) } /** - * Get publishDown + * Get publishDown. * * @return \DateTime */ @@ -549,9 +548,9 @@ public function getPublishDown() } /** - * Set downloadCount + * Set downloadCount. * - * @param integer $downloadCount + * @param int $downloadCount * * @return Asset */ @@ -563,9 +562,9 @@ public function setDownloadCount($downloadCount) } /** - * Get downloadCount + * Get downloadCount. * - * @return integer + * @return int */ public function getDownloadCount() { @@ -573,9 +572,9 @@ public function getDownloadCount() } /** - * Set revision + * Set revision. * - * @param integer $revision + * @param int $revision * * @return Asset */ @@ -587,9 +586,9 @@ public function setRevision($revision) } /** - * Get revision + * Get revision. * - * @return integer + * @return int */ public function getRevision() { @@ -597,7 +596,7 @@ public function getRevision() } /** - * Set language + * Set language. * * @param string $language * @@ -612,7 +611,7 @@ public function setLanguage($language) } /** - * Get language + * Get language. * * @return string */ @@ -622,7 +621,7 @@ public function getLanguage() } /** - * Set category + * Set category. * * @param \Mautic\CategoryBundle\Entity\Category $category * @@ -637,7 +636,7 @@ public function setCategory(\Mautic\CategoryBundle\Entity\Category $category = n } /** - * Get category + * Get category. * * @return \Mautic\CategoryBundle\Entity\Category */ @@ -652,23 +651,23 @@ public function getCategory() */ protected function isChanged($prop, $val) { - $getter = "get".ucfirst($prop); + $getter = 'get'.ucfirst($prop); $current = $this->$getter(); parent::isChanged($prop, $val); } /** - * Constructor + * Constructor. */ public function __construct() { } /** - * Set uniqueDownloadCount + * Set uniqueDownloadCount. * - * @param integer $uniqueDownloadCount + * @param int $uniqueDownloadCount * * @return Asset */ @@ -680,9 +679,9 @@ public function setUniqueDownloadCount($uniqueDownloadCount) } /** - * Get uniqueDownloadCount + * Get uniqueDownloadCount. * - * @return integer + * @return int */ public function getUniqueDownloadCount() { @@ -767,11 +766,9 @@ public function upload() } /** - * Remove a file + * Remove a file. * - * @param boolean $temp >> regular uploaded file or temporary - * - * @return void + * @param bool $temp >> regular uploaded file or temporary */ public function removeUpload($temp = false) { @@ -837,7 +834,7 @@ protected function getUploadDir() } /** - * Set uploadDir + * Set uploadDir. * * @param string $uploadDir * @@ -852,7 +849,7 @@ public function setUploadDir($uploadDir) /** * Returns maximal uploadable size in bytes. - * If not set, 6000000 is default + * If not set, 6000000 is default. * * @return string */ @@ -866,7 +863,7 @@ protected function getMaxSize() } /** - * Set max size + * Set max size. * * @param string $maxSize * @@ -880,14 +877,13 @@ public function setMaxSize($maxSize) } /** - * Returns file extension + * Returns file extension. * * @return string */ public function getFileType() { if (!empty($this->extension) && empty($this->changes['originalFileName'])) { - return $this->extension; } @@ -903,13 +899,13 @@ public function getFileType() } /** - * Returns some file info + * Returns some file info. * * @return array */ public function getFileInfo() { - $fileInfo = array(); + $fileInfo = []; if ($this->getStorageLocation() == 'remote') { $ch = curl_init($this->getRemotePath()); @@ -941,7 +937,7 @@ public function getFileInfo() } /** - * Returns file mime type + * Returns file mime type. * * @return string */ @@ -997,7 +993,7 @@ public function getIconClass() /** * Decides if an asset is image displayable by browser. * - * @return boolean + * @return bool */ public function isImage() { @@ -1007,7 +1003,7 @@ public function isImage() return false; } - $imageTypes = array('jpg', 'jpeg', 'png', 'gif'); + $imageTypes = ['jpg', 'jpeg', 'png', 'gif']; if (in_array($fileType, $imageTypes)) { return true; @@ -1017,56 +1013,56 @@ public function isImage() } /** - * Returns array of common extensions + * Returns array of common extensions. * * @return string */ public function getFileExtensions() { - return array( - 'excel' => array( + return [ + 'excel' => [ 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xls', - 'xlt' - ), - 'word' => array( + 'xlt', + ], + 'word' => [ 'doc', 'docx', 'docm', - 'dotx' - ), - 'pdf' => array( - 'pdf' - ), - 'audio' => array( - 'mp3' - ), - 'archive' => array( + 'dotx', + ], + 'pdf' => [ + 'pdf', + ], + 'audio' => [ + 'mp3', + ], + 'archive' => [ 'zip', 'rar', 'iso', 'tar', 'gz', - '7z' - ), - 'image' => array( + '7z', + ], + 'image' => [ 'jpg', 'jpeg', 'png', 'gif', 'ico', 'bmp', - 'psd' - ), - 'text' => array( + 'psd', + ], + 'text' => [ 'txt', - 'pub' - ), - 'code' => array( + 'pub', + ], + 'code' => [ 'php', 'js', 'json', @@ -1074,9 +1070,9 @@ public function getFileExtensions() 'xml', 'html', 'htm', - 'sql' - ), - 'powerpoint' => array( + 'sql', + ], + 'powerpoint' => [ 'ppt', 'pptx', 'pptm', @@ -1085,16 +1081,16 @@ public function getFileExtensions() 'potx', 'pot', 'pps', - 'odp' - ), - 'video' => array( + 'odp', + ], + 'video' => [ 'wmv', 'avi', 'mp4', 'mkv', - 'mpeg' - ) - ); + 'mpeg', + ], + ]; } /** @@ -1136,7 +1132,7 @@ public function getFileContents() } /** - * Get the path to the file; a URL if remote or full file path if local + * Get the path to the file; a URL if remote or full file path if local. * * @return string */ @@ -1167,11 +1163,11 @@ public function setDescription($description) public static function loadValidatorMetadata(ClassMetadata $metadata) { // Add a constraint to manage the file upload data - $metadata->addConstraint(new Assert\Callback(array('\\Mautic\\AssetBundle\\Entity\\Asset', 'validateFile'))); + $metadata->addConstraint(new Assert\Callback(['\\Mautic\\AssetBundle\\Entity\\Asset', 'validateFile'])); } /** - * Validator to ensure proper data for the file fields + * Validator to ensure proper data for the file fields. * * @param Asset $object Entity object to validate * @param ExecutionContextInterface $context Context object @@ -1213,7 +1209,7 @@ public static function validateFile($object, ExecutionContextInterface $context) } /** - * Set temporary ID + * Set temporary ID. * * @param string $tempId * @@ -1227,7 +1223,7 @@ public function setTempId($tempId) } /** - * Get temporary ID + * Get temporary ID. * * @return string */ @@ -1237,7 +1233,7 @@ public function getTempId() } /** - * Set temporary file name + * Set temporary file name. * * @param string $tempName * @@ -1251,7 +1247,7 @@ public function setTempName($tempName) } /** - * Get temporary file name + * Get temporary file name. * * @return string */ @@ -1306,18 +1302,16 @@ public function setSize($size) return $this; } - /** - * Borrowed from Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize + * Borrowed from Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize. * * @param $size * * @return int|string */ - static public function convertSizeToBytes($size) + public static function convertSizeToBytes($size) { if ('' === $size) { - return PHP_INT_MAX; } @@ -1345,19 +1339,18 @@ static public function convertSizeToBytes($size) } /** - * Get value from PHP configuration with special handling of -1 + * Get value from PHP configuration with special handling of -1. * * @param string $setting * @param bool|true $convertToBytes * * @return int */ - static public function getIniValue($setting, $convertToBytes = true) + public static function getIniValue($setting, $convertToBytes = true) { $value = ini_get($setting); if ($value == -1 || $value === 0) { - return PHP_INT_MAX; } @@ -1374,7 +1367,7 @@ static public function getIniValue($setting, $convertToBytes = true) * * @return string */ - static public function convertBytesToHumanReadable($size, $unit = '') + public static function convertBytesToHumanReadable($size, $unit = '') { list($number, $unit) = self::convertBytesToUnit($size, $unit); @@ -1382,7 +1375,7 @@ static public function convertBytesToHumanReadable($size, $unit = '') $number = number_format($number, 2); // Remove trailing .00 - $number = strpos($number,'.') !== false ? rtrim(rtrim($number,'0'),'.') : $number; + $number = strpos($number, '.') !== false ? rtrim(rtrim($number, '0'), '.') : $number; return $number.' '.$unit; } @@ -1393,25 +1386,22 @@ static public function convertBytesToHumanReadable($size, $unit = '') * * @return array */ - static public function convertBytesToUnit($size, $unit = '') + public static function convertBytesToUnit($size, $unit = '') { $unit = strtoupper($unit); if ((!$unit && $size >= 1 << 30) || $unit == 'GB' || $unit == 'G') { - - return array($size / (1 << 30), 'GB'); + return [$size / (1 << 30), 'GB']; } if ((!$unit && $size >= 1 << 20) || $unit == 'MB' || $unit == 'M') { - - return array($size / (1 << 20), 'MB'); + return [$size / (1 << 20), 'MB']; } if ((!$unit && $size >= 1 << 10) || $unit == 'KB' || $unit == 'K') { - - return array($size / (1 << 10), 'KB'); + return [$size / (1 << 10), 'KB']; } // Add zero to remove useless .00 - return array($size, 'bytes'); + return [$size, 'bytes']; } /** @@ -1439,7 +1429,7 @@ public function setDownloadUrl($downloadUrl) */ public function isLocal() { - return ($this->storageLocation != 'remote'); + return $this->storageLocation != 'remote'; } /** @@ -1447,6 +1437,6 @@ public function isLocal() */ public function isRemote() { - return ($this->storageLocation == 'remote'); + return $this->storageLocation == 'remote'; } } diff --git a/app/bundles/AssetBundle/Entity/AssetRepository.php b/app/bundles/AssetBundle/Entity/AssetRepository.php index 6447a4ff5e1..a1c4127f0e1 100644 --- a/app/bundles/AssetBundle/Entity/AssetRepository.php +++ b/app/bundles/AssetBundle/Entity/AssetRepository.php @@ -1,9 +1,10 @@ createQueryBuilder('a') @@ -69,19 +68,20 @@ public function getAssetList($search = '', $limit = 10, $start = 0, $viewOther = } $results = $q->getQuery()->getArrayResult(); + return $results; } - /** * @param QueryBuilder $q * @param $filter + * * @return array */ protected function addCatchAllWhereClause(&$q, $filter) { - $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier - $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; + $unique = $this->generateRandomParameterName(); //ensure that the string has a unique parameter identifier + $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; $expr = $q->expr()->orX( $q->expr()->like('a.title', ":$unique"), @@ -90,31 +90,33 @@ protected function addCatchAllWhereClause(&$q, $filter) if ($filter->not) { $expr = $q->expr()->not($expr); } - return array( + + return [ $expr, - array("$unique" => $string) - ); + ["$unique" => $string], + ]; } /** * @param QueryBuilder $q * @param $filter + * * @return array */ protected function addSearchCommandWhereClause(&$q, $filter) { - $command = $field = $filter->command; + $command = $field = $filter->command; $unique = $this->generateRandomParameterName(); $returnParameter = true; //returning a parameter that is not used will lead to a Doctrine error $expr = false; switch ($command) { case $this->translator->trans('mautic.core.searchcommand.ispublished'): - $expr = $q->expr()->eq("a.isPublished", ":$unique"); - $forceParameters = array($unique => true); + $expr = $q->expr()->eq('a.isPublished', ":$unique"); + $forceParameters = [$unique => true]; break; case $this->translator->trans('mautic.core.searchcommand.isunpublished'): - $expr = $q->expr()->eq("a.isPublished", ":$unique"); - $forceParameters = array($unique => false); + $expr = $q->expr()->eq('a.isPublished', ":$unique"); + $forceParameters = [$unique => false]; $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.isuncategorized'): @@ -125,20 +127,20 @@ protected function addSearchCommandWhereClause(&$q, $filter) $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.ismine'): - $expr = $q->expr()->eq("IDENTITY(a.createdBy)", $this->currentUser->getId()); + $expr = $q->expr()->eq('IDENTITY(a.createdBy)', $this->currentUser->getId()); $returnParameter = false; break; case $this->translator->trans('mautic.core.searchcommand.category'): - $expr = $q->expr()->like('c.alias', ":$unique"); + $expr = $q->expr()->like('c.alias', ":$unique"); $filter->strict = true; break; case $this->translator->trans('mautic.asset.asset.searchcommand.lang'): - $langUnique = $this->generateRandomParameterName(); - $langValue = $filter->string . "_%"; - $forceParameters = array( + $langUnique = $this->generateRandomParameterName(); + $langValue = $filter->string.'_%'; + $forceParameters = [ $langUnique => $langValue, - $unique => $filter->string - ); + $unique => $filter->string, + ]; $expr = $q->expr()->orX( $q->expr()->eq('a.language', ":$unique"), $q->expr()->like('a.language', ":$langUnique") @@ -153,13 +155,13 @@ protected function addSearchCommandWhereClause(&$q, $filter) if (!empty($forceParameters)) { $parameters = $forceParameters; } elseif (!$returnParameter) { - $parameters = array(); + $parameters = []; } else { $string = ($filter->strict) ? $filter->string : "%{$filter->string}%"; - $parameters = array("$unique" => $string); + $parameters = ["$unique" => $string]; } - return array( $expr, $parameters ); + return [$expr, $parameters]; } /** @@ -167,14 +169,14 @@ protected function addSearchCommandWhereClause(&$q, $filter) */ public function getSearchCommands() { - return array( + return [ 'mautic.core.searchcommand.ispublished', 'mautic.core.searchcommand.isunpublished', 'mautic.core.searchcommand.isuncategorized', 'mautic.core.searchcommand.ismine', 'mautic.core.searchcommand.category', - 'mautic.asset.asset.searchcommand.lang' - ); + 'mautic.asset.asset.searchcommand.lang', + ]; } /** @@ -182,9 +184,9 @@ public function getSearchCommands() */ protected function getDefaultOrder() { - return array( - array('a.title', 'ASC') - ); + return [ + ['a.title', 'ASC'], + ]; } /** @@ -198,7 +200,7 @@ public function getTableAlias() } /** - * Gets the sum size of assets + * Gets the sum size of assets. * * @param array $assets * @@ -228,11 +230,11 @@ public function upDownloadCount($id, $increaseBy = 1, $unique = false) $q = $this->_em->getConnection()->createQueryBuilder(); $q->update(MAUTIC_TABLE_PREFIX.'assets') - ->set('download_count', 'download_count + ' . (int) $increaseBy) - ->where('id = ' . (int) $id); + ->set('download_count', 'download_count + '.(int) $increaseBy) + ->where('id = '.(int) $id); if ($unique) { - $q->set('unique_download_count', 'unique_download_count + ' . (int) $increaseBy); + $q->set('unique_download_count', 'unique_download_count + '.(int) $increaseBy); } $q->execute(); diff --git a/app/bundles/AssetBundle/Entity/Download.php b/app/bundles/AssetBundle/Entity/Download.php index f1ed293d506..f6c48043dc9 100644 --- a/app/bundles/AssetBundle/Entity/Download.php +++ b/app/bundles/AssetBundle/Entity/Download.php @@ -1,9 +1,10 @@ getEntityManager()->getConnection()->createQueryBuilder() ->select('a.id as asset_id, d.date_download as dateDownload, a.title') @@ -78,13 +77,14 @@ public function getLeadDownloads($leadId, array $options = array()) } /** - * Get list of assets ordered by it's download count + * Get list of assets ordered by it's download count. * * @param QueryBuilder $query - * @param integer $limit - * @param integer $offset + * @param int $limit + * @param int $offset * * @return array + * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ @@ -102,13 +102,14 @@ public function getMostDownloaded($query, $limit = 10, $offset = 0) } /** - * Get list of asset referrals ordered by it's count + * Get list of asset referrals ordered by it's count. * * @param QueryBuilder $query - * @param integer $limit - * @param integer $offset + * @param int $limit + * @param int $offset * * @return array + * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ @@ -126,11 +127,12 @@ public function getTopReferrers($query, $limit = 10, $offset = 0) } /** - * Get pie graph data for http statuses + * Get pie graph data for http statuses. * * @param QueryBuilder $query * * @return array + * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ @@ -143,7 +145,7 @@ public function getHttpStatuses($query) $results = $query->execute()->fetchAll(); $chart = new PieChart(); - foreach($results as $result) { + foreach ($results as $result) { $chart->setDataset($result['status'], $result['count']); } @@ -166,7 +168,6 @@ public function getDownloadCountsByPage($pageId, \DateTime $fromDate = null) if (is_array($pageId)) { $q->where($q->expr()->in('p.id', $pageId)) ->groupBy('p.id, a.source_id, p.title, p.hits'); - } else { $q->where($q->expr()->eq('p.id', ':page')) ->setParameter('page', (int) $pageId); @@ -183,7 +184,7 @@ public function getDownloadCountsByPage($pageId, \DateTime $fromDate = null) $results = $q->execute()->fetchAll(); - $downloads = array(); + $downloads = []; foreach ($results as $r) { $downloads[$r['id']] = $r; } @@ -193,7 +194,7 @@ public function getDownloadCountsByPage($pageId, \DateTime $fromDate = null) /** * Get download count by email by linking emails that have been associated with a page hit that has the - * same tracking ID as an asset download tracking ID and thus assumed happened in the same session + * same tracking ID as an asset download tracking ID and thus assumed happened in the same session. * * @param $emailId * @param \DateTime $fromDate @@ -226,7 +227,7 @@ public function getDownloadCountsByEmail($emailId, \DateTime $fromDate = null) $results = $q->execute()->fetchAll(); - $downloads = array(); + $downloads = []; foreach ($results as $r) { $downloads[$r['id']] = $r; } @@ -242,21 +243,21 @@ public function getDownloadCountsByEmail($emailId, \DateTime $fromDate = null) public function updateLeadByTrackingId($leadId, $newTrackingId, $oldTrackingId) { $q = $this->_em->getConnection()->createQueryBuilder(); - $q->update(MAUTIC_TABLE_PREFIX . 'asset_downloads') + $q->update(MAUTIC_TABLE_PREFIX.'asset_downloads') ->set('lead_id', (int) $leadId) ->set('tracking_id', ':newTrackingId') ->where( $q->expr()->eq('tracking_id', ':oldTrackingId') ) - ->setParameters(array( + ->setParameters([ 'newTrackingId' => $newTrackingId, - 'oldTrackingId' => $oldTrackingId - )) + 'oldTrackingId' => $oldTrackingId, + ]) ->execute(); } /** - * Updates lead ID (e.g. after a lead merge) + * Updates lead ID (e.g. after a lead merge). * * @param $fromLeadId * @param $toLeadId @@ -264,9 +265,9 @@ public function updateLeadByTrackingId($leadId, $newTrackingId, $oldTrackingId) public function updateLead($fromLeadId, $toLeadId) { $q = $this->_em->getConnection()->createQueryBuilder(); - $q->update(MAUTIC_TABLE_PREFIX . 'asset_downloads') + $q->update(MAUTIC_TABLE_PREFIX.'asset_downloads') ->set('lead_id', (int) $toLeadId) - ->where('lead_id = ' . (int) $fromLeadId) + ->where('lead_id = '.(int) $fromLeadId) ->execute(); } } diff --git a/app/bundles/AssetBundle/ErrorHandler/DropzoneErrorHandler.php b/app/bundles/AssetBundle/ErrorHandler/DropzoneErrorHandler.php index a73f60b2bd9..e0da59da07a 100644 --- a/app/bundles/AssetBundle/ErrorHandler/DropzoneErrorHandler.php +++ b/app/bundles/AssetBundle/ErrorHandler/DropzoneErrorHandler.php @@ -1,9 +1,10 @@ getMessage(); diff --git a/app/bundles/AssetBundle/Event/AssetEvent.php b/app/bundles/AssetBundle/Event/AssetEvent.php index d2c635b0807..f20294e8f36 100644 --- a/app/bundles/AssetBundle/Event/AssetEvent.php +++ b/app/bundles/AssetBundle/Event/AssetEvent.php @@ -1,21 +1,20 @@ ipLookupHelper = $ipLookupHelper; - $this->auditLogModel = $auditLogModel; + $this->auditLogModel = $auditLogModel; } /** * @return array */ - static public function getSubscribedEvents() + public static function getSubscribedEvents() { - return array( - AssetEvents::ASSET_POST_SAVE => array('onAssetPostSave', 0), - AssetEvents::ASSET_POST_DELETE => array('onAssetDelete', 0) - ); + return [ + AssetEvents::ASSET_POST_SAVE => ['onAssetPostSave', 0], + AssetEvents::ASSET_POST_DELETE => ['onAssetDelete', 0], + ]; } /** - * Add an entry to the audit log + * Add an entry to the audit log. * * @param Events\AssetEvent $event */ @@ -65,34 +63,34 @@ public function onAssetPostSave(Events\AssetEvent $event) { $asset = $event->getAsset(); if ($details = $event->getChanges()) { - $log = array( - "bundle" => "asset", - "object" => "asset", - "objectId" => $asset->getId(), - "action" => ($event->isNew()) ? "create" : "update", - "details" => $details, - "ipAddress" => $this->ipLookupHelper->getIpAddressFromRequest() - ); + $log = [ + 'bundle' => 'asset', + 'object' => 'asset', + 'objectId' => $asset->getId(), + 'action' => ($event->isNew()) ? 'create' : 'update', + 'details' => $details, + 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), + ]; $this->auditLogModel->writeToLog($log); } } /** - * Add a delete entry to the audit log + * Add a delete entry to the audit log. * * @param Events\AssetEvent $event */ public function onAssetDelete(Events\AssetEvent $event) { $asset = $event->getAsset(); - $log = array( - "bundle" => "asset", - "object" => "asset", - "objectId" => $asset->deletedId, - "action" => "delete", - "details" => array('name' => $asset->getTitle()), - "ipAddress" => $this->ipLookupHelper->getIpAddressFromRequest() - ); + $log = [ + 'bundle' => 'asset', + 'object' => 'asset', + 'objectId' => $asset->deletedId, + 'action' => 'delete', + 'details' => ['name' => $asset->getTitle()], + 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), + ]; $this->auditLogModel->writeToLog($log); //In case of batch delete, this method call remove the uploaded file diff --git a/app/bundles/AssetBundle/EventListener/BuilderSubscriber.php b/app/bundles/AssetBundle/EventListener/BuilderSubscriber.php index 6a84698d670..3472830d3cf 100644 --- a/app/bundles/AssetBundle/EventListener/BuilderSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/BuilderSubscriber.php @@ -1,9 +1,10 @@ array('onBuilderBuild', 0), - EmailEvents::EMAIL_ON_SEND => array('onEmailGenerate', 0), - EmailEvents::EMAIL_ON_DISPLAY => array('onEmailGenerate', 0), - PageEvents::PAGE_ON_BUILD => array('onBuilderBuild', 0), - PageEvents::PAGE_ON_DISPLAY => array('onPageDisplay', 0) - ); + return [ + EmailEvents::EMAIL_ON_BUILD => ['onBuilderBuild', 0], + EmailEvents::EMAIL_ON_SEND => ['onEmailGenerate', 0], + EmailEvents::EMAIL_ON_DISPLAY => ['onEmailGenerate', 0], + PageEvents::PAGE_ON_BUILD => ['onBuilderBuild', 0], + PageEvents::PAGE_ON_DISPLAY => ['onPageDisplay', 0], + ]; } /** @@ -101,7 +101,7 @@ public function onPageDisplay(PageDisplayEvent $event) { $page = $event->getPage(); $leadId = ($this->security->isAnonymous()) ? $this->leadModel->getCurrentLead()->getId() : null; - $tokens = $this->generateTokensFromContent($event, $leadId, array('page', $page->getId())); + $tokens = $this->generateTokensFromContent($event, $leadId, ['page', $page->getId()]); $content = $event->getContent(); if (!empty($tokens)) { @@ -128,13 +128,13 @@ private function addTokenSections($event) * * @return array */ - private function generateTokensFromContent($event, $leadId, $source = array(), $emailId = null) + private function generateTokensFromContent($event, $leadId, $source = [], $emailId = null) { $content = $event->getContent(); - $clickthrough = array(); + $clickthrough = []; if ($event instanceof PageDisplayEvent || ($event instanceof EmailSendEvent && $event->shouldAppendClickthrough())) { - $clickthrough = array('source' => $source); + $clickthrough = ['source' => $source]; if ($leadId !== null) { $clickthrough['lead'] = $leadId; diff --git a/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php b/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php index 0161728b73e..882b941d8d2 100644 --- a/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php @@ -1,15 +1,16 @@ ['onCampaignBuild', 0], AssetEvents::ASSET_ON_LOAD => ['onAssetDownload', 0], - AssetEvents::ON_CAMPAIGN_TRIGGER_DECISION => ['onCampaignTriggerDecision', 0] + AssetEvents::ON_CAMPAIGN_TRIGGER_DECISION => ['onCampaignTriggerDecision', 0], ]; } @@ -60,14 +59,14 @@ public function onCampaignBuild(CampaignBuilderEvent $event) 'label' => 'mautic.asset.campaign.event.download', 'description' => 'mautic.asset.campaign.event.download_descr', 'eventName' => AssetEvents::ON_CAMPAIGN_TRIGGER_DECISION, - 'formType' => 'campaignevent_assetdownload' + 'formType' => 'campaignevent_assetdownload', ]; $event->addDecision('asset.download', $trigger); } /** - * Trigger point actions for asset download + * Trigger point actions for asset download. * * @param AssetLoadEvent $event */ @@ -101,4 +100,4 @@ public function onCampaignTriggerDecision(CampaignExecutionEvent $event) $event->setResult(true); } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/EventListener/ConfigSubscriber.php b/app/bundles/AssetBundle/EventListener/ConfigSubscriber.php index 3322defc41c..9d7ba284c1f 100644 --- a/app/bundles/AssetBundle/EventListener/ConfigSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/ConfigSubscriber.php @@ -1,42 +1,41 @@ array('onConfigGenerate', 0) - ); + return [ + ConfigEvents::CONFIG_ON_GENERATE => ['onConfigGenerate', 0], + ]; } - public function onConfigGenerate (ConfigBuilderEvent $event) + public function onConfigGenerate(ConfigBuilderEvent $event) { - $event->addForm(array( + $event->addForm([ 'bundle' => 'AssetBundle', 'formAlias' => 'assetconfig', 'formTheme' => 'MauticAssetBundle:FormTheme\Config', - 'parameters' => $event->getParametersFromConfig('MauticAssetBundle') - )); + 'parameters' => $event->getParametersFromConfig('MauticAssetBundle'), + ]); } } diff --git a/app/bundles/AssetBundle/EventListener/DashboardSubscriber.php b/app/bundles/AssetBundle/EventListener/DashboardSubscriber.php index 1070a74646d..43c24d88cfa 100644 --- a/app/bundles/AssetBundle/EventListener/DashboardSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/DashboardSubscriber.php @@ -1,54 +1,52 @@ array(), - 'unique.vs.repetitive.downloads' => array(), - 'popular.assets' => array(), - 'created.assets' => array() - ); + protected $types = [ + 'asset.downloads.in.time' => [], + 'unique.vs.repetitive.downloads' => [], + 'popular.assets' => [], + 'created.assets' => [], + ]; /** - * Define permissions to see those widgets + * Define permissions to see those widgets. * * @var array */ - protected $permissions = array( + protected $permissions = [ 'asset:assets:viewown', - 'asset:assets:viewother' - ); + 'asset:assets:viewother', + ]; /** * @var AssetModel @@ -66,23 +64,21 @@ public function __construct(AssetModel $assetModel) } /** - * Set a widget detail when needed + * Set a widget detail when needed. * * @param WidgetDetailEvent $event - * - * @return void */ public function onWidgetDetailGenerate(WidgetDetailEvent $event) { $this->checkPermissions($event); $canViewOthers = $event->hasPermission('asset:assets:viewother'); - + if ($event->getType() == 'asset.downloads.in.time') { $widget = $event->getWidget(); $params = $widget->getParams(); if (!$event->isCached()) { - $event->setTemplateData(array( + $event->setTemplateData([ 'chartType' => 'line', 'chartHeight' => $widget->getHeight() - 80, 'chartData' => $this->assetModel->getDownloadsLineChartData( @@ -91,8 +87,8 @@ public function onWidgetDetailGenerate(WidgetDetailEvent $event) $params['dateTo'], $params['dateFormat'], $canViewOthers - ) - )); + ), + ]); } $event->setTemplate('MauticCoreBundle:Helper:chart.html.php'); @@ -102,12 +98,12 @@ public function onWidgetDetailGenerate(WidgetDetailEvent $event) if ($event->getType() == 'unique.vs.repetitive.downloads') { if (!$event->isCached()) { $params = $event->getWidget()->getParams(); - $model = $this->factory->getModel('asset'); - $event->setTemplateData(array( + $model = $this->factory->getModel('asset'); + $event->setTemplateData([ 'chartType' => 'pie', 'chartHeight' => $event->getWidget()->getHeight() - 80, - 'chartData' => $this->assetModel->getUniqueVsRepetitivePieChartData($params['dateFrom'], $params['dateTo'], $canViewOthers) - )); + 'chartData' => $this->assetModel->getUniqueVsRepetitivePieChartData($params['dateFrom'], $params['dateTo'], $canViewOthers), + ]); } $event->setTemplate('MauticCoreBundle:Helper:chart.html.php'); @@ -124,36 +120,36 @@ public function onWidgetDetailGenerate(WidgetDetailEvent $event) } else { $limit = $params['limit']; } - + $assets = $this->assetModel->getPopularAssets($limit, $params['dateFrom'], $params['dateTo'], $canViewOthers); - $items = array(); + $items = []; // Build table rows with links if ($assets) { foreach ($assets as &$asset) { - $assetUrl = $this->router->generate('mautic_asset_action', array('objectAction' => 'view', 'objectId' => $asset['id'])); - $row = array( - array( + $assetUrl = $this->router->generate('mautic_asset_action', ['objectAction' => 'view', 'objectId' => $asset['id']]); + $row = [ + [ 'value' => $asset['title'], - 'type' => 'link', - 'link' => $assetUrl - ), - array( - 'value' => $asset['download_count'] - ) - ); + 'type' => 'link', + 'link' => $assetUrl, + ], + [ + 'value' => $asset['download_count'], + ], + ]; $items[] = $row; } } - - $event->setTemplateData(array( - 'headItems' => array( + + $event->setTemplateData([ + 'headItems' => [ $event->getTranslator()->trans('mautic.dashboard.label.title'), - $event->getTranslator()->trans('mautic.dashboard.label.downloads') - ), - 'bodyItems' => $items, - 'raw' => $assets - )); + $event->getTranslator()->trans('mautic.dashboard.label.downloads'), + ], + 'bodyItems' => $items, + 'raw' => $assets, + ]); } $event->setTemplate('MauticCoreBundle:Helper:table.html.php'); @@ -171,33 +167,33 @@ public function onWidgetDetailGenerate(WidgetDetailEvent $event) $limit = $params['limit']; } - $assets = $this->assetModel->getAssetList($limit, $params['dateFrom'], $params['dateTo'], array(), array('canViewOthers' => $canViewOthers)); - $items = array(); + $assets = $this->assetModel->getAssetList($limit, $params['dateFrom'], $params['dateTo'], [], ['canViewOthers' => $canViewOthers]); + $items = []; // Build table rows with links if ($assets) { foreach ($assets as &$asset) { - $assetUrl = $this->router->generate('mautic_asset_action', array('objectAction' => 'view', 'objectId' => $asset['id'])); - $row = array( - array( + $assetUrl = $this->router->generate('mautic_asset_action', ['objectAction' => 'view', 'objectId' => $asset['id']]); + $row = [ + [ 'value' => $asset['name'], - 'type' => 'link', - 'link' => $assetUrl - ) - ); + 'type' => 'link', + 'link' => $assetUrl, + ], + ]; $items[] = $row; } } - $event->setTemplateData(array( - 'headItems' => array( - $event->getTranslator()->trans('mautic.dashboard.label.title') - ), - 'bodyItems' => $items, - 'raw' => $assets - )); + $event->setTemplateData([ + 'headItems' => [ + $event->getTranslator()->trans('mautic.dashboard.label.title'), + ], + 'bodyItems' => $items, + 'raw' => $assets, + ]); } - + $event->setTemplate('MauticCoreBundle:Helper:table.html.php'); $event->stopPropagation(); } diff --git a/app/bundles/AssetBundle/EventListener/EmailSubscriber.php b/app/bundles/AssetBundle/EventListener/EmailSubscriber.php index f3d2c3e76b8..289b667be82 100644 --- a/app/bundles/AssetBundle/EventListener/EmailSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/EmailSubscriber.php @@ -1,9 +1,10 @@ array('onEmailBuild', 0), - ); + return [ + EmailEvents::EMAIL_ON_BUILD => ['onEmailBuild', 0], + ]; } /** - * * @param EmailBuilderEvent $event */ - public function onEmailBuild (EmailBuilderEvent $event) + public function onEmailBuild(EmailBuilderEvent $event) { if ($event->abTestWinnerCriteriaRequested()) { //add AB Test Winner Criteria - $formSubmissions = array( + $formSubmissions = [ 'group' => 'mautic.asset.abtest.criteria', 'label' => 'mautic.asset.abtest.criteria.downloads', - 'callback' => '\Mautic\AssetBundle\Helper\AbTestHelper::determineDownloadWinner' - ); + 'callback' => '\Mautic\AssetBundle\Helper\AbTestHelper::determineDownloadWinner', + ]; $event->addAbTestWinnerCriteria('asset.downloads', $formSubmissions); } } diff --git a/app/bundles/AssetBundle/EventListener/FormSubscriber.php b/app/bundles/AssetBundle/EventListener/FormSubscriber.php index 91d5cc6d1d5..1cb19ebf716 100644 --- a/app/bundles/AssetBundle/EventListener/FormSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/FormSubscriber.php @@ -1,9 +1,10 @@ array('onFormBuilder', 0), - ); + return [ + FormEvents::FORM_ON_BUILD => ['onFormBuilder', 0], + ]; } /** - * Add a lead generation action to available form submit actions + * Add a lead generation action to available form submit actions. * * @param FormBuilderEvent $event */ public function onFormBuilder(FormBuilderEvent $event) { //add form submit actions - $action = array( + $action = [ 'group' => 'mautic.asset.actions', 'label' => 'mautic.asset.asset.submitaction.downloadfile', 'description' => 'mautic.asset.asset.submitaction.downloadfile_descr', 'formType' => 'asset_submitaction_downloadfile', - 'formTypeCleanMasks' => array('message' => 'html'), + 'formTypeCleanMasks' => ['message' => 'html'], 'callback' => '\Mautic\AssetBundle\Helper\FormSubmitHelper::onFormSubmit', - 'allowCampaignForm' => true - ); + 'allowCampaignForm' => true, + ]; $event->addSubmitAction('asset.download', $action); } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/EventListener/LeadSubscriber.php b/app/bundles/AssetBundle/EventListener/LeadSubscriber.php index b7d6d6c4959..6d3ebd56c4e 100644 --- a/app/bundles/AssetBundle/EventListener/LeadSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/LeadSubscriber.php @@ -1,26 +1,24 @@ ['onTimelineGenerate', 0], @@ -52,7 +50,7 @@ static public function getSubscribedEvents() } /** - * Compile events for the lead timeline + * Compile events for the lead timeline. * * @param LeadTimelineEvent $event */ @@ -65,7 +63,6 @@ public function onTimelineGenerate(LeadTimelineEvent $event) // Decide if those events are filtered if (!$event->isApplicable($eventTypeKey)) { - return; } @@ -85,19 +82,19 @@ public function onTimelineGenerate(LeadTimelineEvent $event) $asset = $this->assetModel->getEntity($download['asset_id']); $event->addEvent( [ - 'event' => $eventTypeKey, - 'eventLabel' => [ + 'event' => $eventTypeKey, + 'eventLabel' => [ 'label' => $download['title'], - 'href' => $this->router->generate('mautic_asset_action', ['objectAction' => 'view', 'objectId' => $download['asset_id']]) + 'href' => $this->router->generate('mautic_asset_action', ['objectAction' => 'view', 'objectId' => $download['asset_id']]), ], - 'extra' => [ + 'extra' => [ 'asset' => $asset, - 'assetDownloadUrl' => $this->assetModel->generateUrl($asset) + 'assetDownloadUrl' => $this->assetModel->generateUrl($asset), ], 'eventType' => $eventTypeName, 'timestamp' => $download['dateDownload'], 'icon' => 'fa-download', - 'contentTemplate' => 'MauticAssetBundle:SubscribedEvents\Timeline:index.html.php' + 'contentTemplate' => 'MauticAssetBundle:SubscribedEvents\Timeline:index.html.php', ] ); } diff --git a/app/bundles/AssetBundle/EventListener/PageSubscriber.php b/app/bundles/AssetBundle/EventListener/PageSubscriber.php index e226c0679c5..aa98a8964e1 100644 --- a/app/bundles/AssetBundle/EventListener/PageSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/PageSubscriber.php @@ -1,9 +1,10 @@ array('OnPageBuild', 0) - ); + return [ + PageEvents::PAGE_ON_BUILD => ['OnPageBuild', 0], + ]; } /** - * Add forms to available page tokens + * Add forms to available page tokens. * * @param PageBuilderEvent $event */ - public function onPageBuild (PageBuilderEvent $event) + public function onPageBuild(PageBuilderEvent $event) { if ($event->abTestWinnerCriteriaRequested()) { //add AB Test Winner Criteria - $assetDownloads = array( + $assetDownloads = [ 'group' => 'mautic.asset.abtest.criteria', 'label' => 'mautic.asset.abtest.criteria.downloads', - 'callback' => '\Mautic\AssetBundle\Helper\AbTestHelper::determineDownloadWinner' - ); + 'callback' => '\Mautic\AssetBundle\Helper\AbTestHelper::determineDownloadWinner', + ]; $event->addAbTestWinnerCriteria('asset.downloads', $assetDownloads); } } diff --git a/app/bundles/AssetBundle/EventListener/PointSubscriber.php b/app/bundles/AssetBundle/EventListener/PointSubscriber.php index 86e86efaa6f..7e1ba9432fa 100644 --- a/app/bundles/AssetBundle/EventListener/PointSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/PointSubscriber.php @@ -1,11 +1,13 @@ array('onPointBuild', 0), - AssetEvents::ASSET_ON_LOAD => array('onAssetDownload', 0) - ); + return [ + PointEvents::POINT_ON_BUILD => ['onPointBuild', 0], + AssetEvents::ASSET_ON_LOAD => ['onAssetDownload', 0], + ]; } /** @@ -53,28 +53,28 @@ static public function getSubscribedEvents() */ public function onPointBuild(PointBuilderEvent $event) { - $action = array( + $action = [ 'group' => 'mautic.asset.actions', 'label' => 'mautic.asset.point.action.download', 'description' => 'mautic.asset.point.action.download_descr', - 'callback' => array('\\Mautic\\AssetBundle\\Helper\\PointActionHelper', 'validateAssetDownload'), - 'formType' => 'pointaction_assetdownload' - ); + 'callback' => ['\\Mautic\\AssetBundle\\Helper\\PointActionHelper', 'validateAssetDownload'], + 'formType' => 'pointaction_assetdownload', + ]; $event->addAction('asset.download', $action); } /** - * Trigger point actions for asset download + * Trigger point actions for asset download. * * @param AssetLoadEvent $event */ public function onAssetDownload(AssetLoadEvent $event) { $asset = $event->getRecord()->getAsset(); - + if ($asset !== null) { $this->pointModel->triggerAction('asset.download', $asset); } } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/EventListener/ReportSubscriber.php b/app/bundles/AssetBundle/EventListener/ReportSubscriber.php index 62161799b57..25846fd9460 100644 --- a/app/bundles/AssetBundle/EventListener/ReportSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/ReportSubscriber.php @@ -1,46 +1,43 @@ ['onReportBuilder', 0], ReportEvents::REPORT_ON_GENERATE => ['onReportGenerate', 0], - ReportEvents::REPORT_ON_GRAPH_GENERATE => ['onReportGraphGenerate', 0] + ReportEvents::REPORT_ON_GRAPH_GENERATE => ['onReportGraphGenerate', 0], ]; } /** - * Add available tables and columns to the report builder lookup + * Add available tables and columns to the report builder lookup. * * @param ReportBuilderEvent $event - * - * @return void */ public function onReportBuilder(ReportBuilderEvent $event) { @@ -48,26 +45,26 @@ public function onReportBuilder(ReportBuilderEvent $event) // Assets $prefix = 'a.'; $columns = [ - $prefix.'download_count' => [ + $prefix.'download_count' => [ 'label' => 'mautic.asset.report.download_count', - 'type' => 'int' + 'type' => 'int', ], $prefix.'unique_download_count' => [ 'label' => 'mautic.asset.report.unique_download_count', - 'type' => 'int' + 'type' => 'int', ], - $prefix.'alias' => [ + $prefix.'alias' => [ 'label' => 'mautic.core.alias', - 'type' => 'string' + 'type' => 'string', ], - $prefix.'lang' => [ + $prefix.'lang' => [ 'label' => 'mautic.core.language', - 'type' => 'string' + 'type' => 'string', ], - $prefix.'title' => [ + $prefix.'title' => [ 'label' => 'mautic.core.title', - 'type' => 'string' - ] + 'type' => 'string', + ], ]; $columns = array_merge($columns, $event->getStandardColumns($prefix, ['name'], 'mautic_asset_action'), $event->getCategoryColumns()); @@ -75,7 +72,7 @@ public function onReportBuilder(ReportBuilderEvent $event) 'assets', [ 'display_name' => 'mautic.asset.assets', - 'columns' => $columns + 'columns' => $columns, ] ); @@ -85,31 +82,31 @@ public function onReportBuilder(ReportBuilderEvent $event) $downloadColumns = [ $downloadPrefix.'date_download' => [ 'label' => 'mautic.asset.report.download.date_download', - 'type' => 'datetime' + 'type' => 'datetime', ], - $downloadPrefix.'code' => [ + $downloadPrefix.'code' => [ 'label' => 'mautic.asset.report.download.code', - 'type' => 'string' + 'type' => 'string', ], - $downloadPrefix.'referer' => [ + $downloadPrefix.'referer' => [ 'label' => 'mautic.core.referer', - 'type' => 'string' + 'type' => 'string', ], - $downloadPrefix.'source' => [ + $downloadPrefix.'source' => [ 'label' => 'mautic.report.field.source', - 'type' => 'string' + 'type' => 'string', ], - $downloadPrefix.'source_id' => [ + $downloadPrefix.'source_id' => [ 'label' => 'mautic.report.field.source_id', - 'type' => 'int' - ] + 'type' => 'int', + ], ]; $event->addTable( 'asset.downloads', [ 'display_name' => 'mautic.asset.report.downloads.table', - 'columns' => array_merge($columns, $downloadColumns, $event->getLeadColumns(), $event->getIpColumn()) + 'columns' => array_merge($columns, $downloadColumns, $event->getLeadColumns(), $event->getIpColumn()), ], 'assets' ); @@ -125,11 +122,9 @@ public function onReportBuilder(ReportBuilderEvent $event) } /** - * Initialize the QueryBuilder object to generate reports from + * Initialize the QueryBuilder object to generate reports from. * * @param ReportGeneratorEvent $event - * - * @return void */ public function onReportGenerate(ReportGeneratorEvent $event) { @@ -153,11 +148,9 @@ public function onReportGenerate(ReportGeneratorEvent $event) } /** - * Initialize the QueryBuilder object to generate reports from + * Initialize the QueryBuilder object to generate reports from. * * @param ReportGraphEvent $event - * - * @return void */ public function onReportGraphGenerate(ReportGraphEvent $event) { diff --git a/app/bundles/AssetBundle/EventListener/SearchSubscriber.php b/app/bundles/AssetBundle/EventListener/SearchSubscriber.php index 47213f8baec..b0e84ab6e87 100644 --- a/app/bundles/AssetBundle/EventListener/SearchSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/SearchSubscriber.php @@ -1,23 +1,22 @@ array('onGlobalSearch', 0), - CoreEvents::BUILD_COMMAND_LIST => array('onBuildCommandList', 0) - ); + return [ + CoreEvents::GLOBAL_SEARCH => ['onGlobalSearch', 0], + CoreEvents::BUILD_COMMAND_LIST => ['onBuildCommandList', 0], + ]; } /** @@ -57,44 +56,44 @@ public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event) return; } - $filter = array("string" => $str, "force" => array()); + $filter = ['string' => $str, 'force' => []]; $permissions = $this->security->isGranted( - array('asset:assets:viewown', 'asset:assets:viewother'), + ['asset:assets:viewown', 'asset:assets:viewother'], 'RETURN_ARRAY' ); if ($permissions['asset:assets:viewown'] || $permissions['asset:assets:viewother']) { if (!$permissions['asset:assets:viewother']) { - $filter['force'][] = array( + $filter['force'][] = [ 'column' => 'IDENTITY(a.createdBy)', 'expr' => 'eq', - 'value' => $this->factory->getUser()->getId() - ); + 'value' => $this->factory->getUser()->getId(), + ]; } $assets = $this->assetModel->getEntities( - array( + [ 'limit' => 5, - 'filter' => $filter - )); + 'filter' => $filter, + ]); if (count($assets) > 0) { - $assetResults = array(); + $assetResults = []; foreach ($assets as $asset) { $assetResults[] = $this->templating->renderResponse( 'MauticAssetBundle:SubscribedEvents\Search:global.html.php', - array('asset' => $asset) + ['asset' => $asset] )->getContent(); } if (count($assets) > 5) { $assetResults[] = $this->templating->renderResponse( 'MauticAssetBundle:SubscribedEvents\Search:global.html.php', - array( + [ 'showMore' => true, 'searchString' => $str, - 'remaining' => (count($assets) - 5) - ) + 'remaining' => (count($assets) - 5), + ] )->getContent(); } $assetResults['count'] = count($assets); @@ -108,11 +107,11 @@ public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event) */ public function onBuildCommandList(MauticEvents\CommandListEvent $event) { - if ($this->security->isGranted(array('asset:assets:viewown', 'asset:assets:viewother'), "MATCH_ONE")) { + if ($this->security->isGranted(['asset:assets:viewown', 'asset:assets:viewother'], 'MATCH_ONE')) { $event->addCommands( 'mautic.asset.assets', $this->assetModel->getCommandList() ); } } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/EventListener/UploadSubscriber.php b/app/bundles/AssetBundle/EventListener/UploadSubscriber.php index e9220e66236..fc5e95da20d 100644 --- a/app/bundles/AssetBundle/EventListener/UploadSubscriber.php +++ b/app/bundles/AssetBundle/EventListener/UploadSubscriber.php @@ -1,9 +1,10 @@ translator = $translator; + $this->translator = $translator; $this->coreParametersHelper = $coreParametersHelper; - $this->assetModel = $assetModel; + $this->assetModel = $assetModel; } /** * @return array */ - static public function getSubscribedEvents () + public static function getSubscribedEvents() { return [ UploadEvents::POST_UPLOAD => ['onPostUpload', 0], - UploadEvents::VALIDATION => ['onUploadValidation', 0] + UploadEvents::VALIDATION => ['onUploadValidation', 0], ]; } @@ -71,7 +70,7 @@ static public function getSubscribedEvents () * * @param PostUploadEvent $event */ - public function onPostUpload (PostUploadEvent $event) + public function onPostUpload(PostUploadEvent $event) { $request = $event->getRequest()->request; $response = $event->getResponse(); @@ -79,7 +78,7 @@ public function onPostUpload (PostUploadEvent $event) $file = $event->getFile(); $config = $event->getConfig(); $uploadDir = $config['storage']['directory']; - $tmpDir = $uploadDir . '/tmp/' . $tempId; + $tmpDir = $uploadDir.'/tmp/'.$tempId; // Move uploaded file to temporary folder $file->move($tmpDir); @@ -90,11 +89,11 @@ public function onPostUpload (PostUploadEvent $event) } /** - * Validates file before upload + * Validates file before upload. * * @param ValidationEvent $event */ - public function onUploadValidation (ValidationEvent $event) + public function onUploadValidation(ValidationEvent $event) { $file = $event->getFile(); $extensions = $this->coreParametersHelper->getParameter('allowed_extensions'); @@ -104,7 +103,7 @@ public function onUploadValidation (ValidationEvent $event) if ($file->getSize() > $maxSize) { $message = $this->translator->trans('mautic.asset.asset.error.file.size', [ '%fileSize%' => round($file->getSize() / 1048576, 2), - '%maxSize%' => round($maxSize / 1048576, 2) + '%maxSize%' => round($maxSize / 1048576, 2), ], 'validators'); throw new ValidationException($message); } @@ -112,7 +111,7 @@ public function onUploadValidation (ValidationEvent $event) if (!in_array(strtolower($file->getExtension()), array_map('strtolower', $extensions))) { $message = $this->translator->trans('mautic.asset.asset.error.file.extension', [ '%fileExtension%' => $file->getExtension(), - '%extensions%' => implode(', ', $extensions) + '%extensions%' => implode(', ', $extensions), ], 'validators'); throw new ValidationException($message); } diff --git a/app/bundles/AssetBundle/Form/Type/AssetListType.php b/app/bundles/AssetBundle/Form/Type/AssetListType.php index 5908dd5300e..1de69062048 100644 --- a/app/bundles/AssetBundle/Form/Type/AssetListType.php +++ b/app/bundles/AssetBundle/Form/Type/AssetListType.php @@ -1,9 +1,10 @@ getSecurity()->isGranted('asset:assets:viewother'); - $repo = $factory->getModel('asset')->getRepository(); + $repo = $factory->getModel('asset')->getRepository(); $repo->setCurrentUser($factory->getUser()); $choices = $repo->getAssetList('', 0, 0, $viewOther); - + foreach ($choices as $asset) { $this->choices[$asset['language']][$asset['id']] = $asset['title']; } @@ -49,13 +47,13 @@ public function __construct(MauticFactory $factory) */ public function setDefaultOptions(OptionsResolverInterface $resolver) { - $resolver->setDefaults(array( - 'choices' => $this->choices, - 'empty_value' => false, - 'expanded' => false, - 'multiple' => true, - 'required' => false - )); + $resolver->setDefaults([ + 'choices' => $this->choices, + 'empty_value' => false, + 'expanded' => false, + 'multiple' => true, + 'required' => false, + ]); } /** @@ -63,7 +61,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) */ public function getName() { - return "asset_list"; + return 'asset_list'; } /** diff --git a/app/bundles/AssetBundle/Form/Type/AssetType.php b/app/bundles/AssetBundle/Form/Type/AssetType.php index e2b715f1107..2c649e063f5 100644 --- a/app/bundles/AssetBundle/Form/Type/AssetType.php +++ b/app/bundles/AssetBundle/Form/Type/AssetType.php @@ -1,9 +1,10 @@ addEventSubscriber(new CleanFormSubscriber(['description' => 'html'])); $builder->addEventSubscriber(new FormExitSubscriber('asset.asset', $options)); $builder->add('storageLocation', 'button_group', [ - 'label' => 'mautic.asset.asset.form.storageLocation', + 'label' => 'mautic.asset.asset.form.storageLocation', 'choice_list' => new ChoiceList( ['local', 'remote'], ['mautic.asset.asset.form.storageLocation.local', 'mautic.asset.asset.form.storageLocation.remote'] ), 'attr' => [ - 'onchange' => 'Mautic.changeAssetStorageLocation();' - ] + 'onchange' => 'Mautic.changeAssetStorageLocation();', + ], ]); $maxUploadSize = $this->assetModel->getMaxUploadSize('', true); $builder->add('tempName', 'hidden', [ 'label' => $this->translator->trans('mautic.asset.asset.form.file.upload', ['%max%' => $maxUploadSize]), 'label_attr' => ['class' => 'control-label'], - 'required' => false + 'required' => false, ]); $builder->add('originalFileName', 'hidden', [ - 'required' => false + 'required' => false, ]); $builder->add('remotePath', 'text', [ 'label' => 'mautic.asset.asset.form.remotePath', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], - 'required' => false + 'required' => false, ]); $builder->add('title', 'text', [ 'label' => 'mautic.core.title', 'label_attr' => ['class' => 'control-label'], - 'attr' => ['class' => 'form-control'] + 'attr' => ['class' => 'form-control'], ]); $builder->add('alias', 'text', [ @@ -106,18 +105,18 @@ public function buildForm (FormBuilderInterface $builder, array $options) 'class' => 'form-control', 'tooltip' => 'mautic.asset.asset.help.alias', ], - 'required' => false + 'required' => false, ]); $builder->add('description', 'textarea', [ 'label' => 'mautic.core.description', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control editor'], - 'required' => false + 'required' => false, ]); $builder->add('category', 'category', [ - 'bundle' => 'asset' + 'bundle' => 'asset', ]); $builder->add('language', 'locale', [ @@ -127,7 +126,7 @@ public function buildForm (FormBuilderInterface $builder, array $options) 'class' => 'form-control', 'tooltip' => 'mautic.asset.asset.form.language.help', ], - 'required' => false + 'required' => false, ]); $builder->add('isPublished', 'yesno_button_group'); @@ -138,10 +137,10 @@ public function buildForm (FormBuilderInterface $builder, array $options) 'label_attr' => ['class' => 'control-label'], 'attr' => [ 'class' => 'form-control', - 'data-toggle' => 'datetime' + 'data-toggle' => 'datetime', ], - 'format' => 'yyyy-MM-dd HH:mm', - 'required' => false + 'format' => 'yyyy-MM-dd HH:mm', + 'required' => false, ]); $builder->add('publishDown', 'datetime', [ @@ -150,20 +149,20 @@ public function buildForm (FormBuilderInterface $builder, array $options) 'label_attr' => ['class' => 'control-label'], 'attr' => [ 'class' => 'form-control', - 'data-toggle' => 'datetime' + 'data-toggle' => 'datetime', ], - 'format' => 'yyyy-MM-dd HH:mm', - 'required' => false + 'format' => 'yyyy-MM-dd HH:mm', + 'required' => false, ]); $builder->add('tempId', 'hidden', [ - 'required' => false + 'required' => false, ]); $builder->add('buttons', 'form_buttons', []); - if (!empty($options["action"])) { - $builder->setAction($options["action"]); + if (!empty($options['action'])) { + $builder->setAction($options['action']); } } @@ -180,6 +179,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) */ public function getName() { - return "asset"; + return 'asset'; } } diff --git a/app/bundles/AssetBundle/Form/Type/CampaignEventAssetDownloadType.php b/app/bundles/AssetBundle/Form/Type/CampaignEventAssetDownloadType.php index aa98fa18ab6..d44f30f3236 100644 --- a/app/bundles/AssetBundle/Form/Type/CampaignEventAssetDownloadType.php +++ b/app/bundles/AssetBundle/Form/Type/CampaignEventAssetDownloadType.php @@ -1,9 +1,10 @@ add('assets', 'asset_list', array( - 'label' => 'mautic.asset.campaign.event.assets', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + $builder->add('assets', 'asset_list', [ + 'label' => 'mautic.asset.campaign.event.assets', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', - 'tooltip' => 'mautic.asset.campaign.event.assets.descr' - ) - )); + 'tooltip' => 'mautic.asset.campaign.event.assets.descr', + ], + ]); } /** * @return string */ - public function getName() { - return "campaignevent_assetdownload"; + public function getName() + { + return 'campaignevent_assetdownload'; } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/Form/Type/ConfigType.php b/app/bundles/AssetBundle/Form/Type/ConfigType.php index 66ec65a10ce..435050c8cc0 100644 --- a/app/bundles/AssetBundle/Form/Type/ConfigType.php +++ b/app/bundles/AssetBundle/Form/Type/ConfigType.php @@ -1,23 +1,22 @@ add('upload_dir', 'text', array( - 'label' => 'mautic.asset.config.form.upload.dir', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( - 'class' => 'form-control', - 'tooltip' => 'mautic.asset.config.form.upload.dir.tooltip' - ), - 'constraints' => array( - new NotBlank(array( - 'message' => 'mautic.core.value.required' - )) - ) - )); + $builder->add('upload_dir', 'text', [ + 'label' => 'mautic.asset.config.form.upload.dir', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => 'mautic.asset.config.form.upload.dir.tooltip', + ], + 'constraints' => [ + new NotBlank([ + 'message' => 'mautic.core.value.required', + ]), + ], + ]); - $builder->add('max_size', 'text', array( - 'label' => 'mautic.asset.config.form.max.size', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( - 'class' => 'form-control', - 'tooltip' => 'mautic.asset.config.form.max.size.tooltip' - ), - 'constraints' => array( - new NotBlank(array( - 'message' => 'mautic.core.value.required' - )) - ) - )); + $builder->add('max_size', 'text', [ + 'label' => 'mautic.asset.config.form.max.size', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => 'mautic.asset.config.form.max.size.tooltip', + ], + 'constraints' => [ + new NotBlank([ + 'message' => 'mautic.core.value.required', + ]), + ], + ]); $arrayStringTransformer = new ArrayStringTransformer(); $builder->add( - $builder->create('allowed_extensions', 'text', array( + $builder->create('allowed_extensions', 'text', [ 'label' => 'mautic.asset.config.form.allowed.extensions', - 'label_attr' => array('class' => 'control-label'), - 'attr' => array( + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ 'class' => 'form-control', - 'tooltip' => 'mautic.asset.config.form.allowed.extensions.tooltip' - ), - 'required' => false - ))->addViewTransformer($arrayStringTransformer) + 'tooltip' => 'mautic.asset.config.form.allowed.extensions.tooltip', + ], + 'required' => false, + ])->addViewTransformer($arrayStringTransformer) ); } @@ -76,4 +75,4 @@ public function getName() { return 'assetconfig'; } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/Form/Type/FormSubmitActionDownloadFileType.php b/app/bundles/AssetBundle/Form/Type/FormSubmitActionDownloadFileType.php index ba764be80b2..cb293d84d16 100644 --- a/app/bundles/AssetBundle/Form/Type/FormSubmitActionDownloadFileType.php +++ b/app/bundles/AssetBundle/Form/Type/FormSubmitActionDownloadFileType.php @@ -1,9 +1,10 @@ add('asset', 'asset_list', array( - 'expanded' => false, - 'multiple' => false, - 'label' => 'mautic.asset.form.submit.assets', - 'label_attr' => array('class' => 'control-label'), - 'empty_value' => false, - 'required' => false, - 'attr' => array( + $builder->add('asset', 'asset_list', [ + 'expanded' => false, + 'multiple' => false, + 'label' => 'mautic.asset.form.submit.assets', + 'label_attr' => ['class' => 'control-label'], + 'empty_value' => false, + 'required' => false, + 'attr' => [ 'class' => 'form-control', - 'tooltip' => 'mautic.asset.form.submit.assets_descr' - ) - )); + 'tooltip' => 'mautic.asset.form.submit.assets_descr', + ], + ]); } /** * @return string */ - public function getName() { - return "asset_submitaction_downloadfile"; + public function getName() + { + return 'asset_submitaction_downloadfile'; } } diff --git a/app/bundles/AssetBundle/Form/Type/PointActionAssetDownloadType.php b/app/bundles/AssetBundle/Form/Type/PointActionAssetDownloadType.php index 53ace1d13cb..1093d2d66bc 100644 --- a/app/bundles/AssetBundle/Form/Type/PointActionAssetDownloadType.php +++ b/app/bundles/AssetBundle/Form/Type/PointActionAssetDownloadType.php @@ -1,9 +1,10 @@ add('assets', 'asset_list', array( - 'expanded' => false, - 'multiple' => true, - 'label' => 'mautic.asset.point.action.assets', - 'label_attr' => array('class' => 'control-label'), - 'empty_value' => false, - 'required' => false, - 'attr' => array( + $builder->add('assets', 'asset_list', [ + 'expanded' => false, + 'multiple' => true, + 'label' => 'mautic.asset.point.action.assets', + 'label_attr' => ['class' => 'control-label'], + 'empty_value' => false, + 'required' => false, + 'attr' => [ 'class' => 'form-control', - 'tooltip' => 'mautic.asset.point.action.assets.descr' - ) - )); + 'tooltip' => 'mautic.asset.point.action.assets.descr', + ], + ]); } /** * @return string */ - public function getName() { - return "pointaction_assetdownload"; + public function getName() + { + return 'pointaction_assetdownload'; } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/Helper/AbTestHelper.php b/app/bundles/AssetBundle/Helper/AbTestHelper.php index 7b955d7609d..82c869303e0 100644 --- a/app/bundles/AssetBundle/Helper/AbTestHelper.php +++ b/app/bundles/AssetBundle/Helper/AbTestHelper.php @@ -1,9 +1,10 @@ getEntityManager()->getRepository('MauticAssetBundle:Download'); @@ -36,7 +36,7 @@ public static function determineDownloadWinner ($factory, $parent, $children) //if it is a page A/B test, then link form submission to page $type = ($parent instanceof Email) ? 'email' : 'page'; - $ids = array($parent->getId()); + $ids = [$parent->getId()]; foreach ($children as $c) { if ($c->isPublished()) { @@ -51,40 +51,40 @@ public static function determineDownloadWinner ($factory, $parent, $children) $translator = $factory->getTranslator(); if ($counts) { - $downloads = $support = $data = array(); - $hasResults = array(); + $downloads = $support = $data = []; + $hasResults = []; $downloadsLabel = $translator->trans('mautic.asset.abtest.label.downloads'); - $hitsLabel = ($type == 'page') ? $translator->trans('mautic.asset.abtest.label.hits') : $translator->trans('mautic.asset.abtest.label.sentemils'); + $hitsLabel = ($type == 'page') ? $translator->trans('mautic.asset.abtest.label.hits') : $translator->trans('mautic.asset.abtest.label.sentemils'); foreach ($counts as $stats) { $rate = ($stats['total']) ? round(($stats['count'] / $stats['total']) * 100, 2) : 0; $downloads[$stats['id']] = $rate; $data[$downloadsLabel][] = $stats['count']; $data[$hitsLabel][] = $stats['total']; - $support['labels'][] = $stats['id'] . ':' . $stats['name'] . ' (' . $rate . '%)'; + $support['labels'][] = $stats['id'].':'.$stats['name'].' ('.$rate.'%)'; $hasResults[] = $stats['id']; } //make sure that parent and published children are included if (!in_array($parent->getId(), $hasResults)) { $data[$downloadsLabel][] = 0; - $data[$hitsLabel][] = 0; - $support['labels'][] = $parent->getId() . ':' . (($type == 'page') ? $parent->getTitle() : $parent->getName()) . ' (0%)'; + $data[$hitsLabel][] = 0; + $support['labels'][] = $parent->getId().':'.(($type == 'page') ? $parent->getTitle() : $parent->getName()).' (0%)'; } foreach ($children as $c) { if ($c->isPublished()) { if (!in_array($c->getId(), $hasResults)) { $data[$downloadsLabel][] = 0; - $data[$hitsLabel][] = 0; - $support['labels'][] = $c->getId() . ':' . (($type == 'page') ? $c->getTitle() : $c->getName()) . ' (0%)'; + $data[$hitsLabel][] = 0; + $support['labels'][] = $c->getId().':'.(($type == 'page') ? $c->getTitle() : $c->getName()).' (0%)'; } } } $support['data'] = $data; //set max for scales - $maxes = array(); + $maxes = []; foreach ($support['data'] as $label => $data) { $maxes[] = max($data); } @@ -98,21 +98,21 @@ public static function determineDownloadWinner ($factory, $parent, $children) $max = max($downloads); //get the page ids with the most number of downloads - $winners = ($max > 0) ? array_keys($downloads, $max) : array(); + $winners = ($max > 0) ? array_keys($downloads, $max) : []; - return array( + return [ 'winners' => $winners, 'support' => $support, 'basedOn' => 'asset.downloads', - 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\AbTest:bargraph.html.php' - ); + 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\AbTest:bargraph.html.php', + ]; } } - return array( - 'winners' => array(), - 'support' => array(), - 'basedOn' => 'asset.downloads' - ); + return [ + 'winners' => [], + 'support' => [], + 'basedOn' => 'asset.downloads', + ]; } -} \ No newline at end of file +} diff --git a/app/bundles/AssetBundle/Helper/FormSubmitHelper.php b/app/bundles/AssetBundle/Helper/FormSubmitHelper.php index 9afa15ddca8..4d85ccce208 100644 --- a/app/bundles/AssetBundle/Helper/FormSubmitHelper.php +++ b/app/bundles/AssetBundle/Helper/FormSubmitHelper.php @@ -1,13 +1,15 @@ getProperties(); - $assetId = $properties['asset']; + $assetId = $properties['asset']; /** @var \Mautic\AssetBundle\Model\AssetModel $model */ - $model = $factory->getModel('asset'); - $asset = $model->getEntity($assetId); - $form = $action->getForm(); + $model = $factory->getModel('asset'); + $asset = $model->getEntity($assetId); + $form = $action->getForm(); //make sure the asset still exists and is published if ($asset != null && $asset->isPublished()) { //register a callback after the other actions have been fired - return array( + return [ 'callback' => '\Mautic\AssetBundle\Helper\FormSubmitHelper::downloadFile', 'form' => $form, 'asset' => $asset, - 'message' => (isset($properties['message'])) ? $properties['message'] : '' - ); + 'message' => (isset($properties['message'])) ? $properties['message'] : '', + ]; } } @@ -65,29 +64,29 @@ public static function downloadFile(Form $form, Asset $asset, MauticFactory $fac { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $factory->getModel('asset'); - $url = $model->generateUrl($asset, true, array('form', $form->getId())); + $url = $model->generateUrl($asset, true, ['form', $form->getId()]); if ($messengerMode) { - return array('download' => $url); + return ['download' => $url]; } - $msg = $message . $factory->getTranslator()->trans('mautic.asset.asset.submitaction.downloadfile.msg', array( - '%url%' => $url - )); + $msg = $message.$factory->getTranslator()->trans('mautic.asset.asset.submitaction.downloadfile.msg', [ + '%url%' => $url, + ]); $analytics = $factory->getHelper('template.analytics')->getCode(); - if (! empty($analytics)) { + if (!empty($analytics)) { $factory->getHelper('template.assets')->addCustomDeclaration($analytics); } - $logicalName = $factory->getHelper('theme')->checkForTwigTemplate(':' . $factory->getParameter('theme') . ':message.html.php'); + $logicalName = $factory->getHelper('theme')->checkForTwigTemplate(':'.$factory->getParameter('theme').':message.html.php'); - $content = $factory->getTemplating()->renderResponse($logicalName, array( + $content = $factory->getTemplating()->renderResponse($logicalName, [ 'message' => $msg, 'type' => 'notice', - 'template' => $factory->getParameter('theme') - ))->getContent(); + 'template' => $factory->getParameter('theme'), + ])->getContent(); return new Response($content); } diff --git a/app/bundles/AssetBundle/Helper/PointActionHelper.php b/app/bundles/AssetBundle/Helper/PointActionHelper.php index 8051d48297b..bdd21425272 100644 --- a/app/bundles/AssetBundle/Helper/PointActionHelper.php +++ b/app/bundles/AssetBundle/Helper/PointActionHelper.php @@ -1,18 +1,17 @@ leadModel = $leadModel; - $this->categoryModel = $categoryModel; - $this->request = $requestStack->getCurrentRequest(); + $this->leadModel = $leadModel; + $this->categoryModel = $categoryModel; + $this->request = $requestStack->getCurrentRequest(); $this->ipLookupHelper = $ipLookupHelper; - $this->maxAssetSize = $coreParametersHelper->getParameter('mautic.max_size'); + $this->maxAssetSize = $coreParametersHelper->getParameter('mautic.max_size'); } /** @@ -96,9 +97,9 @@ public function saveEntity($entity, $unlock = true) $aliasTag = $count; while ($count) { - $testAlias = $alias . $aliasTag; + $testAlias = $alias.$aliasTag; $count = $repo->checkUniqueAlias($testAlias, $entity); - $aliasTag++; + ++$aliasTag; } if ($testAlias != $alias) { $alias = $testAlias; @@ -110,7 +111,7 @@ public function saveEntity($entity, $unlock = true) if (!$entity->isNew()) { //increase the revision $revision = $entity->getRevision(); - $revision++; + ++$revision; $entity->setRevision($revision); } @@ -119,13 +120,14 @@ public function saveEntity($entity, $unlock = true) /** * @param $asset - * @param null $request + * @param null $request * @param string $code - * @param array $systemEntry + * @param array $systemEntry + * * @throws \Doctrine\ORM\ORMException * @throws \Exception */ - public function trackDownload($asset, $request = null, $code = '200', $systemEntry = array()) + public function trackDownload($asset, $request = null, $code = '200', $systemEntry = []) { // Don't skew results with in-house downloads if (empty($systemEntry) && !$this->security->isAnonymous()) { @@ -152,7 +154,7 @@ public function trackDownload($asset, $request = null, $code = '200', $systemEnt if ($lead !== null) { $this->leadModel->setLeadCookie($clickthrough['lead']); list($trackingId, $trackingNewlyGenerated) = $this->leadModel->getTrackingCookie(); - $leadClickthrough = true; + $leadClickthrough = true; $this->leadModel->setCurrentLead($lead); } @@ -173,7 +175,7 @@ public function trackDownload($asset, $request = null, $code = '200', $systemEnt } if (!empty($clickthrough['email'])) { - $emailRepo = $this->em->getRepository("MauticEmailBundle:Email"); + $emailRepo = $this->em->getRepository('MauticEmailBundle:Email'); if ($emailEntity = $emailRepo->getEntity($clickthrough['email'])) { $download->setEmail($emailEntity); } @@ -272,7 +274,7 @@ public function trackDownload($asset, $request = null, $code = '200', $systemEnt } /** - * Increase the download count + * Increase the download count. * * @param $asset * @param int $increaseBy @@ -314,7 +316,7 @@ public function getPermissionBase() */ public function getNameGetter() { - return "getTitle"; + return 'getTitle'; } /** @@ -322,19 +324,21 @@ public function getNameGetter() * * @throws NotFoundHttpException */ - public function createForm($entity, $formFactory, $action = null, $options = array()) + public function createForm($entity, $formFactory, $action = null, $options = []) { if (!$entity instanceof Asset) { - throw new MethodNotAllowedHttpException(array('Asset')); + throw new MethodNotAllowedHttpException(['Asset']); } - $params = (!empty($action)) ? array('action' => $action) : array(); + $params = (!empty($action)) ? ['action' => $action] : []; + return $formFactory->create('asset', $entity, $params); } /** - * Get a specific entity or generate a new one if id is empty + * Get a specific entity or generate a new one if id is empty. * * @param $id + * * @return null|Asset */ public function getEntity($id = null) @@ -355,25 +359,26 @@ public function getEntity($id = null) * @param $event * @param $entity * @param $isNew + * * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException */ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null) { if (!$entity instanceof Asset) { - throw new MethodNotAllowedHttpException(array('Asset')); + throw new MethodNotAllowedHttpException(['Asset']); } switch ($action) { - case "pre_save": + case 'pre_save': $name = AssetEvents::ASSET_PRE_SAVE; break; - case "post_save": + case 'post_save': $name = AssetEvents::ASSET_POST_SAVE; break; - case "pre_delete": + case 'pre_delete': $name = AssetEvents::ASSET_PRE_DELETE; break; - case "post_delete": + case 'post_delete': $name = AssetEvents::ASSET_POST_DELETE; break; default: @@ -387,6 +392,7 @@ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event } $this->dispatcher->dispatch($name, $event); + return $event; } else { return null; @@ -394,7 +400,7 @@ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event } /** - * Get list of entities for autopopulate fields + * Get list of entities for autopopulate fields. * * @param $type * @param $filter @@ -404,7 +410,7 @@ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event */ public function getLookupResults($type, $filter = '', $limit = 10) { - $results = array(); + $results = []; switch ($type) { case 'asset': $viewOther = $this->security->isGranted('asset:assets:viewother'); @@ -421,7 +427,7 @@ public function getLookupResults($type, $filter = '', $limit = 10) } /** - * Generate url for an asset + * Generate url for an asset. * * @param Asset $entity * @param bool $absolute @@ -429,22 +435,22 @@ public function getLookupResults($type, $filter = '', $limit = 10) * * @return string */ - public function generateUrl($entity, $absolute = true, $clickthrough = array()) + public function generateUrl($entity, $absolute = true, $clickthrough = []) { - $assetSlug = $entity->getId() . ':' . $entity->getAlias(); + $assetSlug = $entity->getId().':'.$entity->getAlias(); - $slugs = array( - 'slug' => $assetSlug - ); + $slugs = [ + 'slug' => $assetSlug, + ]; return $this->buildUrl('mautic_asset_download', $slugs, $absolute, $clickthrough); } /** - * Determine the max upload size based on PHP restrictions and config + * Determine the max upload size based on PHP restrictions and config. * - * @param string $unit If '', determine the best unit based on the number - * @param bool|false $humanReadable Return as a human readable filesize + * @param string $unit If '', determine the best unit based on the number + * @param bool|false $humanReadable Return as a human readable filesize * * @return float */ @@ -455,7 +461,7 @@ public function getMaxUploadSize($unit = 'M', $humanReadable = false) $maxPostSize = Asset::getIniValue('post_max_size'); $maxUploadSize = Asset::getIniValue('upload_max_filesize'); $memoryLimit = Asset::getIniValue('memory_limit'); - $maxAllowed = min(array_filter(array($maxAssetSize, $maxPostSize, $maxUploadSize, $memoryLimit))); + $maxAllowed = min(array_filter([$maxAssetSize, $maxPostSize, $maxUploadSize, $memoryLimit])); if ($humanReadable) { $number = Asset::convertBytesToHumanReadable($maxAllowed); @@ -475,7 +481,7 @@ public function getTotalFilesize($assets) { $firstAsset = is_array($assets) ? reset($assets) : false; if ($assets instanceof PersistentCollection || is_object($firstAsset)) { - $assetIds = array(); + $assetIds = []; foreach ($assets as $asset) { $assetIds[] = $asset->getId(); } @@ -483,7 +489,7 @@ public function getTotalFilesize($assets) } if (!is_array($assets)) { - $assets = array($assets); + $assets = [$assets]; } if (empty($assets)) { @@ -501,22 +507,22 @@ public function getTotalFilesize($assets) } /** - * Get line chart data of downloads + * Get line chart data of downloads. * - * @param char $unit {@link php.net/manual/en/function.date.php#refsect1-function.date-parameters} + * @param char $unit {@link php.net/manual/en/function.date.php#refsect1-function.date-parameters} * @param \DateTime $dateFrom * @param \DateTime $dateTo * @param string $dateFormat * @param array $filter - * @param boolean $canViewOthers + * @param bool $canViewOthers * * @return array */ - public function getDownloadsLineChartData($unit, \DateTime $dateFrom, \DateTime $dateTo, $dateFormat = null, $filter = array(), $canViewOthers = true) + public function getDownloadsLineChartData($unit, \DateTime $dateFrom, \DateTime $dateTo, $dateFormat = null, $filter = [], $canViewOthers = true) { - $chart = new LineChart($unit, $dateFrom, $dateTo, $dateFormat); - $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo); - $q = $query->prepareTimeDataQuery('asset_downloads', 'date_download', $filter); + $chart = new LineChart($unit, $dateFrom, $dateTo, $dateFormat); + $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo); + $q = $query->prepareTimeDataQuery('asset_downloads', 'date_download', $filter); if (!$canViewOthers) { $q->join('t', MAUTIC_TABLE_PREFIX.'assets', 'a', 'a.id = t.asset_id') @@ -527,26 +533,27 @@ public function getDownloadsLineChartData($unit, \DateTime $dateFrom, \DateTime $data = $query->loadAndBuildTimeData($q); $chart->setDataset($this->translator->trans('mautic.asset.downloadcount'), $data); + return $chart->render(); } /** * Get pie chart data of unique vs repetitive downloads. - * Repetitive in this case mean if a lead downloaded any of the assets more than once + * Repetitive in this case mean if a lead downloaded any of the assets more than once. * - * @param string $dateFrom - * @param string $dateTo - * @param array $filters - * @param boolean $canViewOthers + * @param string $dateFrom + * @param string $dateTo + * @param array $filters + * @param bool $canViewOthers * * @return array */ - public function getUniqueVsRepetitivePieChartData($dateFrom, $dateTo, $filters = array(), $canViewOthers = true) + public function getUniqueVsRepetitivePieChartData($dateFrom, $dateTo, $filters = [], $canViewOthers = true) { - $chart = new PieChart(); - $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo); - $allQ = $query->getCountQuery('asset_downloads', 'id', 'date_download', $filters); - $uniqueQ = $query->getCountQuery('asset_downloads', 'lead_id', 'date_download', $filters, array('getUnique' => true)); + $chart = new PieChart(); + $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo); + $allQ = $query->getCountQuery('asset_downloads', 'id', 'date_download', $filters); + $uniqueQ = $query->getCountQuery('asset_downloads', 'lead_id', 'date_download', $filters, ['getUnique' => true]); if (!$canViewOthers) { $allQ->join('t', MAUTIC_TABLE_PREFIX.'assets', 'a', 'a.id = t.asset_id') @@ -557,7 +564,7 @@ public function getUniqueVsRepetitivePieChartData($dateFrom, $dateTo, $filters = ->setParameter('userId', $this->user->getId()); } - $all = $query->fetchCount($allQ); + $all = $query->fetchCount($allQ); $unique = $query->fetchCount($uniqueQ); $repetitive = $all - $unique; @@ -568,17 +575,17 @@ public function getUniqueVsRepetitivePieChartData($dateFrom, $dateTo, $filters = } /** - * Get a list of popular (by downloads) assets + * Get a list of popular (by downloads) assets. * - * @param integer $limit - * @param string $dateFrom - * @param string $dateTo - * @param array $filters - * @param boolean $canViewOthers + * @param int $limit + * @param string $dateFrom + * @param string $dateTo + * @param array $filters + * @param bool $canViewOthers * * @return array */ - public function getPopularAssets($limit = 10, $dateFrom = null, $dateTo = null, $filters = array(), $canViewOthers = true) + public function getPopularAssets($limit = 10, $dateFrom = null, $dateTo = null, $filters = [], $canViewOthers = true) { $q = $this->em->getConnection()->createQueryBuilder(); $q->select('COUNT(DISTINCT t.id) AS download_count, a.id, a.title') @@ -603,9 +610,9 @@ public function getPopularAssets($limit = 10, $dateFrom = null, $dateTo = null, } /** - * Get a list of assets in a date range + * Get a list of assets in a date range. * - * @param integer $limit + * @param int $limit * @param \DateTime $dateFrom * @param \DateTime $dateTo * @param array $filters @@ -613,7 +620,7 @@ public function getPopularAssets($limit = 10, $dateFrom = null, $dateTo = null, * * @return array */ - public function getAssetList($limit = 10, \DateTime $dateFrom = null, \DateTime $dateTo = null, $filters = array(), $options = array()) + public function getAssetList($limit = 10, \DateTime $dateFrom = null, \DateTime $dateTo = null, $filters = [], $options = []) { $q = $this->em->getConnection()->createQueryBuilder(); $q->select('t.id, t.title as name, t.date_added, t.date_modified') diff --git a/app/bundles/AssetBundle/Security/Permissions/AssetPermissions.php b/app/bundles/AssetBundle/Security/Permissions/AssetPermissions.php index 9c5c4cc2427..1527286e44f 100644 --- a/app/bundles/AssetBundle/Security/Permissions/AssetPermissions.php +++ b/app/bundles/AssetBundle/Security/Permissions/AssetPermissions.php @@ -1,25 +1,23 @@ extend('MauticCoreBundle:Default:content.html.php'); $view['slots']->set('mauticContent', 'asset'); -$view['slots']->set("headerTitle", $activeAsset->getTitle()); +$view['slots']->set('headerTitle', $activeAsset->getTitle()); $view['slots']->set( 'actions', $view->render( 'MauticCoreBundle:Helper:page_actions.html.php', - array( + [ 'item' => $activeAsset, - 'templateButtons' => array( - 'edit' => $security->hasEntityAccess( + 'templateButtons' => [ + 'edit' => $security->hasEntityAccess( $permissions['asset:assets:editown'], $permissions['asset:assets:editother'], $activeAsset->getCreatedBy() ), - 'clone' => $permissions['asset:assets:create'], + 'clone' => $permissions['asset:assets:create'], 'delete' => $security->hasEntityAccess( $permissions['asset:assets:deleteown'], $permissions['asset:assets:deleteother'], $activeAsset->getCreatedBy() ), - 'close' => $security->hasEntityAccess( + 'close' => $security->hasEntityAccess( $permissions['asset:assets:viewown'], $permissions['asset:assets:viewother'], $activeAsset->getCreatedBy() - ) - ), - 'routeBase' => 'asset', - 'langVar' => 'asset.asset', - 'nameGetter' => 'getTitle' - ) + ), + ], + 'routeBase' => 'asset', + 'langVar' => 'asset.asset', + 'nameGetter' => 'getTitle', + ] ) ); $view['slots']->set( 'publishStatus', - $view->render('MauticCoreBundle:Helper:publishstatus_badge.html.php', array('entity' => $activeAsset)) + $view->render('MauticCoreBundle:Helper:publishstatus_badge.html.php', ['entity' => $activeAsset]) ); ?> @@ -71,7 +71,7 @@ render( 'MauticCoreBundle:Helper:details.html.php', - array('entity' => $activeAsset) + ['entity' => $activeAsset] ); ?> trans( @@ -132,16 +132,16 @@
- trans('mautic.asset.asset.downloads.total', array('count' => $stats['downloads']['total'])); ?> + trans('mautic.asset.asset.downloads.total', ['count' => $stats['downloads']['total']]); ?> | - trans('mautic.asset.asset.downloads.unique', array('count' => $stats['downloads']['unique'])); ?> + trans('mautic.asset.asset.downloads.unique', ['count' => $stats['downloads']['unique']]); ?>
- render('MauticCoreBundle:Helper:graph_dateselect.html.php', array('dateRangeForm' => $dateRangeForm, 'class' => 'pull-right')); ?> + render('MauticCoreBundle:Helper:graph_dateselect.html.php', ['dateRangeForm' => $dateRangeForm, 'class' => 'pull-right']); ?>
- render('MauticCoreBundle:Helper:chart.html.php', array('chartData' => $stats['downloads']['timeStats'], 'chartType' => 'line', 'chartHeight' => 300)); ?> + render('MauticCoreBundle:Helper:chart.html.php', ['chartData' => $stats['downloads']['timeStats'], 'chartType' => 'line', 'chartHeight' => 300]); ?>
@@ -154,7 +154,7 @@
render( 'MauticAssetBundle:Asset:preview.html.php', - array('activeAsset' => $activeAsset, 'assetDownloadUrl' => $assetDownloadUrl) + ['activeAsset' => $activeAsset, 'assetDownloadUrl' => $assetDownloadUrl] ); ?>
@@ -186,7 +186,7 @@
- render('MauticCoreBundle:Helper:recentactivity.html.php', array('logs' => $logs)); ?> + render('MauticCoreBundle:Helper:recentactivity.html.php', ['logs' => $logs]); ?> diff --git a/app/bundles/AssetBundle/Views/Asset/form.html.php b/app/bundles/AssetBundle/Views/Asset/form.html.php index a64bb849160..6da101277d0 100644 --- a/app/bundles/AssetBundle/Views/Asset/form.html.php +++ b/app/bundles/AssetBundle/Views/Asset/form.html.php @@ -1,25 +1,26 @@ extend('MauticCoreBundle:Default:content.html.php'); $header = ($activeAsset->getId()) ? $view['translator']->trans('mautic.asset.asset.menu.edit', - array('%name%' => $activeAsset->getTitle())) : + ['%name%' => $activeAsset->getTitle()]) : $view['translator']->trans('mautic.asset.asset.menu.new'); -$view['slots']->set("headerTitle", $header); +$view['slots']->set('headerTitle', $header); $view['slots']->set('mauticContent', 'asset'); ?> start($form); ?> @@ -32,14 +33,18 @@
row($form['storageLocation']); ?>
-
+
trans('mautic.asset.remote.file.browse'); ?>
-
> +
>
label($form['tempName']); ?> @@ -54,14 +59,16 @@
-
> +
> row($form['remotePath']); ?>
- render('MauticAssetBundle:Asset:preview.html.php', array('activeAsset' => $activeAsset, 'assetDownloadUrl' => $assetDownloadUrl)); ?> + render('MauticAssetBundle:Asset:preview.html.php', ['activeAsset' => $activeAsset, 'assetDownloadUrl' => $assetDownloadUrl]); ?>
@@ -84,21 +91,21 @@
row($form['category']); - echo $view['form']->row($form['language']); - echo $view['form']->row($form['isPublished']); - echo $view['form']->row($form['publishUp']); - echo $view['form']->row($form['publishDown']); - ?> + echo $view['form']->row($form['category']); + echo $view['form']->row($form['language']); + echo $view['form']->row($form['isPublished']); + echo $view['form']->row($form['publishUp']); + echo $view['form']->row($form['publishDown']); + ?>
end($form); ?> - render('MauticCoreBundle:Helper:modal.html.php', array( - 'id' => 'RemoteFileModal', - 'size' => 'lg', - 'footerButtons' => true - )); ?> + render('MauticCoreBundle:Helper:modal.html.php', [ + 'id' => 'RemoteFileModal', + 'size' => 'lg', + 'footerButtons' => true, + ]); ?> diff --git a/app/bundles/AssetBundle/Views/Asset/index.html.php b/app/bundles/AssetBundle/Views/Asset/index.html.php index 2b0eb200d11..ae177e5cf0f 100644 --- a/app/bundles/AssetBundle/Views/Asset/index.html.php +++ b/app/bundles/AssetBundle/Views/Asset/index.html.php @@ -1,41 +1,41 @@ extend('MauticCoreBundle:Default:content.html.php'); $view['slots']->set('mauticContent', 'asset'); -$view['slots']->set("headerTitle", $view['translator']->trans('mautic.asset.assets')); +$view['slots']->set('headerTitle', $view['translator']->trans('mautic.asset.assets')); $view['slots']->set( 'actions', $view->render( 'MauticCoreBundle:Helper:page_actions.html.php', - array( - 'templateButtons' => array( - 'new' => $permissions['asset:assets:create'] - ), - 'routeBase' => 'asset', - 'langVar' => 'asset.asset' - ) + [ + 'templateButtons' => [ + 'new' => $permissions['asset:assets:create'], + ], + 'routeBase' => 'asset', + 'langVar' => 'asset.asset', + ] ) ); ?>
- render('MauticCoreBundle:Helper:list_toolbar.html.php', array( - 'searchValue' => $searchValue, - 'action' => $currentRoute, - 'langVar' => 'asset.asset', - 'routeBase' => 'asset', - 'templateButtons' => array( - 'delete' => $permissions['asset:assets:deleteown'] || $permissions['asset:assets:deleteother'] - ) - )); ?> + render('MauticCoreBundle:Helper:list_toolbar.html.php', [ + 'searchValue' => $searchValue, + 'action' => $currentRoute, + 'langVar' => 'asset.asset', + 'routeBase' => 'asset', + 'templateButtons' => [ + 'delete' => $permissions['asset:assets:deleteown'] || $permissions['asset:assets:deleteother'], + ], + ]); ?>
output('_content'); ?>
diff --git a/app/bundles/AssetBundle/Views/Asset/list.html.php b/app/bundles/AssetBundle/Views/Asset/list.html.php index 2645d8d29ce..3f26ab517ec 100644 --- a/app/bundles/AssetBundle/Views/Asset/list.html.php +++ b/app/bundles/AssetBundle/Views/Asset/list.html.php @@ -1,13 +1,15 @@ extend('MauticAssetBundle:Asset:index.html.php'); +if ($tmpl == 'index') { + $view->extend('MauticAssetBundle:Asset:index.html.php'); +} ?>
@@ -17,7 +19,7 @@ render('MauticCoreBundle:Helper:tableheader.html.php', [ 'checkall' => 'true', - 'target' => '#assetTable' + 'target' => '#assetTable', ]); echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ @@ -25,28 +27,28 @@ 'orderBy' => 'a.title', 'text' => 'mautic.core.title', 'class' => 'col-asset-title', - 'default' => true + 'default' => true, ]); echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'sessionVar' => 'asset', 'orderBy' => 'c.title', 'text' => 'mautic.core.category', - 'class' => 'visible-md visible-lg col-asset-category' + 'class' => 'visible-md visible-lg col-asset-category', ]); echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'sessionVar' => 'asset', 'orderBy' => 'a.downloadCount', 'text' => 'mautic.asset.asset.thead.download.count', - 'class' => 'visible-md visible-lg col-asset-download-count' + 'class' => 'visible-md visible-lg col-asset-download-count', ]); echo $view->render('MauticCoreBundle:Helper:tableheader.html.php', [ 'sessionVar' => 'asset', 'orderBy' => 'a.id', 'text' => 'mautic.core.id', - 'class' => 'visible-md visible-lg col-asset-id' + 'class' => 'visible-md visible-lg col-asset-id', ]); ?> @@ -57,37 +59,37 @@ render('MauticCoreBundle:Helper:list_actions.html.php', [ - 'item' => $item, + 'item' => $item, 'templateButtons' => [ - 'edit' => $security->hasEntityAccess($permissions['asset:assets:editown'], $permissions['asset:assets:editother'], $item->getCreatedBy()), - 'delete' => $security->hasEntityAccess($permissions['asset:assets:deleteown'], $permissions['asset:assets:deleteother'], $item->getCreatedBy()), - 'clone' => $permissions['asset:assets:create'], + 'edit' => $security->hasEntityAccess($permissions['asset:assets:editown'], $permissions['asset:assets:editother'], $item->getCreatedBy()), + 'delete' => $security->hasEntityAccess($permissions['asset:assets:deleteown'], $permissions['asset:assets:deleteother'], $item->getCreatedBy()), + 'clone' => $permissions['asset:assets:create'], ], - 'routeBase' => 'asset', - 'langVar' => 'asset.asset', - 'nameGetter' => 'getTitle', + 'routeBase' => 'asset', + 'langVar' => 'asset.asset', + 'nameGetter' => 'getTitle', 'customButtons' => [ [ 'attr' => [ 'data-toggle' => 'ajaxmodal', 'data-target' => '#AssetPreviewModal', - 'href' => $view['router']->path('mautic_asset_action', ['objectAction' => 'preview', 'objectId' => $item->getId()]) + 'href' => $view['router']->path('mautic_asset_action', ['objectAction' => 'preview', 'objectId' => $item->getId()]), ], 'btnText' => $view['translator']->trans('mautic.asset.asset.preview'), - 'iconClass' => 'fa fa-image' - ] - ] + 'iconClass' => 'fa fa-image', + ], + ], ]); ?>
render('MauticCoreBundle:Helper:publishstatus_icon.html.php', [ - 'item' => $item, - 'model' => 'asset.asset' + 'item' => $item, + 'model' => 'asset.asset', ]); ?> "view", "objectId" => $item->getId()]); ?>" + ['objectAction' => 'view', 'objectId' => $item->getId()]); ?>" data-toggle="ajax"> getTitle(); ?> (getAlias(); ?>) @@ -100,7 +102,7 @@ getCategory(); ?> getTitle() : $view['translator']->trans('mautic.core.form.uncategorized'); ?> - getColor() : 'inherit'; ?> + getColor() : 'inherit'; ?> getDownloadCount(); ?> @@ -113,12 +115,12 @@ @@ -127,5 +129,5 @@ render('MauticCoreBundle:Helper:modal.html.php', [ 'id' => 'AssetPreviewModal', - 'header' => false + 'header' => false, ]); diff --git a/app/bundles/AssetBundle/Views/Asset/preview.html.php b/app/bundles/AssetBundle/Views/Asset/preview.html.php index 687ccd38d59..c9766bed461 100644 --- a/app/bundles/AssetBundle/Views/Asset/preview.html.php +++ b/app/bundles/AssetBundle/Views/Asset/preview.html.php @@ -1,9 +1,10 @@ @@ -11,14 +12,14 @@
trans('mautic.asset.asset.preview'); ?>
isImage()): ?> - <?php echo $activeAsset->getTitle(); ?> + <?php echo $activeAsset->getTitle(); ?> getFileType()) == 'pdf') : ?> - - getMime(), 'video') === 0 || in_array($activeAsset->getExtension(), array('mp4', 'webm'))): ?> + + getMime(), 'video') === 0 || in_array($activeAsset->getExtension(), ['mp4', 'webm'])): ?> - getMime(), 'audio') === 0 || in_array($activeAsset->getExtension(), array('mpg', 'mpeg', 'mp3', 'ogg', 'wav'))): ?> + getMime(), 'audio') === 0 || in_array($activeAsset->getExtension(), ['mpg', 'mpeg', 'mp3', 'ogg', 'wav'])): ?>