Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5d4adda
Showing
13 changed files
with
1,039 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Standard .gitignore for a Mautic plugin. | ||
.* | ||
!.gitignore | ||
!.htaccess | ||
!.gitkeep | ||
!.travis.yml | ||
vendor | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Standard .travis.yml for a Mautic plugin. Adjust env variables as needed. | ||
env: | ||
global: | ||
# The exact plugin folder/bundle name. | ||
- "MAUTIC_PLUGIN=MauticApiServicesBundle" | ||
|
||
dist: precise | ||
|
||
language: php | ||
|
||
services: | ||
- mysql | ||
|
||
php: | ||
- 5.6.19 | ||
- 7.0 | ||
- 7.1 | ||
|
||
before_install: | ||
|
||
# Create mautictest database. | ||
- mysql -e 'CREATE DATABASE mautictest;' | ||
|
||
# Turn off XDebug. | ||
- phpenv config-rm xdebug.ini || return | ||
|
||
# Install dependencies in parallel. | ||
- travis_retry composer global require hirak/prestissimo | ||
|
||
# Set to test environment for Symfony's commands in post install commands. | ||
- export SYMFONY_ENV="test" | ||
|
||
# Install PHPSTAN for PHP 7+ | ||
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then composer global require phpstan/phpstan-shim:0.8.5; fi | ||
|
||
# Clone the latest core release. | ||
- git clone -b staging --single-branch --depth 1 https://github.com/mautic/mautic.git /tmp/mautic | ||
|
||
# Combine core with our plugin. | ||
- mkdir -p /tmp/mautic/plugins/$MAUTIC_PLUGIN | ||
- rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/ /tmp/mautic/plugins/$MAUTIC_PLUGIN | ||
- rsync -r --delete-after --quiet /tmp/mautic/ $TRAVIS_BUILD_DIR/ | ||
|
||
install: | ||
|
||
# Install core and include any plugin dependencies. | ||
- composer config extra.merge-plugin.include "./plugins/**/composer.json" | ||
- composer require wikimedia/composer-merge-plugin | ||
- composer update wikimedia/composer-merge-plugin | ||
|
||
script: | ||
|
||
# Run PHPUnit including core tests to find potential BC breaks. | ||
- bin/phpunit -d memory_limit=2048M --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --fail-on-warning | ||
|
||
# Run PHPSTAN analysis for PHP 7+ only in the scope of this plugin. | ||
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then ~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse plugins/$MAUTIC_PLUGIN; fi | ||
|
||
# Check code standards for PHP 7.1 only in the scope of this plugin. | ||
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then bin/php-cs-fixer fix -v --dry-run --diff plugins/$MAUTIC_PLUGIN; fi |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2014 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace MauticPlugin\MauticSegmentExtrasBundle\Controller; | ||
|
||
use Mautic\CoreBundle\Controller\CommonController; | ||
|
||
class SegmentController extends CommonController | ||
{ | ||
|
||
public function batchExportAction($segmentId = null) | ||
{ | ||
|
||
if(!$segmentId){ | ||
return $this->notFound('mautic.segmentextras.export.notfound'); | ||
} | ||
$contactIds = $this->getSegmentLeadIdsForExport($segmentId); | ||
|
||
// adjust $size for memory vs. speed | ||
$batches = array_chunk($contactIds, 100); | ||
|
||
//testing | ||
/** @var OverrideLeadRepository $contactRepo */ | ||
$contactRepo = $this->getModel('lead')->getRepository(); | ||
|
||
$fileName = sprintf('ContactsExportFromSegment%s.csv', str_replace(' ', '', $segmentId)); | ||
|
||
$response = new StreamedResponse( | ||
function () use ($contactRepo, $batches) { | ||
ini_set('max_execution_time', 0); | ||
$handle = fopen('php://output', 'w'); | ||
|
||
$fieldNames = []; | ||
foreach ($batches as $batch) { | ||
$leads = $contactRepo->getEntities( | ||
['ids' => $batch, '', 'withTotalCounts' => 0, 'withChannelRules' => 1, 'ignore_paginator' => 1] | ||
); | ||
/** | ||
* @var int | ||
* @var Lead $lead | ||
*/ | ||
foreach ($leads as $id => $lead) { | ||
if (empty($fieldNames)) { | ||
$fields = $lead->getFields(true); | ||
$columnNames = array_map( | ||
function ($f) { | ||
return $f['label']; | ||
}, | ||
$fields | ||
); | ||
$columnNames = array_merge(['Id'], $columnNames); | ||
fputcsv($handle, $columnNames); | ||
$fieldNames = array_map( | ||
function ($f) { | ||
return $f['alias']; | ||
}, | ||
$fields | ||
); | ||
} | ||
$values = [$id]; | ||
foreach ($fieldNames as $fieldName) { | ||
$values[] = $lead->getFieldValue($fieldName); | ||
} | ||
fputcsv($handle, $values); | ||
} | ||
} | ||
fclose($handle); | ||
}, | ||
200, | ||
[ | ||
'Content-Type' => 'application/csv; charset=utf-8', | ||
'Content-Disposition' => 'attachment; filename="'.$fileName.'"', | ||
] | ||
); | ||
|
||
return $response; | ||
} | ||
|
||
public function getSegmentLeadIdsForExport($segmentId) | ||
{ | ||
/** @var QueryBuilder $q */ | ||
$q = $this->get('doctrine.orm.entity_manager')->getConnection()->createQueryBuilder(); | ||
$q->select('ll.lead_id') | ||
->from('lead_list_leads', 'lll') | ||
->where( | ||
$q->expr()->eq('lll.manually_removed', ':false'), | ||
$q->expr()->eq('lll.leadlist_id', ':segmentId') | ||
) | ||
->setParameter('false', false, 'boolean') | ||
->setParameter('segmentId', $segmentId); | ||
|
||
$result = $q->execute()->fetchAll(); | ||
if (!empty($result)) { | ||
$contactIds = array_column($result, 'lead_id'); | ||
} | ||
|
||
return $contactIds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
|
||
// Load grunt tasks automatically | ||
require('load-grunt-tasks')(grunt); | ||
|
||
require('time-grunt')(grunt); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
|
||
grunt.loadNpmTasks('grunt-contrib-cssmin'); | ||
|
||
grunt.loadNpmTasks('grunt-beep'); | ||
|
||
// Define the configuration for all the tasks | ||
grunt.initConfig({ | ||
uglify: { | ||
my_target: { | ||
files: { | ||
'Assets/build/segmentextras.min.js': ['Assets/js/libraries/*.js', 'Assets/js/*.js'] | ||
} | ||
} | ||
}, | ||
cssmin: { | ||
options: { | ||
mergeIntoShorthands: false, | ||
roundingPrecision: -1, | ||
sourceMap: true, | ||
root: 'Assets/build/' | ||
}, | ||
target: { | ||
files: { | ||
'Assets/build/segmentextras.min.css': ['Assets/css/libraries/*.css', 'Assets/css/*.css'] | ||
} | ||
} | ||
}, | ||
watch: { | ||
js: { | ||
files: ['Assets/js/libraries/*.js', 'Assets/js/*.js'], | ||
tasks: ['uglify', 'beep'] | ||
}, | ||
css: { | ||
files: ['Assets/css/libraries/*.css', 'Assets/css/*.css'], | ||
tasks: ['cssmin', 'beep'] | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['uglify', 'cssmin']); | ||
}; |
Oops, something went wrong.