Merge branch 'master' into PHRAS-2196-api-stories-pagination

This commit is contained in:
Nicolas Maillat
2019-11-21 17:54:23 +01:00
committed by GitHub
482 changed files with 45299 additions and 36138 deletions

View File

@@ -1,100 +1,149 @@
version: 2 version: 2.1
orbs:
aws-ecr: circleci/aws-ecr@4.0.1
executors:
docker_build:
machine:
docker_layer_caching: true
jobs: jobs:
build: build:
working_directory: ~/alchemy-fr/Phraseanet
parallelism: 2
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
docker:
- image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
command: /sbin/init
steps:
- checkout
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run:
working_directory: ~/alchemy-fr/Phraseanet working_directory: ~/alchemy-fr/Phraseanet
command: nvm install v10.12.0 && nvm alias default v10.12.0 parallelism: 2
- run: shell: /bin/bash --login
working_directory: ~/alchemy-fr/Phraseanet environment:
command: 'sudo service memcached status || sudo service memcached start; sudo CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
redis-cli ping >/dev/null 2>&1 || sudo service redis-server start; sudo CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
service mysql status || sudo service mysql start; sudo service rabbitmq-server docker:
status || sudo service rabbitmq-server start; ' - image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
# Dependencies - image: circleci/rabbitmq:3.7.7
# This would typically go in either a build or a build-and-test job when using workflows steps:
# Restore the dependency cache - checkout
- restore_cache: - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
keys: - run:
# This branch if available working_directory: ~/alchemy-fr/Phraseanet
- v1-dep-{{ .Branch }}- command: nvm install v10.12.0 && nvm alias default v10.12.0
# Default branch if not - run:
- v1-dep-master- working_directory: ~/alchemy-fr/Phraseanet
# Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly command: 'sudo service mysql status || sudo service mysql start;'
- v1-dep- # Dependencies
# This is based on your 1.0 configuration file or project settings # This would typically go in either a build or a build-and-test job when using workflows
- run: git clone https://github.com/alanxz/rabbitmq-c # Restore the dependency cache
- run: cd rabbitmq-c && git checkout 2ca1774489328cde71195f5fa95e17cf3a80cb8a - restore_cache:
- run: cd rabbitmq-c && git submodule init && git submodule update && autoreconf -i && ./configure && make && sudo make install keys:
- run: pecl channel-update pear.php.net # This branch if available
- run: yes '' | pecl install amqp-1.9.3 - v1-dep-{{ .Branch }}-
- run: yes '' | pecl install imagick # Default branch if not
- run: sudo apt-get install libzmq-dev - v1-dep-master-
- run: yes '' | pecl install zmq-beta # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
- run: echo "extension = amqp.so" > /opt/circleci/php/$(phpenv global)/etc/conf.d/amqp.ini - v1-dep-
- run: echo "extension = zmq.so" > /opt/circleci/php/$(phpenv global)/etc/conf.d/zmq.ini # This is based on your 1.0 configuration file or project settings
- run: echo "date.timezone = UTC" > /opt/circleci/php/$(phpenv global)/etc/conf.d/timezone.ini - run: echo 127.0.0.1 redis elasticsearch db rabbitmq | sudo tee -a /etc/hosts
- run: sed -i 's/^\(session.cache_limiter = \).*/\1""/' /opt/circleci/php/$(phpenv global)/etc/php.ini - run: git clone https://github.com/alanxz/rabbitmq-c
- run: npm rebuild node-sass - run: cd rabbitmq-c && git checkout 2ca1774489328cde71195f5fa95e17cf3a80cb8a
# This is based on your 1.0 configuration file or project settings - run: cd rabbitmq-c && git submodule init && git submodule update && autoreconf -i && ./configure && make && sudo make install
- run: composer install --no-progress --no-interaction --optimize-autoloader # disabled because pear.php.net is down cause of security failure
# This is based on your 1.0 configuration file or project settings #- run: pecl channel-update pear.php.net
- run: node -v - run: yes '' | pecl install amqp-1.9.3
- run: npm -v - run: yes '' | pecl install imagick
- run: npm install - run: sudo apt-get install libzmq-dev
- run: if [[ ! -e elasticsearch-2.3.3 ]]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.3.tar.gz && tar -xvf elasticsearch-2.3.3.tar.gz && elasticsearch-2.3.3/bin/plugin install analysis-icu; fi - run: yes '' | pecl install zmq-beta
- run: - run: echo "extension = amqp.so" > /opt/circleci/php/$(phpenv global)/etc/conf.d/amqp.ini
command: elasticsearch-2.3.3/bin/elasticsearch - run: echo "extension = zmq.so" > /opt/circleci/php/$(phpenv global)/etc/conf.d/zmq.ini
background: true - run: echo "date.timezone = UTC" > /opt/circleci/php/$(phpenv global)/etc/conf.d/timezone.ini
# Save dependency cache - run: sed -i 's/^\(session.cache_limiter = \).*/\1""/' /opt/circleci/php/$(phpenv global)/etc/php.ini
- save_cache: - run: npm rebuild node-sass
key: v1-dep-{{ .Branch }}-{{ epoch }} # This is based on your 1.0 configuration file or project settings
paths: - run: composer install --no-progress --no-interaction --optimize-autoloader
# This is a broad list of cache paths to include many possible development environments # This is based on your 1.0 configuration file or project settings
# You can probably delete some of these entries - run: node -v
- vendor/bundle - run: npm -v
- ~/virtualenvs - run: npm install -g yarn
- ~/.m2 - run: rm ~/.yarn/bin/yarn
- ~/.ivy2 - run: ln -s /opt/circleci/nodejs/v10.12.0/bin/yarn ~/.yarn/bin/yarn
- ~/.bundle - run: yarn install
- ~/.go_workspace - run: if [[ ! -e elasticsearch-2.3.3 ]]; then wget --no-check-certificate https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.3.tar.gz && tar -xvf elasticsearch-2.3.3.tar.gz && elasticsearch-2.3.3/bin/plugin install analysis-icu; fi
- ~/.gradle - run:
- ~/.cache/bower command: elasticsearch-2.3.3/bin/elasticsearch
# These cache paths were specified in the 1.0 config background: true
- elasticsearch-2.3.3 # Save dependency cache
- node_modules - save_cache:
- ~/.composer key: v1-dep-{{ .Branch }}-{{ epoch }}
# This is based on your 1.0 configuration file or project settings paths:
- run: mysql -u ubuntu -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;'; # This is a broad list of cache paths to include many possible development environments
# This is based on your 1.0 configuration file or project settings # You can probably delete some of these entries
- run: ./bin/developer system:uninstall -v - vendor/bundle
- run: ./bin/setup system:install -v --email=test@phraseanet.com --password=test --db-host=127.0.0.1 --db-user=ubuntu --db-template=fr-simple --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y; - ~/virtualenvs
- run: ./bin/developer ini:setup-tests-dbs -v - ~/.m2
- run: ./bin/console searchengine:index:create -v - ~/.ivy2
- run: ./bin/developer phraseanet:regenerate-sqlite -v - ~/.bundle
- run: ./bin/developer phraseanet:generate-js-fixtures -v - ~/.go_workspace
# Test - ~/.gradle
# This would typically be a build job when using workflows, possibly combined with build - ~/.cache/bower
# This is based on your 1.0 configuration file or project settings # These cache paths were specified in the 1.0 config
- run: case $CIRCLE_NODE_INDEX in 0) EXIT=0; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-unit.xml --exclude-group legacy || EXIT=$?; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-no-web.xml --group legacy --exclude-group web || EXIT=$?; exit $EXIT;; 1) php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-web.xml --group web ;; esac - elasticsearch-2.3.3
# Teardown - node_modules
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each - ~/.composer
# Save test results # This is based on your 1.0 configuration file or project settings
- store_test_results: - run: mysql -u ubuntu -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;';
path: /tmp/circleci-test-results # This is based on your 1.0 configuration file or project settings
# Save artifacts - run: ./bin/developer system:uninstall -v
- store_artifacts: - run: ./bin/setup system:install -v --email=test@phraseanet.com --password=test --db-host=127.0.0.1 --db-user=ubuntu --db-template=fr-simple --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y;
path: /tmp/circleci-artifacts - run: ./bin/developer ini:setup-tests-dbs -v
- store_artifacts: - run: ./bin/console searchengine:index:create -v
path: /tmp/circleci-test-results - run: ./bin/developer phraseanet:regenerate-sqlite -v
- run: ./bin/developer phraseanet:generate-js-fixtures -v
# Test
# This would typically be a build job when using workflows, possibly combined with build
# This is based on your 1.0 configuration file or project settings
- run: case $CIRCLE_NODE_INDEX in 0) EXIT=0; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-unit.xml --exclude-group legacy || EXIT=$?; php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-no-web.xml --group legacy --exclude-group web || EXIT=$?; exit $EXIT;; 1) php -d memory_limit=-1 bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit-legacy-web.xml --group web ;; esac
# Teardown
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
# Save test results
- store_test_results:
path: /tmp/circleci-test-results
# Save artifacts
- store_artifacts:
path: /tmp/circleci-artifacts
- store_artifacts:
path: /tmp/circleci-test-results
workflows:
version: 2
oldfashion:
jobs:
- build
newfashion:
jobs:
- aws-ecr/build_and_push_image:
account-url: AWS_ACCOUNT_URL
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
context: "AWS London"
create-repo: true
dockerfile: Dockerfile
extra-build-args: "--target phraseanet-fpm"
region: AWS_DEFAULT_REGION
repo: "${AWS_RESOURCE_NAME_PREFIX}/phraseanet"
tag: "alpha-0.1"
- aws-ecr/build_and_push_image:
account-url: AWS_ACCOUNT_URL
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
context: "AWS London"
create-repo: true
dockerfile: Dockerfile
extra-build-args: "--target phraseanet-nginx"
region: AWS_DEFAULT_REGION
repo: "${AWS_RESOURCE_NAME_PREFIX}/phraseanet-nginx"
tag: "alpha-0.1"
- aws-ecr/build_and_push_image:
account-url: AWS_ACCOUNT_URL
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
context: "AWS London"
create-repo: true
dockerfile: Dockerfile
extra-build-args: "--target phraseanet-worker"
region: AWS_DEFAULT_REGION
repo: "${AWS_RESOURCE_NAME_PREFIX}/phraseanet"
tag: "alpha-0.1"

4
.gitignore vendored
View File

@@ -21,7 +21,7 @@
!/config/configuration.sample.yml !/config/configuration.sample.yml
# Exclude generated proxies from doctrine2 # Exclude generated proxies from doctrine2
/resources/proxies #/resources/proxies
# Exclude temporaries resources (zip files, quarantine documents etc ..) folder # Exclude temporaries resources (zip files, quarantine documents etc ..) folder
/tmp /tmp
@@ -69,3 +69,5 @@ grammar/jison-*
pimple.json pimple.json
playbook.retry playbook.retry
npm-debug.log npm-debug.log
/Phrasea_datas

45
AUTHORS
View File

@@ -1,30 +1,43 @@
** Phraseanet is written and maintained by the Phraseanet Developer Team ** ** Phraseanet is written and maintained by the Phraseanet Developer Team **
Benoît Burnichon - Jean-Yves Gaulier
Jean-Yves Gaulier - Milos M
Andrey Kalinovsky - Mike NG
Nicolas Legoff - Xavier Rousset
Romain Neutron - Aina Sitraka
- Filip Vilic
** Proudly Powered by Alchemy ** ** Proudly Powered by Alchemy **
Nicolas Amendola - Aurélie Bachelet
Nathanaël Attar - Laetitia Bianchi
Aurélie Bachelet - Anthony Cabot
Anthony Cabot - Moctar Diouf
Moctar Diouf - Jennifer Guérin
Jennifer Guérin - Félix Noir
Nicolas Honoré - Nicolas Maillat
Nicolas Maillat - Guillaume Maubert
Guillaume Maubert
Jonathan Schneider
** They gave some love to Phraseanet ** ** They gave some love to Phraseanet **
Ysoline Gresille - Nicolas Amendola
- Nathanaël Attar
- Florian Blouet
- Benoît Burnichon
- Thibaud Fabre
- Ysoline Gresille
- Nicolas Honoré
- Andrey Kalinovsky
- Nicolas Legoff
- Romain Neutron
- Jonathan Schneider
Phraseanet c/o Alchemy Phraseanet c/o Alchemy
30 Place Saint Georges 30 Place Saint Georges
75009 Paris - France 75009 Paris - France
+33 1 53 20 43 80 +33 1 53 20 43 80
info@alchemy.fr info@alchemy.fr

View File

@@ -1,14 +1,140 @@
# CHANGELOG # CHANGELOG
## 4.0.9
## 4.0.0 (xxxx-xx-xx) ### Adds
- Convert Orders custom adapter to Doctrine entity. - PHRAS-2535 - Back / Front - Unsubscription: It's now possible to request a validation by email to delete a Phraseanet user account.
- Convert Feeds custom adapter to Doctrine entity. - PHRAS-2480 - Back / Front - It's now possible to add a user model as order manager on a collection:All users with this model applied can manage orders on this collection. This features fixes an issue when users is provided by SAML and the orders manager is lost when user logs in.
- Convert Users custom adapter to Doctrine entity. - PHRAS-2474 - Back / front. - Searched terms are now found even if the searched terms are split in Business Field and regular Field.
- Convert Ftp Export custom adapter to Doctrine entity. - PHRAS-2462 - Front - Share media on LinkedIn as you can do on Facebook, Twitter.
- Convert Ftp Export custom adapter to Doctrine entity. - PHRAS-2417 - Front - Skin: grey and white, graphic enhancements.
- Session management is now part of Phraseanet configuration. - PHRAS-2067 - Front - Introducing thumbnail & preview generic images for Fonts
### Fixes
* PHRAS-2491 - Front - Click on facets title (expand/collapse) launched a bad query, due to jquery error.
* PHRAS-2510 - Front - Facets values appear Truncated after 15th character.
* PHRAS-2153 - Front - No user search possible with the field "Company" and field "Country".
* PHRAS-2154 - Front - Bug on Chrome only - selected 1 document instead of all for the feedback.
* PHRAS-2538 - Back - Some MP4 files were not correctly detected by Phraseanet.
## 4.0.8
### Adds:
- Upload: Distant files can be added via their URL in GUI and by API. Phraseanet downloads the file before archiving it.
- Search optimisation when searching in full text, there was a problem when the query mixed different types of fields.
- Search optimisation, its now possible to search a partial date in full text.
- Populate optimisation, now populating time: 3 times faster.
- It is now possible to migrate from 3.1 3.0 version to 4.X, without an intermediate step in 3.8.Fix:
### Fixes
- Search filter were not taken into account due to a bug in JS.
- Overlay title: In this field, text was repeated twice if : one or several words were highlighted in the field, and if the title contained more than 102 characters.
- List Manager: it was impossible to add users in the list manager after page 3.
- List of fields was not refreshed in the exported fields section.
- Push and Feedback fix error when adding a user when Geonames was not set (null value in Geonames).
## 4.0.7
### Adds:
- Advanced search refacto
- Thesaurus search is now in strict mode
- Refactoring of report module
- Refactoring query storage and changing strategy for field search restriction
- It is now possible to search for terms in thesaurus and candidates in all languages, not only on the login language
- Enhancements on archive task
- Graphic enhancements for menu and icons
- Video file enhancement, support of MXF container
- Extraction of a video soundtrack (MP3, MP4, WAVE, etc.)
- For Office Documents, all generated subviews will be PDF assets by default. The flexpaper preview still exists but will be optional.
- In Prod Gui, there will be 5 facets but the possibility to view more.
### Fixes:
- Quarantine: Fix for the “Substitute” action: alert when selection is empty
- Quarantine: File name with a special character cant be added
- Fix for the Adobe CC default token
- XSS vulnerabilities in Prod, Admin & Lightbox. Many thanks to Kris (@HV_hat_)
- PDF containing (XMP-xmp:PageImage) fails generating subview
- MIME types are trucated
-Vagrant dev environment fix
- Feedback: Sort assets “Order by best choice” has no effect
## 4.0.3
### Adds:
- Prod: For a record, show the current day in the statistics section of the detailed view.
- Prod: Store state (open or closed) of facet answer. eg: Database or collection, store in session.
- Admin: Access to scheduler and task local menu when parameter is set to false in .yml configuration.
- Prod: Database, collection and document type facets are fixed on top
- Prod: Better rendering for values of exposure, shutter speed and flash status in facets. eg for shutter speed: 1/30 instead of 0,0333333.
- Versions 4 are now compliant with the Phraseanet plugins for Adobe CC Suite.
- White list mode: extending autoregistration and adding wildcard access condition by mail domain. Automatically grant access to a user according to the email entered in the request.
- Find your documents from the colors in the facets (AI plugin)
- Generate a PDF from a Word document or a picture, its now possible to define a pdf subview type
- Specify a temporary work repository for building video subdefs, to accelerate video generation.
### Fixes:
- Prod: In Upload, correct status are not loaded
- Prod:Arrow keys navigation adds last selected facet as filter
- Admin:Subdef presets, sizes and bitrates (bits/s) not OK
- Admin: App error on loading in French due to a simple quote
- Prod: Deletion message is not fully readable when deleting a story
- Fixing highlight with Elasticsearch for full text only, not for the thesaurus
- 500 error at the first authentication for a user with the SAML Phraseanet pluginDev
- Dev: Fix API version returned in answer
- Dev: Fix vagrant provisioning for Windows
## 4.0.2
### Adds:
- Prod: Message Improv, when selected records are in Trash and another one.
- Prod: alt-click on active facets (filter) to invert it.
- Prod: do not erase facets in filter when returning 0 answers.
- Core: Add preference to authorize user connection without an email
- Core: Add preference to set default validity period of download link
### Fixes:
- Thesaurus: 0 character terms are blocked
- Admin: fix action create and drop index from elasticsearch
- Prod: Fix advanced sarch: no filters possible on fields using IE
- Prod: 500 error in publication reader when record is missing (deleted from db)Unit test: fix error in Json serialization for custom link
- Prod: fix field list in advanced search with Edge browser
- Upload: fix 500 error when missing collection
- Install wizard: fix error in graphical installer
## 4.0.0
### Adds:
#### Phraseanet gets a new search engine: Elasticsearch
- Faceted navigation enables to create a “mapping” of the response. Browse in a very intuitive way by creating several associations of filters. Facets can be used on the databases, collections, documentary fields and technical data.
- Speed of processing search and results display has been improved
- Possibility to use Kibana (open source visualization plugin for Elasticsearch)
#### API enhancement
- New API routes are available (orders, facets, quarantine)
- Enhancement of new, faster routes
#### Redesign of the Prod interface
- Enhanced, redesigned ergonomics: the detailed view windows; redesign of the workzone (baskets and stories, facets, webgalleries)
- New white and grey skins are now available
- New order manager
#### Other
- Permalinks sharing: activate/deactivate sharing links for the document and sub resolutions
- New: the applicative trash: you can now define a collection named _TRASH_. Then, all deleted records from collections (except from Trash) go to the Trash collection. Permalinks on subdefs are deactivated. When you delete a record from the Trash collection, it is permanently deleted. When you move a record from the Trash collection to another, the permalinks are reactivated.
- Rewriting of the task scheduler based on the web sockets
- Quarantine enhancement
- Drag and drop upload
## 3.8.8 (2015-12-02) ## 3.8.8 (2015-12-02)

View File

@@ -1,3 +1,7 @@
#version 4.0
- Krzysztof Szulski Security
- Ideepix Docker Deploiement
#version 3.7 #version 3.7
- Pieter Demonie (Dutch localization) - Pieter Demonie (Dutch localization)

181
Dockerfile Normal file
View File

@@ -0,0 +1,181 @@
FROM php:7.0-fpm-stretch as builder
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
ca-certificates \
gnupg2 \
&& apt-get update \
&& apt-get install -y --no-install-recommends zlib1g-dev \
git \
ghostscript \
gpac \
imagemagick \
libav-tools \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
librabbitmq-dev \
libssl-dev \
libxslt-dev \
libzmq3-dev \
locales \
mcrypt \
swftools \
unoconv \
unzip \
xpdf \
&& update-locale "LANG=fr_FR.UTF-8 UTF-8" \
&& dpkg-reconfigure --frontend noninteractive locales \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip exif iconv mbstring pcntl sockets xsl intl pdo_mysql gettext bcmath mcrypt \
&& pecl install redis amqp-1.9.3 zmq-beta imagick-beta \
&& docker-php-ext-enable redis amqp zmq imagick \
&& pecl clear-cache \
&& docker-php-source delete \
&& rm -rf /var/lib/apt/lists/*
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
# Node Installation (node + yarn)
# Reference :
# https://linuxize.com/post/how-to-install-node-js-on-ubuntu-18.04/
# https://yarnpkg.com/lang/en/docs/install/#debian-stable
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y --no-install-recommends yarn \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/
RUN mkdir /entrypoint /var/alchemy \
&& useradd -u 1000 app \
&& mkdir -p /home/app/.composer \
&& chown -R app: /home/app /var/alchemy
WORKDIR /var/alchemy/
COPY gulpfile.js /var/alchemy/
COPY Makefile /var/alchemy/
COPY package.json /var/alchemy/
COPY phpunit.xml.dist /var/alchemy/
COPY yarn.lock /var/alchemy/
COPY bin /var/alchemy/bin
COPY composer.json /var/alchemy/
COPY composer.lock /var/alchemy/
RUN make install_composer
COPY resources /var/alchemy/resources
COPY www /var/alchemy/www
RUN make clean_assets
RUN make install_asset_dependencies
RUN make install_assets
ADD ./docker/phraseanet/ /
COPY lib /var/alchemy/lib
COPY tmp /var/alchemy/tmp
COPY config /var/alchemy/config
COPY grammar /var/alchemy/grammar
COPY templates-profiler /var/alchemy/templates-profiler
COPY templates /var/alchemy/templates
COPY tests /var/alchemy/tests
RUN mkdir -p /var/alchemy/Phraseanet/logs \
&& chmod -R 777 /var/alchemy/Phraseanet/logs \
&& mkdir -p /var/alchemy/Phraseanet/cache \
&& chmod -R 777 /var/alchemy/Phraseanet/cache \
&& mkdir -p /var/alchemy/Phraseanet/datas \
&& chmod -R 777 /var/alchemy/Phraseanet/datas \
&& mkdir -p /var/alchemy/Phraseanet/tmp \
&& chmod -R 777 /var/alchemy/Phraseanet/tmp \
&& mkdir -p /var/alchemy/Phraseanet/www/custom \
&& chmod -R 777 /var/alchemy/Phraseanet/www/custom \
&& mkdir -p /var/alchemy/Phraseanet/config \
&& chmod -R 777 /var/alchemy/Phraseanet/config
# Phraseanet
FROM php:7.0-fpm-stretch as phraseanet-fpm
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
ca-certificates \
gnupg2 \
&& apt-get update \
&& apt-get install -y --no-install-recommends zlib1g-dev \
gettext \
git \
ghostscript \
gpac \
imagemagick \
libav-tools \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
librabbitmq-dev \
libssl-dev \
libxslt-dev \
libzmq3-dev \
locales \
mcrypt \
swftools \
unoconv \
unzip \
xpdf \
&& update-locale "LANG=fr_FR.UTF-8 UTF-8" \
&& dpkg-reconfigure --frontend noninteractive locales \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip exif iconv mbstring pcntl sockets xsl intl pdo_mysql gettext bcmath mcrypt \
&& pecl install redis amqp-1.9.3 zmq-beta imagick-beta \
&& docker-php-ext-enable redis amqp zmq imagick \
&& pecl clear-cache \
&& docker-php-source delete \
&& rm -rf /var/lib/apt/lists/*
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
# Node Installation (node + yarn)
# Reference :
# https://linuxize.com/post/how-to-install-node-js-on-ubuntu-18.04/
# https://yarnpkg.com/lang/en/docs/install/#debian-stable
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
&& apt install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y --no-install-recommends yarn \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/
RUN mkdir /entrypoint /var/alchemy \
&& useradd -u 1000 app \
&& mkdir -p /home/app/.composer \
&& chown -R app: /home/app /var/alchemy
COPY --from=builder --chown=app /var/alchemy /var/alchemy/Phraseanet
ADD ./docker/phraseanet/ /
WORKDIR /var/alchemy/Phraseanet
ENTRYPOINT ["/phraseanet-entrypoint.sh"]
CMD ["/boot.sh"]
# phraseanet-worker
FROM phraseanet-fpm as phraseanet-worker
CMD ["/worker-boot.sh"]
# phraseanet-nginx
FROM nginx:1.15 as phraseanet-nginx
RUN useradd -u 1000 app
ADD ./docker/nginx/ /
COPY --from=builder /var/alchemy/www /var/alchemy/Phraseanet/www
CMD ["/boot.sh"]

18
Dockerfile-debug Normal file
View File

@@ -0,0 +1,18 @@
ARG phraseanet
FROM $phraseanet
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
iproute2 \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& pecl clear-cache
ADD ./docker/phraseanet-debug/ /
RUN chmod +x /entrypoint.sh /usr/local/bin/docker-*
ENTRYPOINT ["/entrypoint.sh"]
CMD ["php-fpm"]

View File

@@ -5,20 +5,18 @@ install:
make install_assets make install_assets
install_composer: install_composer:
composer install composer install --ignore-platform-reqs
install_asset_dependencies: install_asset_dependencies:
yarn upgrade yarn install
./node_modules/.bin/gulp build ./node_modules/.bin/gulp build
install_assets: install_assets:
./node_modules/.bin/gulp install-assets ./node_modules/.bin/gulp install-assets
clean_assets: clean_assets:
rm -rf ./node_modules
rm -rf ./www/assets rm -rf ./www/assets
mkdir ./node_modules rm -Rf ./cache/*
touch ./node_modules/.gitkeep
config: config:
@php bin/console compile:configuration @php bin/console compile:configuration

View File

@@ -1,15 +1,18 @@
Phraseanet 4.0 - Digital Asset Management application Phraseanet 4.1 - Digital Asset Management application
===================================================== =====================================================
[![CircleCI](https://circleci.com/gh/alchemy-fr/Phraseanet/tree/master.svg?style=shield)](https://circleci.com/gh/alchemy-fr/Phraseanet/tree/master) [![CircleCI](https://circleci.com/gh/alchemy-fr/Phraseanet/tree/master.svg?style=shield)](https://circleci.com/gh/alchemy-fr/Phraseanet/tree/master)
# Features : # Features :
- Metadata Management (include Thesaurus and DublinCore Mapping) - Metadata Management (include Thesaurus and DublinCore Mapping)
- RestFull APIS (See Developer Documentation https://docs.phraseanet.com/Devel) - RestFull APIS
- Bridge to Youtube/Dailymotion/Flickr - Elasticsearch search engine
- Multiple resolution assets generation
# License :
Phraseanet is licensed under GPL-v3 license.
# Documentation : # Documentation :
@@ -21,16 +24,51 @@ You **must** not download the source from GitHub, but download a packaged versio
https://www.phraseanet.com/download/ https://www.phraseanet.com/download/
And follow the install steps described at https://docs.phraseanet.com/Admin/ And follow the install steps described at https://docs.phraseanet.com/4.0/en/Admin/Install.html
# Try Phraseanet :
You can also download a testing pre installed Virtual Machine in OVA format here :
https://www.phraseanet.com/download/
# Development : # Development :
For development purpose Phraseanet is shipped with ready to use development environments using vagrant. For development purpose Phraseanet is shipped with ready to use development environments using vagrant.
You can easily choose betweeen a complete build or a prebuild box, with a specific PHP version.
See https://docs.phraseanet.com/Devel/ git clone
vagrant up --provision
# License : then, a prompt allow you to choose PHP version, and another one to choose a complete build or an Alchemy prebuilt boxes.
Phraseanet is licensed under GPL-v3 license. Ex:
- vagrant up --provision //// 5.6 ///// 1 >> Build an ubuntu/xenial box with php5.6
- vagrant up --provision //// 7.0 ///// 1 >> Build an ubuntu/xenial with php7.0
- vagrant up --provision //// 7.2 ///// 2 >> Build the alchemy/phraseanet-php-7.2 box
- vagrant up --provision //// 5.6 ///// 1 >> Build the alchemy/phraseanet-php-5.6 box
For development with Phraseanet API see https://docs.phraseanet.com/4.0/en/Devel/index.html
# Docker build
WARNING : still in a work-in-progress status and can be used only for test purposes.
The docker distribution come with 3 differents containers :
* An nginx that act as the front http server.
* The php-fpm who serves the php files through nginx.
* The worker who execute Phraseanet scheduler.
## How to build
You can build all the images with the following command at the root directory, choosing an arbirary TAG name :
./build.sh <TAG>
It will build and tag the following images :
local/phraseanet-worker:<TAG>
local/phraseanet-fpm:<TAG>
local/phraseanet-nginx:<TAG>

108
Vagrantfile vendored
View File

@@ -1,16 +1,6 @@
Vagrant.require_version ">= 1.5" Vagrant.require_version ">= 1.5"
require 'json'
class MyCustomError < StandardError
attr_reader :code
def initialize(code)
@code = code
end
def to_s
"[#{code} #{super}]"
end
end
# Check to determine whether we're on a windows or linux/os-x host, # Check to determine whether we're on a windows or linux/os-x host,
# later on we use this to launch ansible in the supported way # later on we use this to launch ansible in the supported way
# source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby # source: https://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
@@ -34,15 +24,62 @@ else if which('ifconfig')
end end
end end
$php = [ "5.6", "7.0", "7.1", "7.2" ]
$phpVersion = ENV['phpversion'] ? ENV['phpversion'] : "5.6";
unless Vagrant.has_plugin?('vagrant-hostmanager') unless Vagrant.has_plugin?('vagrant-hostmanager')
raise "vagrant-hostmanager is not installed! Please run\n vagrant plugin install vagrant-hostmanager\n\n" raise "vagrant-hostmanager is not installed! Please run\n vagrant plugin install vagrant-hostmanager\n\n"
end end
unless $php.include?($phpVersion) # Check to determine if box_meta JSON is present
raise "You should specify php version before running vagrant\n\n (Available : 5.6, 7.0, 7.1, 7.2 | default => 5.6)\n\n Exemple: phpversion='7.0' vagrant up \n\n" # if provisionned : pick name of box
if File.file?(".vagrant/machines/default/virtualbox/box_meta")
data = File.read(".vagrant/machines/default/virtualbox/box_meta")
parsed_json = JSON.parse(data)
$box = parsed_json["name"]
end
# if not : run prompt to configure provisioning
if !File.file?(".vagrant/machines/default/virtualbox/box_meta") && ARGV[0] == 'up'
print "\033[34m \nChoose a Build type :\n\n(1) Use prebuilt Phraseanet Box\n(2) Build Phraseanet from scratch (xenial)\n\033[00m"
type = STDIN.gets.chomp
print "\n"
# Switch between Phraseanet box and native trusty64
case (type)
when '1'
$box = "alchemy/Phraseanet-vagrant-dev_php"
$playbook = "resources/ansible/playbook-boxes.yml"
when '2'
$box = "ubuntu/xenial64"
$playbook = "resources/ansible/playbook.yml"
else
raise "\033[31mYou should specify Build type before running vagrant\n\n (Available : 1, 2)\n\n\033[00m"
end
print "\033[32m-----------------------------------------------\n"
print "Build with "+$box+" box\n"
print "-----------------------------------------------\n\n\033[00m"
print "\033[34mChoose a PHP version for your build (Available : 5.6, 7.0, 7.1, 7.2)\n\033[00m"
phpversion = STDIN.gets.chomp
print "\n"
# Php version selection
case (phpversion)
when "5.6", "7.0", "7.1", "7.2"
print "\033[32mSelected PHP version : "+phpversion+"\n\033[00m"
print "Continue ? (Y/n) \n"
continue = STDIN.gets.chomp
case continue
when 'n', 'no', 'N', 'NO'
raise "\033[31mBuild aborted\033[00m"
else
if (type == '1')
$box.concat(phpversion)
end
print "\033[32m-----------------------------------------------\n"
print "Build with PHP"+phpversion+"\n"
print "-----------------------------------------------\n\n\033[00m"
end
else
raise "\033[31mYou should specify php version before running vagrant\n\n (Available : 5.6, 7.0, 7.1, 7.2)\n\n\033[00m"
end
end end
$root = File.dirname(File.expand_path(__FILE__)) $root = File.dirname(File.expand_path(__FILE__))
@@ -70,6 +107,9 @@ def config_net(config)
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"] vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end end
end end
config.vm.network :public_network, bridge:"en0: Ethernet"
config.hostmanager.ip_resolver = proc do |vm, resolving_vm| config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
if vm.id if vm.id
if $env == "mac" || $env == "linux" if $env == "mac" || $env == "linux"
@@ -92,8 +132,6 @@ else if $env == "linux"
$hostIps = `ifconfig | sed -nE 's/[[:space:]]*inet ([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})(.*)$/\\1/p'`.split("\n"); $hostIps = `ifconfig | sed -nE 's/[[:space:]]*inet ([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})(.*)$/\\1/p'`.split("\n");
else else
$hostIps = `resources/ansible/inventories/GetIpAdresses.cmd`; $hostIps = `resources/ansible/inventories/GetIpAdresses.cmd`;
# raise MyCustomError.new($hostIps), "HOST IP"
end end
end end
@@ -116,26 +154,28 @@ Vagrant.configure("2") do |config|
] ]
end end
config.vm.box = "ubuntu/trusty64" config.vm.box = $box
config.ssh.forward_agent = true config.ssh.forward_agent = true
config_net(config) config_net(config)
# If ansible is in your path it will provision from your HOST machine # If ansible is in your path it will provision from your HOST machine
# If ansible is not found in the path it will be instaled in the VM and provisioned from there # If ansible is not found in the path it will be instaled in the VM and provisioned from there
if which('ansible-playbook') if which('ansible-playbook')
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "resources/ansible/playbook.yml" if $playbook
ansible.limit = 'all' config.vm.provision "ansible_local" do |ansible|
ansible.verbose = 'vvv' ansible.playbook = $playbook
ansible.extra_vars = { ansible.limit = 'all'
hostname: $hostname, ansible.verbose = 'vvv'
host_addresses: $hostIps, ansible.extra_vars = {
phpversion: $phpVersion, hostname: $hostname,
postfix: { host_addresses: $hostIps,
postfix_domain: $hostname + ".vb" phpversion: phpversion,
postfix: {
postfix_domain: $hostname + ".vb"
}
} }
} end
end end
config.vm.provision "ansible_local", run: "always" do |ansible| config.vm.provision "ansible_local", run: "always" do |ansible|
@@ -148,10 +188,6 @@ Vagrant.configure("2") do |config|
} }
end end
else else
# raise MyCustomError.new([$hostname, $phpVersion, $hostIps]), "HOST IP"
# raise MyCustomError.new($hostIps), "HOST IP"
# raise MyCustomError.new($hostIps), "HOST IP"
config.vm.provision :shell, path: "resources/ansible/windows.sh", args: [$hostname, $phpVersion, $hostIps] config.vm.provision :shell, path: "resources/ansible/windows.sh", args: [$hostname, $phpVersion, $hostIps]
# config.vm.provision :shell, run: "always", path: "resources/ansible/windows-always.sh", args: ["default"] # config.vm.provision :shell, run: "always", path: "resources/ansible/windows-always.sh", args: ["default"]
end end
@@ -163,4 +199,4 @@ Vagrant.configure("2") do |config|
config.vm.synced_folder "./", "/vagrant" config.vm.synced_folder "./", "/vagrant"
end end
end end

View File

@@ -13,6 +13,7 @@ namespace KonsoleKommander;
use Alchemy\Phrasea\Command\Setup\ConfigurationEditor; use Alchemy\Phrasea\Command\Setup\ConfigurationEditor;
use Alchemy\Phrasea\Command\Setup\FixAutoincrements; use Alchemy\Phrasea\Command\Setup\FixAutoincrements;
use Alchemy\Phrasea\Command\Setup\FixLogCollId;
use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\UpgradeDBDatas; use Alchemy\Phrasea\Command\UpgradeDBDatas;
use Alchemy\Phrasea\Command\Setup\Install; use Alchemy\Phrasea\Command\Setup\Install;
@@ -23,6 +24,7 @@ use Alchemy\Phrasea\Command\Plugin\AddPlugin;
use Alchemy\Phrasea\Command\Plugin\RemovePlugin; use Alchemy\Phrasea\Command\Plugin\RemovePlugin;
use Alchemy\Phrasea\Command\Plugin\EnablePlugin; use Alchemy\Phrasea\Command\Plugin\EnablePlugin;
use Alchemy\Phrasea\Command\Plugin\DisablePlugin; use Alchemy\Phrasea\Command\Plugin\DisablePlugin;
use Alchemy\Phrasea\Command\Plugin\DownloadPlugin;
use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Command\Setup\CheckEnvironment; use Alchemy\Phrasea\Command\Setup\CheckEnvironment;
use Alchemy\Phrasea\Core\CLIProvider\DoctrineMigrationServiceProvider; use Alchemy\Phrasea\Core\CLIProvider\DoctrineMigrationServiceProvider;
@@ -49,7 +51,7 @@ $app = new CLI("
This program comes with ABSOLUTELY NO WARRANTY. This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it This is free software, and you are welcome to redistribute it
under certain conditions; type `about:license' for details.\n\n" under certain conditions; type `about:license' for details.\n\n"
. ' SETUP', $version->getName() . ' ' . $version->getNumber()); . ' SETUP', $version->getName() . ' ' . $version->getNumber());
$app->register(new DoctrineMigrationServiceProvider()); $app->register(new DoctrineMigrationServiceProvider());
@@ -69,6 +71,7 @@ if ($configurationTester->isInstalled()) {
} }
$app->command(new AddPlugin()); $app->command(new AddPlugin());
$app->command(new DownloadPlugin());
$app->command(new ListPlugin()); $app->command(new ListPlugin());
$app->command(new RemovePlugin()); $app->command(new RemovePlugin());
$app->command(new PluginsReset()); $app->command(new PluginsReset());
@@ -78,6 +81,7 @@ $app->command(new CheckEnvironment('check:system'));
$app->command(new Install('system:install', $app['phraseanet.structure-template'])); $app->command(new Install('system:install', $app['phraseanet.structure-template']));
$app->command(new CrossDomainGenerator()); $app->command(new CrossDomainGenerator());
$app->command(new FixAutoincrements('system:fix-autoincrements')); $app->command(new FixAutoincrements('system:fix-autoincrements'));
$app->command(new FixLogCollId());
$app['phraseanet.setup_mode'] = true; $app['phraseanet.setup_mode'] = true;

11
build.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
# nginx server
docker build --target phraseanet-nginx -t local/phraseanet-nginx:$1 .
# php-fpm application
docker build --target phraseanet-fpm -t local/phraseanet-fpm:$1 .
# worker
docker build --target phraseanet-worker -t local/phraseanet-worker:$1 .

View File

@@ -47,10 +47,10 @@
"php": ">=5.5.9", "php": ">=5.5.9",
"ext-intl": "*", "ext-intl": "*",
"alchemy-fr/tcpdf-clone": "~6.0", "alchemy-fr/tcpdf-clone": "~6.0",
"alchemy/embed-bundle": "^0.3.4", "alchemy/embed-bundle": "^2.0.7",
"alchemy/geonames-api-consumer": "~0.1.0", "alchemy/geonames-api-consumer": "~0.1.0",
"alchemy/mediavorus": "^0.4.4", "alchemy/mediavorus": "^0.4.4",
"alchemy/oauth2php": "1.0.0", "alchemy/oauth2php": "1.1.0",
"alchemy/phlickr": "0.2.9", "alchemy/phlickr": "0.2.9",
"alchemy/phpexiftool": "^0.7.0", "alchemy/phpexiftool": "^0.7.0",
"alchemy/rest-bundle": "^0.0.5", "alchemy/rest-bundle": "^0.0.5",
@@ -78,7 +78,6 @@
"hoa/router": "~2.0", "hoa/router": "~2.0",
"igorw/get-in": "~1.0", "igorw/get-in": "~1.0",
"imagine/imagine": "0.6.x-dev", "imagine/imagine": "0.6.x-dev",
"ircmaxell/random-lib": "~1.0",
"jms/serializer": "~0.10", "jms/serializer": "~0.10",
"jms/translation-bundle": "dev-rebase-2015-10-20", "jms/translation-bundle": "dev-rebase-2015-10-20",
"justinrainbow/json-schema": "2.0.3 as 1.6.1", "justinrainbow/json-schema": "2.0.3 as 1.6.1",
@@ -119,10 +118,13 @@
"alchemy/worker-bundle": "^0.1.6", "alchemy/worker-bundle": "^0.1.6",
"alchemy/queue-bundle": "^0.1.5", "alchemy/queue-bundle": "^0.1.5",
"google/recaptcha": "^1.1", "google/recaptcha": "^1.1",
"facebook/graph-sdk": "^5.6" "facebook/graph-sdk": "^5.6",
"box/spout": "^2.7",
"paragonie/random-lib": "^2.0",
"czproject/git-php": "^3.17"
}, },
"require-dev": { "require-dev": {
"mikey179/vfsStream": "~1.5", "mikey179/vfsstream": "~1.5",
"phpunit/phpunit": "^4.8|^5.0" "phpunit/phpunit": "^4.8|^5.0"
}, },
"autoload": { "autoload": {

767
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,8 @@ main:
languages: [] languages: []
key: '' key: ''
api_require_ssl: true api_require_ssl: true
api_token_header: false
delete-account-require-email-confirmation: true
database: database:
host: 127.0.0.1 host: 127.0.0.1
port: 3306 port: 3306
@@ -89,7 +91,9 @@ main:
client_secret: null client_secret: null
border-manager: border-manager:
enabled: true enabled: true
extension-mapping: { } extension-mapping:
otc: application/vnd.oasis.opendocument.chart-template
ttc: application/x-font-ttf
checkers: checkers:
- -
type: Checker\Sha256 type: Checker\Sha256
@@ -227,17 +231,19 @@ embed_bundle:
video: video:
player: videojs player: videojs
autoplay: false autoplay: false
coverSubdef: previewx4 cover_subdef: thumbnail
available-speeds: message_start: StartOfMessage
available_speeds:
- 1 - 1
- 1.5 - 1.5
- 3 - 3
audio: audio:
player: videojs player: videojs
autoplay: false autoplay: false
cover_subdef: thumbnail
document: document:
player: flexpaper player: flexpaper
enable-pdfjs: true enable_pdfjs: true
geocoding-providers: geocoding-providers:
- -
map-provider: mapboxWebGL map-provider: mapboxWebGL
@@ -282,3 +288,7 @@ workers:
user: guest user: guest
password: guest password: guest
vhost: / vhost: /
user_account:
deleting_policies:
email_confirmation: true

6
docker/nginx/boot.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
set -xe
cat nginx.conf.sample | sed "s/\$MAX_BODY_SIZE/$MAX_BODY_SIZE/g" > /etc/nginx/conf.d/default.conf
nginx -g "daemon off;"

View File

@@ -0,0 +1,31 @@
user app;
worker_processes 1;
error_log /var/log/ngnix_error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}

View File

@@ -0,0 +1,39 @@
upstream backend {
server phraseanet:9000;
}
server {
listen 80;
root /var/alchemy/Phraseanet/www;
index index.php;
client_max_body_size $MAX_BODY_SIZE;
location /api {
rewrite ^(.*)$ /api.php/$1 last;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /index.php/$1 last;
}
# PHP scripts -> PHP-FPM server listening on 127.0.0.1:9000
location ~ ^/(index|index_dev|api)\.php(/|$) {
fastcgi_pass backend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/(status|ping)$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_pass backend;
}
}

View File

@@ -0,0 +1,9 @@
#!/bin/sh
set -e
if [ ! -z ${DOCKER_XDEBUG_ENABLED} ]; then
. usr-bin/docker-xdebug-enable
fi
exec "$@"

View File

@@ -0,0 +1,4 @@
#!/bin/sh
/sbin/ip route|awk '/default/ { print $3 }'
# TODO support MacOS & Windows host IP

View File

@@ -0,0 +1,5 @@
#!/bin/sh
unset HOST_IP
unset XDEBUG_CONFIG
unset XDEBUG_REMOTE_HOST

View File

@@ -0,0 +1,9 @@
#!/bin/sh
set -e
HOST_IP=$(docker-get-host-ip);
export HOST_IP
export XDEBUG_CONFIG="remote_enable=1 remote_host=${HOST_IP} idekey=PHPSTORM";
export XDEBUG_REMOTE_HOST="${HOST_IP}";

View File

@@ -0,0 +1,54 @@
#!/bin/bash
set -xe
if [ $INSTALL_ACCOUNT_EMAIL = ""]; then
echo "INSTALL_ACCOUNT_EMAIL var is not set."
exit 1
fi
if [ $INSTALL_ACCOUNT_PASSWORD = ""]; then
echo "INSTALL_ACCOUNT_PASSWORD var is not set."
exit 1
fi
/var/alchemy/Phraseanet/bin/setup system:install \
--email=$INSTALL_ACCOUNT_EMAIL \
--password=$INSTALL_ACCOUNT_PASSWORD \
--db-host=$INSTALL_DB_HOST \
--db-port=$INSTALL_DB_PORT \
--db-user=$INSTALL_DB_USER \
--db-password=$INSTALL_DB_PASSWORD \
--db-template=$INSTALL_DB_TEMPLATE \
--appbox=$INSTALL_APPBOX \
--databox=$INSTALL_DATABOX \
--server-name=$INSTALL_SERVER_NAME \
--data-path=/var/alchemy/Phraseanet/datas -y
/var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.host elasticsearch
/var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.minScore 2
/var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.base_aggregate_limit 10
/var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.collection_aggregate_limit 10
/var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.doctype_aggregate_limit 10
## Redis
/var/alchemy/Phraseanet/bin/setup system:config set main.cache.options.host redis
/var/alchemy/Phraseanet/bin/setup system:config set main.cache.options.port 6379
/var/alchemy/Phraseanet/bin/setup system:config set main.cache.options.domain $INSTALL_SERVER_NAME
/var/alchemy/Phraseanet/bin/setup system:config set main.cache.type redis
# RabbitMQ
bin/setup system:config set rabbitmq.server.host rabbitmq
bin/setup system:config set rabbitmq.server.port 5672
bin/setup system:config set rabbitmq.server.user $INSTALL_RABBITMQ_USER
bin/setup system:config set rabbitmq.server.password $INSTALL_RABBITMQ_PASSWORD
bin/setup system:config set rabbitmq.server.vhost /
/var/alchemy/Phraseanet/bin/console searchengine:index -c
## enable API and disable ssl on it
/var/alchemy/Phraseanet/bin/setup system:config set registry.api-clients.api-enabled true
/var/alchemy/Phraseanet/bin/setup system:config set main.api_require_ssl false
/var/alchemy/Phraseanet/bin/console compile:configuration

17
docker/phraseanet/boot.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
set -xe
chown -R app:app /var/alchemy/Phraseanet/config
chown -R app:app /var/alchemy/Phraseanet/datas
chown -R app:app /var/alchemy/Phraseanet/tmp
chown -R app:app /var/alchemy/Phraseanet/www/thumbnails
FILE=/var/alchemy/Phraseanet/config/configuration.yml
if [ -f "$FILE" ]; then
echo "$FILE exist, skip setup."
else
echo "$FILE doesn't exist, entering setup..."
runuser app -c '/auto-install.sh'
fi
php-fpm

View File

@@ -0,0 +1,125 @@
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr/local). This prefix can be dynamically changed by using the
; '-p' argument from the command line.
;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;
[global]
; Pid file
; Note: the default prefix is /usr/local/var
; Default Value: none
;pid = run/php-fpm.pid
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /usr/local/var
; Default Value: log/php-fpm.log
error_log = /var/lib/phraseanet/logs/php-fpm.log
; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon
; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm
; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = $PHP_LOG_LEVEL
; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0
; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated. This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;emergency_restart_interval = 0
; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0
; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
; process.max = 128
; Specify the nice(2) priority to apply to the master process (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool process will inherit the master process priority
; unless it specified otherwise
; Default Value: no set
; process.priority = -19
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes
; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
;rlimit_files = 1024
; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Specify the event mechanism FPM will use. The following is available:
; - select (any POSIX os)
; - poll (any POSIX os)
; - epoll (linux >= 2.5.44)
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll (Solaris >= 7)
; - port (Solaris >= 10)
; Default Value: not set (auto detection)
;events.mechanism = epoll
; When FPM is build with systemd integration, specify the interval,
; in second, between health report notification to systemd.
; Set to 0 to disable.
; Available Units: s(econds), m(inutes), h(ours)
; Default Unit: seconds
; Default value: 10
;systemd_interval = 10
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
; Multiple pools of child processes may be started with different listening
; ports and different management options. The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)
; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr/local otherwise
include=etc/php-fpm.d/*.conf

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -e
envsubst < /php.ini.sample > /usr/local/etc/php/php.ini
envsubst < /php-fpm.conf.sample > /usr/local/etc/php-fpm.conf
bash -e docker-php-entrypoint $@

View File

@@ -0,0 +1,380 @@
[www]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or NONE) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = app
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
;listen.group = app
;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
;listen.acl_users =
;listen.acl_groups =
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
;listen.allowed_clients = 127.0.0.1
; Specify the nice(2) priority to apply to the pool processes (only if set)
; The value can vary from -19 (highest priority) to 20 (lower priority)
; Note: - It will only work if the FPM master process is launched as root
; - The pool processes will inherit the master process priority
; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
; or group is differrent than the master process user. It allows to create proce
ss
; core dump and ptrace the process for the pool user.
; Default Value: no
; process.dumpable = yes
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 2
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 10s;
; The number of requests each child process should execute before respawning.
;pm.max_requests = 500
; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. It shows the following informations:
; pool - the name of the pool;
; process manager - static, dynamic or ondemand;
; start time - the date and time FPM has started;
; start since - number of seconds since FPM has started;
; accepted conn - the number of request accepted by the pool;
; listen queue - the number of request in the queue of pending
; connections (see backlog in listen(2));
; max listen queue - the maximum number of requests in the queue
; of pending connections since FPM has started;
; listen queue len - the size of the socket queue of pending connections;
; idle processes - the number of idle processes;
; active processes - the number of active processes;
; total processes - the number of idle + active processes;
; max active processes - the maximum number of active processes since FPM
; has started;
; max children reached - number of times, the process limit has been reached,
; Example output:
; pool: www
; process manager: static
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 62636
; accepted conn: 190460
; listen queue: 0
; max listen queue: 1
; listen queue len: 42
; idle processes: 4
; active processes: 11
; total processes: 15
; max active processes: 12
; max children reached: 0
;
; By default the status page output is formatted as text/plain. Passing either
; 'html', 'xml' or 'json' in the query string will return the corresponding
; output syntax. Example:
; http://www.foo.bar/status
; http://www.foo.bar/status?json
; http://www.foo.bar/status?html
; query string will also return status for each pool process.
; Example:
; http://www.foo.bar/status?full
; http://www.foo.bar/status?json&full
; http://www.foo.bar/status?html&full
; http://www.foo.bar/status?xml&full
; The Full status returns for each process:
; pid - the PID of the process;
; state - the state of the process (Idle, Running, ...);
; start time - the date and time the process has started;
; start since - the number of seconds since the process has started;
; requests - the number of requests the process has served;
; request duration - the duration in µs of the requests;
; request method - the request method (GET, POST, ...);
; request URI - the request URI with the query string;
; content length - the content length of the request (only with POST);
; user - the user (PHP_AUTH_USER) (or '-' if not set);
; script - the main script called (or '-' if not set);
; last request cpu - the %cpu the last request consumed
; it's always 0 if the process is not in Idle state
; it's always 0 if the process is not in Idle state
; because memory calculation is done when the request
; processing has terminated;
; If the process is in Idle state, then informations are related to the
; last request the process has served. Otherwise informations are related to
; the current request being served.
; Example output:
; ************************
; pid: 31330
; state: Running
; start time: 01/Jul/2011:17:53:49 +0200
; start since: 63087
; requests: 12808
; request duration: 1250261
; request method: GET
; request URI: /test_mem.php?N=10000
; content length: 0
; user: -
; script: /home/fat/web/docs/php/test_mem.php
; last request cpu: 0.00
; It's available in: /usr/local/share/php/fpm/status.html
;
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;pm.status_path = /status
; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping
;ping.response = pong
; The access log file
; Default: not set
;access.log = log/$pool.access.log
; The access log format.
; The following syntax is allowed
; %%: the '%' character
; %C: %CPU used by the request
; it can accept the following format:
; - %{user}C for user CPU only
; - %{system}C for system CPU only
; - %{total}C for user + system CPU (default)
; %d: time taken to serve the request
; it can accept the following format:
; - %{seconds}d (default)
; - %{miliseconds}d
; - %{mili}d
; - %{microseconds}d
; variable. Some exemples:
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
; %f: script filename
; %l: content-length of the request (for POST request only)
; %m: request method
; %M: peak of memory allocated by PHP
; it can accept the following format:
; - %{bytes}M (default)
; - %{kilobytes}M
; - %{kilo}M
; - %{megabytes}M
; - %{mega}M
; %n: pool name
; %o: output header
; it must be associated with embraces to specify the name of the header:
; - %{Content-Type}o
; - %{X-Powered-By}o
; - %{Transfert-Encoding}o
; - ....
; %Q: the '?' character if query string exists
; %r: the request URI (without the query string, see %q and %Q)
; %R: remote IP address
; %s: status (response code)
; %t: server time the request was received
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %T: time the log has been written (the request has finished)
; it can accept a strftime(3) format:
; %d/%b/%Y:%H:%M:%S %z (default)
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
; %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
; The log file for slow requests
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0
; Depth of slow log stack trace.
; Default Value: 20
;request_slowlog_trace_depth = 20
; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0
; Set open file descriptor rlimit.
; Default Value: system defined value
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
;chdir = /var/www
; process time (several ms).
; Default Value: no
;catch_workers_output = yes
; Clear environment in FPM workers
; Prevents arbitrary environment variables from reaching FPM worker processes
; by clearing the environment in workers before env vars specified in this
; pool configuration are added.
; Setting to "no" will make all environment variables available to PHP code
; via getenv(), $_ENV and $_SERVER.
; Default Value: yes
;clear_env = no
; Limits the extensions of the main script FPM will allow to parse. This can
; prevent configuration mistakes on the web server side. You should only limit
; FPM to .php extensions to prevent malicious users to use other extensions to
; execute php code.
; Note: set an empty value to allow all extensions.
; Default Value: .php
;security.limit_extensions = .php .php3 .php4 .php5 .php7
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr/local)
; Default Value: nothing is defined by default except the values in php.ini and
; specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
request_terminate_timeout=300s

View File

@@ -0,0 +1,24 @@
[global]
daemonize = no
error_log = /var/log/fpm-php.www.log
process.max = 128
[www]
listen = 0.0.0.0:9000
;listen = /sock/php-fpm.sock
user = app
group = app
pm = dynamic
pm.max_children = 9
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 1000
request_terminate_timeout=300s
pm.status_path = /status
ping.path = /ping

View File

@@ -0,0 +1,4 @@
#!/bin/bash
mkdir /var/alchemy/Phraseanet/tmp/locks && chown -R app:app /var/alchemy/Phraseanet/tmp
runuser app -c 'php /var/alchemy/Phraseanet/bin/console task-manager:scheduler:run'

View File

@@ -128,7 +128,7 @@ key:
| quoted_string() | quoted_string()
group: group:
::space::? ::parenthese_:: primary() ::_parenthese:: ::space::? ::space::? ::parenthese_:: ::space::? primary() ::space::? ::_parenthese:: ::space::?
// Thesaurus terms // Thesaurus terms

View File

@@ -92,9 +92,12 @@ use Alchemy\WorkerProvider\WorkerServiceProvider;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use MediaVorus\Media\MediaInterface; use MediaVorus\Media\MediaInterface;
use MediaVorus\MediaVorus; use MediaVorus\MediaVorus;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger; use Monolog\Logger;
use Neutron\ReCaptcha\ReCaptchaServiceProvider; use Neutron\ReCaptcha\ReCaptchaServiceProvider;
use Psr\Log\LoggerInterface;
use Silex\Application as SilexApplication; use Silex\Application as SilexApplication;
use Silex\Application\TranslationTrait; use Silex\Application\TranslationTrait;
use Silex\Application\UrlGeneratorTrait; use Silex\Application\UrlGeneratorTrait;
@@ -112,6 +115,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface; use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Process\ExecutableFinder;
use Unoconv\UnoconvServiceProvider; use Unoconv\UnoconvServiceProvider;
use XPDF\PdfToText; use XPDF\PdfToText;
use XPDF\XPDFServiceProvider; use XPDF\XPDFServiceProvider;
@@ -234,8 +238,19 @@ class Application extends SilexApplication
$this->register(new UnicodeServiceProvider()); $this->register(new UnicodeServiceProvider());
$this->register(new ValidatorServiceProvider()); $this->register(new ValidatorServiceProvider());
$this->register(new XPDFServiceProvider());
$this->setupXpdf(); if ($this['configuration.store']->isSetup()) {
$binariesConfig = $this['conf']->get(['main', 'binaries']);
$executableFinder = new ExecutableFinder();
$this->register(new XPDFServiceProvider(), [
'xpdf.configuration' => [
'pdftotext.binaries' => isset($binariesConfig['pdftotext_binary']) ? $binariesConfig['pdftotext_binary'] : $executableFinder->find('pdftotext'),
]
]);
$this->setupXpdf();
}
$this->register(new FileServeServiceProvider()); $this->register(new FileServeServiceProvider());
$this->register(new ManipulatorServiceProvider()); $this->register(new ManipulatorServiceProvider());
$this->register(new PluginServiceProvider()); $this->register(new PluginServiceProvider());
@@ -253,6 +268,23 @@ class Application extends SilexApplication
$this->register(new OrderServiceProvider()); $this->register(new OrderServiceProvider());
$this->register(new WebhookServiceProvider()); $this->register(new WebhookServiceProvider());
$this['monolog'] = $this->share(
$this->extend('monolog', function (LoggerInterface $logger, Application $app) {
$logger->pushHandler(new ErrorLogHandler(
ErrorLogHandler::SAPI,
Logger::ERROR
));
$logger->pushHandler(new StreamHandler(
fopen('php://stderr', 'w'),
Logger::ERROR
));
return $logger;
})
);
$this['phraseanet.exception_handler'] = $this->share(function ($app) { $this['phraseanet.exception_handler'] = $this->share(function ($app) {
/** @var PhraseaExceptionHandler $handler */ /** @var PhraseaExceptionHandler $handler */
$handler = PhraseaExceptionHandler::register($app['debug']); $handler = PhraseaExceptionHandler::register($app['debug']);
@@ -633,7 +665,7 @@ class Application extends SilexApplication
private function setupGeonames() private function setupGeonames()
{ {
$this['geonames.server-uri'] = $this->share(function (Application $app) { $this['geonames.server-uri'] = $this->share(function (Application $app) {
return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'http://geonames.alchemyasp.com/'); return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'https://geonames.alchemyasp.com/');
}); });
} }

View File

@@ -24,9 +24,11 @@ use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Core\Provider\JsonSchemaServiceProvider; use Alchemy\Phrasea\Core\Provider\JsonSchemaServiceProvider;
use Alchemy\Phrasea\Report\ControllerProvider\ApiReportControllerProvider;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class ApiApplicationLoader extends BaseApplicationLoader class ApiApplicationLoader extends BaseApplicationLoader
{ {
protected function doPrePluginServiceRegistration(Application $app) protected function doPrePluginServiceRegistration(Application $app)
@@ -34,6 +36,7 @@ class ApiApplicationLoader extends BaseApplicationLoader
$app->register(new OAuth2()); $app->register(new OAuth2());
$app->register(new V1()); $app->register(new V1());
$app->register(new V2()); $app->register(new V2());
$app->register(new ApiReportControllerProvider());
$app->register(new JsonSchemaServiceProvider()); $app->register(new JsonSchemaServiceProvider());
} }
@@ -132,6 +135,7 @@ class ApiApplicationLoader extends BaseApplicationLoader
$app->mount('/datafiles/', new Datafiles()); $app->mount('/datafiles/', new Datafiles());
$app->mount('/api/v1', new V1()); $app->mount('/api/v1', new V1());
$app->mount('/api/v2', new V2()); $app->mount('/api/v2', new V2());
$app->mount('/api/report', new ApiReportControllerProvider());
$app->mount('/permalink/', new Permalink()); $app->mount('/permalink/', new Permalink());
$app->mount($app['controller.media_accessor.route_prefix'], new MediaAccessor()); $app->mount($app['controller.media_accessor.route_prefix'], new MediaAccessor());
$app->mount('/include/minify/', new Minifier()); $app->mount('/include/minify/', new Minifier());

View File

@@ -5,9 +5,11 @@ namespace Alchemy\Phrasea\Application;
use Alchemy\EmbedProvider\EmbedServiceProvider; use Alchemy\EmbedProvider\EmbedServiceProvider;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\ControllerProvider as Providers; use Alchemy\Phrasea\ControllerProvider as Providers;
use Alchemy\Phrasea\Report\ControllerProvider\ProdReportControllerProvider;
use Assert\Assertion; use Assert\Assertion;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
class RouteLoader class RouteLoader
{ {
@@ -53,6 +55,7 @@ class RouteLoader
'/prod/records/edit' => Providers\Prod\Edit::class, '/prod/records/edit' => Providers\Prod\Edit::class,
'/prod/records/movecollection' => Providers\Prod\MoveCollection::class, '/prod/records/movecollection' => Providers\Prod\MoveCollection::class,
'/prod/records/property' => Providers\Prod\Property::class, '/prod/records/property' => Providers\Prod\Property::class,
'/prod/report/' => ProdReportControllerProvider::class,
'/prod/share/' => Providers\Prod\Share::class, '/prod/share/' => Providers\Prod\Share::class,
'/prod/story' => Providers\Prod\Story::class, '/prod/story' => Providers\Prod\Story::class,
'/prod/subdefs' => Providers\Prod\Subdefs::class, '/prod/subdefs' => Providers\Prod\Subdefs::class,
@@ -62,8 +65,6 @@ class RouteLoader
'/prod/upload/' => Providers\Prod\Upload::class, '/prod/upload/' => Providers\Prod\Upload::class,
'/prod/WorkZone' => Providers\Prod\WorkZone::class, '/prod/WorkZone' => Providers\Prod\WorkZone::class,
'/prod/' => Providers\Prod\Root::class, '/prod/' => Providers\Prod\Root::class,
'/report/activity' => Providers\Report\Activity::class,
'/report/informations' => Providers\Report\Information::class,
'/report/' => Providers\Report\Root::class, '/report/' => Providers\Report\Root::class,
'/session/' => Providers\Root\Session::class, '/session/' => Providers\Root\Session::class,
'/setup' => Providers\Setup::class, '/setup' => Providers\Setup::class,

View File

@@ -73,9 +73,26 @@ class CLI extends Application
$this->bindRoutes(); $this->bindRoutes();
$this['logger'] = $this->extend('logger', function () { $logger = false;
return new Console\Logger\ConsoleLogger(new Console\Output\ConsoleOutput(Console\Output\ConsoleOutput::VERBOSITY_DEBUG));
}); if ($this['configuration.store']->isSetup()){
$config = $this['configuration.store']->getConfig();
if ((isset($config['console_logger_enabled_environments']) && in_array($environment, $config['console_logger_enabled_environments']))){
$logger = true;
}
}
if ($environment == self::ENV_DEV){
$logger = true;
}
if ($logger){
$this['logger'] = $this->extend('logger', function () {
return new Console\Logger\ConsoleLogger(new Console\Output\ConsoleOutput(Console\Output\ConsoleOutput::VERBOSITY_DEBUG));
});
}
error_reporting(-1); error_reporting(-1);
ErrorHandler::register(); ErrorHandler::register();

View File

@@ -73,7 +73,7 @@ class RedisCache extends CacheProvider implements Cache
*/ */
protected function doDelete($id) protected function doDelete($id)
{ {
return $this->_redis->delete($id); return $this->_redis->del($id);
} }
/** /**

View File

@@ -11,7 +11,7 @@
namespace Alchemy\Phrasea\Cache; namespace Alchemy\Phrasea\Cache;
use Doctrine\Common\Cache\WincacheCache as DoctrineWinCache; use Doctrine\Common\Cache\WinCacheCache as DoctrineWinCache;
class WinCacheCache extends DoctrineWinCache implements Cache class WinCacheCache extends DoctrineWinCache implements Cache
{ {

View File

@@ -84,6 +84,15 @@ class CollectionRepositoryRegistry
throw new \OutOfBoundsException('No repository available for given base [baseId: ' . $baseId . ' ].'); throw new \OutOfBoundsException('No repository available for given base [baseId: ' . $baseId . ' ].');
} }
public function getBaseIdMap()
{
if ($this->baseIdMap === null) {
$this->loadBaseIdMap();
}
return $this->baseIdMap;
}
public function purgeRegistry() public function purgeRegistry()
{ {
$this->baseIdMap = null; $this->baseIdMap = null;

View File

@@ -319,7 +319,9 @@ class CollectionService
$result = $userQuery->on_base_ids([ $reference->getBaseId()] ) $result = $userQuery->on_base_ids([ $reference->getBaseId()] )
->who_have_right([\ACL::ORDER_MASTER]) ->who_have_right([\ACL::ORDER_MASTER])
->execute()->get_results(); ->include_templates(true)
->execute()
->get_results();
/** @var ACLProvider $acl */ /** @var ACLProvider $acl */
$acl = $this->app['acl']; $acl = $this->app['acl'];

View File

@@ -51,4 +51,41 @@ abstract class AbstractPluginCommand extends Command
$this->container['plugins.autoloader-generator']->write($manifests); $this->container['plugins.autoloader-generator']->write($manifests);
$output->writeln(" <comment>OK</comment>"); $output->writeln(" <comment>OK</comment>");
} }
protected function doInstallPlugin($source, InputInterface $input, OutputInterface $output)
{
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory();
$output->write("Importing <info>$source</info>...");
$this->container['plugins.importer']->import($source, $temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Validating plugin...");
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($temporaryDir);
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName();
$output->write("Setting up composer...");
$this->container['plugins.composer-installer']->install($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Installing plugin <info>".$manifest->getName()."</info>...");
$this->container['filesystem']->mirror($temporaryDir, $targetDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Copying public files <info>".$manifest->getName()."</info>...");
$this->container['plugins.assets-manager']->update($manifest);
$output->writeln(" <comment>OK</comment>");
$output->write("Removing temporary directory...");
$this->container['filesystem']->remove($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Activating plugin...");
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
$output->writeln(" <comment>OK</comment>");
$this->updateConfigFiles($input, $output);
}
} }

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Command\Plugin;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\ArrayInput;
class AddPlugin extends AbstractPluginCommand class AddPlugin extends AbstractPluginCommand
{ {
@@ -29,41 +30,36 @@ class AddPlugin extends AbstractPluginCommand
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output) protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
{ {
$source = $input->getArgument('source'); $source = $input->getArgument('source');
$shouldDownload = $this->shouldDownloadPlugin($source);
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory(); if ($shouldDownload){
$command = $this->getApplication()->find('plugins:download');
$arguments = [
'command' => 'plugins:download',
'source' => $source,
'shouldInstallPlugin' => true
];
$output->write("Importing <info>$source</info>..."); $downloadInput = new ArrayInput($arguments);
$this->container['plugins.importer']->import($source, $temporaryDir); $command->run($downloadInput, $output);
$output->writeln(" <comment>OK</comment>");
$output->write("Validating plugin..."); } else {
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($temporaryDir);
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName(); $this->doInstallPlugin($source, $input, $output);
}
$output->write("Setting up composer...");
$this->container['plugins.composer-installer']->install($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Installing plugin <info>".$manifest->getName()."</info>...");
$this->container['filesystem']->mirror($temporaryDir, $targetDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Copying public files <info>".$manifest->getName()."</info>...");
$this->container['plugins.assets-manager']->update($manifest);
$output->writeln(" <comment>OK</comment>");
$output->write("Removing temporary directory...");
$this->container['filesystem']->remove($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Activating plugin...");
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
$output->writeln(" <comment>OK</comment>");
$this->updateConfigFiles($input, $output);
return 0; return 0;
} }
protected function shouldDownloadPlugin($source)
{
$allowedScheme = array('https','ssh');
$scheme = parse_url($source, PHP_URL_SCHEME);
if (in_array($scheme, $allowedScheme)){
return true;
} else{
return false;
}
}
} }

View File

@@ -0,0 +1,157 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Plugin;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\ArrayInput;
use Cz\Git\GitRepository as GitRepository;
class DownloadPlugin extends AbstractPluginCommand
{
public function __construct()
{
parent::__construct('plugins:download');
$this
->setDescription('Downloads a plugin to Phraseanet')
->addArgument('source', InputArgument::REQUIRED, 'The source is a remote url (.zip or .git)')
->addArgument('destination', InputArgument::OPTIONAL, 'Download destination')
->addArgument('shouldInstallPlugin', InputArgument::OPTIONAL, 'True or false, determines if plugin should be installed after download');
}
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
{
$source = $input->getArgument('source');
$destination = $input->getArgument('destination');
$shouldInstallPlugin = false;
$shouldInstallPlugin = $input->getArgument('shouldInstallPlugin');
$destinationSubdir = '/plugin-'.md5($source);
if ($destination){
$destination = trim($destination);
$destination = rtrim($destination, '/');
$localDownloadPath = $destination;
} else {
$localDownloadPath = '/tmp/plugin-download' . $destinationSubdir;
}
if (!is_dir($localDownloadPath)) {
mkdir($localDownloadPath, 0755, true);
}
$extension = $this->getURIExtension($source);
if ($extension){
switch ($extension){
case 'zip':
$localUnpackPath = '/tmp/plugin-zip'. $destinationSubdir;
if (!is_dir($localUnpackPath)) {
mkdir($localUnpackPath, 0755, true);
}
$localArchiveFile = $localUnpackPath . '/plugin-downloaded.zip';
// download
$output->writeln("Downloading <info>$source</info>...");
set_time_limit(0);
$fp = fopen ($localArchiveFile, 'w+');
$ch = curl_init($source);;
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// unpack
$output->writeln("Unpacking <info>$source</info>...");
$zip = new \ZipArchive();
$errorUnpack = false;
if ($zip->open($localArchiveFile)) {
for ($i = 0; $i < $zip->numFiles; $i++) {
if (!($zip->extractTo($localDownloadPath, array($zip->getNameIndex($i))))) {
$errorUnpack = true;
}
}
$zip->close();
}
if ($errorUnpack){
$output->writeln("Failed unzipping <info>$source</info>");
} else {
$output->writeln("Plugin downloaded to <info>$localDownloadPath</info>");
if ($shouldInstallPlugin) $this->doInstallPlugin($localDownloadPath, $input, $output);
}
// remove zip archive
$this->delDirTree($localUnpackPath);
break;
case 'git':
$output->writeln("Downloading <info>$source</info>...");
$repo = GitRepository::cloneRepository($source, $localDownloadPath);
$output->writeln("Plugin downloaded to <info>$localDownloadPath</info>");
if ($shouldInstallPlugin) $this->doInstallPlugin($localDownloadPath, $input, $output);
break;
}
} else {
$output->writeln("The source <info>$source</info> is not supported. Only .zip and .git are supported.");
}
return 0;
}
protected function getURIExtension($source)
{
$validExtension = false;
$allowedExtension = array('zip','git');
$path = parse_url($source, PHP_URL_PATH);
if (strpos($path, '.') !== false) {
$pathParts = explode('.', $path);
$extension = $pathParts[1];
if (in_array($extension, $allowedExtension)){
$validExtension = true;
}
}
if ($validExtension){
return $extension;
} else {
return false;
}
}
protected static function delDirTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? self::delDirTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
}

View File

@@ -193,8 +193,7 @@ class FixAutoincrements extends Command
$databox, $databox,
'coll', 'coll',
[ [
'collusr' => 'coll_id', 'collusr' => 'coll_id',
'log_colls' => 'coll_id',
] ]
); );
} }

View File

@@ -0,0 +1,396 @@
<?php
/**
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Doctrine\DBAL\Driver\ResultStatement;
class FixLogCollId extends Command
{
const OPTION_DISTINT_VALUES = 0;
const OPTION_ALL_VALUES = 1;
const PLAYDRY_NONE = 0;
const PLAYDRY_SQL = 1;
const PLAYDRY_CODE = 2;
/** @var InputInterface */
private $input;
/** @var OutputInterface */
private $output;
/** @var \Databox[] */
private $databoxes;
/** @var int */
private $batch_size;
/** @var bool */
private $dry;
/** @var bool */
private $show_sql;
/** @var bool */
private $keep_tmp_table;
public function __construct($name = null)
{
parent::__construct("patch:log_coll_id");
$this->setDescription('Fix empty (null) coll_id in "log_docs" and "log_view" tables.');
$this->addOption('databox', null, InputOption::VALUE_OPTIONAL, 'Mandatory : The id (or dbname or viewname) of the databox');
$this->addOption('batch_size', null, InputOption::VALUE_OPTIONAL, 'work on a batch of n entries (default=100000)');
$this->addOption('dry', null, InputOption::VALUE_NONE, 'dry run, list but don\'t act');
$this->addOption('show_sql', null, InputOption::VALUE_NONE, 'show sql pre-selecting records');
$this->addOption('keep_tmp_table', null, InputOption::VALUE_NONE, 'keep the working "tmp_coll" table (help debug)');
$this->setHelp("help");
}
/**
* sanity check the cmd line options
*
* @param InputInterface $input
* @param OutputInterface $output
* @return bool
*/
protected function sanitizeArgs(InputInterface $input, OutputInterface $output)
{
$argsOK = true;
// find the databox / collection by id or by name
$this->databoxes = [];
if(!is_null($d = $input->getOption('databox'))) {
$d = trim($d);
}
foreach ($this->container->getDataboxes() as $db) {
if(is_null($d)){
$this->databoxes[] = $db;
}
else {
if ($db->get_sbas_id() == (int)$d || $db->get_viewname() == $d || $db->get_dbname() == $d) {
$this->databoxes[] = $db;
}
}
}
if (empty($this->databoxes)) {
if(is_null($d)) {
$output->writeln(sprintf("<error>No databox found</error>", $d));
}
else {
$output->writeln(sprintf("<error>Unknown databox \"%s\"</error>", $d));
}
$argsOK = false;
}
// get options
$this->batch_size = $input->getOption('batch_size');
$this->show_sql = $input->getOption('show_sql') ? true : false;
$this->dry = $input->getOption('dry') ? true : false;
$this->keep_tmp_table = $input->getOption('keep_tmp_table') ? true : false;
if(is_null($this->batch_size)) {
$this->batch_size = 100000;
}
if($this->batch_size < 1) {
$output->writeln(sprintf('<error>batch_size must be > 0</error>'));
$argsOK = false;
}
return $argsOK;
}
/**
* {@inheritdoc}
*/
protected function doExecute(InputInterface $input, OutputInterface $output)
{
// $time_start = new \DateTime();
if(!$this->sanitizeArgs($input, $output)) {
return -1;
}
$this->input = $input;
$this->output = $output;
foreach($this->databoxes as $databox) {
$this->output->writeln("");
$this->output->writeln(sprintf("<info>================================ Working on databox %s (id:%s) ================================</info>", $databox->get_dbname(), $databox->get_sbas_id()));
if (!$this->showCount($databox)) {
// databox not patched
break;
}
$this->createWorkingTable($databox);
// loop to compute coll_id from top to bottom
do {
$n = $this->computeCollId($databox); // in dry mode, n=0
}
while ($n > 0);
// set the "from_coll_id"
$this->computeCollIdFrom($databox);
// copy results back to the log_docs
$this->copyReults($databox);
if (!$this->keep_tmp_table) {
$this->dropWorkingTable($databox);
}
$this->output->writeln("");
}
return 0;
}
private function createWorkingTable(\databox $databox)
{
$this->output->writeln("");
$this->output->writeln(sprintf("<info> ----------------- Creating working %s table -----------------</info>", ($this->keep_tmp_table ? "(temporary)" : "")));
$this->output->writeln("");
$sql = "CREATE " . ($this->keep_tmp_table ? "TABLE IF NOT EXISTS" : "TEMPORARY TABLE") . " `tmp_colls` (\n"
. " `record_id` int(11) unsigned NOT NULL,\n"
. " `from_id` int(11) unsigned NOT NULL,\n"
. " `from_date` datetime NOT NULL,\n"
. " `to_id` int(11) unsigned DEFAULT NULL,\n"
. " `to_date` datetime DEFAULT NULL,\n"
. " `coll_id_from` int(10) unsigned DEFAULT NULL,\n"
. " `coll_id` int(10) unsigned DEFAULT NULL,\n"
. " KEY `record_id` (`record_id`),\n"
. " KEY `from_id` (`from_id`),\n"
. " KEY `from_date` (`from_date`),\n"
. " KEY `to_id` (`to_id`),\n"
. " KEY `to_date` (`to_date`)\n"
. ") ENGINE=InnoDB;";
if($this->show_sql) {
$this->output->writeln($sql);
$this->output->writeln("");
}
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$sql = "TRUNCATE TABLE `tmp_colls`";
if($this->show_sql) {
$this->output->writeln($sql);
$this->output->writeln("");
}
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
}
private function dropWorkingTable(\databox $databox)
{
$this->output->writeln(sprintf("<info> ----------------- Drop working table -----------------</info>"));
$sql = "DROP TABLE `tmp_colls`";
if($this->show_sql) {
$this->output->writeln($sql);
}
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
}
private function showCount(\databox $databox)
{
$ret = true;
$this->playSQL(
$databox,
[
'msg' => "Count work to do",
'sql' => "SELECT\n"
. " SUM(IF(ISNULL(`coll_id`), 0, 1)) AS `n`,\n"
. " COUNT(*) AS `t`,\n"
. " SUM(IF(`coll_id`>0, 1, 0)) AS `p`,\n"
. " SUM(IF(`coll_id`=0, 1, 0)) AS `z`\n"
. " FROM `log_docs`",
'code' => function(ResultStatement $stmt) use($ret) {
$row = $stmt->fetch();
if(is_null($row['n'])) {
// no coll_id ?
$this->output->writeln(sprintf("<error>The \"log_docs\" table has no \"coll_id\" column ? Please apply patch 410alpha12a</error>"));
$ret = false;
}
$this->output->writeln("");
$this->output->writeln(sprintf("done: %s / %s (fixed: %s ; can't fix: %s)", $row['n'], $row['t'], $row['p'], $row['z']));
},
'playdry' => self::PLAYDRY_SQL | self::PLAYDRY_CODE,
]
);
return $ret;
}
private function computeCollId(\databox $databox)
{
static $sql_lastid = null;
static $stmt_lastid = null;
static $sql_insert = null;
static $stmt_insert = null;
$ret = 0;
if(!$stmt_lastid) {
$sql_lastid = "SELECT @m:=COALESCE(MAX(`from_id`), 0) AS `lastid` FROM `tmp_colls`";
$stmt_lastid = $databox->get_connection()->prepare($sql_lastid);
$sql_insert = "INSERT INTO `tmp_colls`\n"
. " SELECT `r1`.`record_id`, `r1`.`id` AS `from_id`, `r1`.`date` AS `from_date`, MIN(`r2`.`id`) AS `to_id`, MIN(`r2`.`date`) AS `to_date`, NULL AS `coll_id_from`, `r1`.`final` AS `coll_id`\n"
. " FROM (\n"
. " SELECT `id`, `date`, `record_id`, `action`, `final` FROM `log_docs`\n"
. " WHERE `id` > @m AND `action` IN('add', 'collection')\n"
. " ORDER BY `id` ASC\n"
. " LIMIT " . $this->batch_size . "\n"
. " ) AS `r1`\n"
. " LEFT JOIN `log_docs` AS `r2`\n"
. " ON `r2`.`record_id`=`r1`.`record_id` AND `r2`.`action`='collection' AND `r2`.`id`>`r1`.`id`\n"
. " GROUP BY `r1`.`id`\n"
// . " ORDER BY `record_id` ASC, `from_id` ASC"
;
$stmt_insert = $databox->get_connection()->prepare($sql_insert);
$this->output->writeln("");
$this->output->writeln(sprintf("<info> ----------------- Compute coll_id to working table ----------------- %s</info>",
$this->dry ? " -- NOT PLAYED IN DRY MODE --" : ""
)
);
$this->output->writeln("");
if ($this->show_sql) {
$this->output->writeln($sql_lastid);
$this->output->writeln($sql_insert);
}
}
if(!$this->dry) {
$stmt_lastid->execute();
$stmt_lastid->closeCursor();
$stmt_insert->execute();
$ret = $stmt_insert->rowCount();
$stmt_insert->closeCursor();
}
return $ret;
}
private function computeCollIdFrom(\databox $databox)
{
static $sql = null;
static $stmt = null;
$ret = 0;
if(!$stmt) {
$sql = "UPDATE `tmp_colls` AS `t1` INNER JOIN `tmp_colls` AS `t2` ON `t2`.`from_id`=`t1`.`to_id`\n"
. " SET `t2`.`coll_id_from` = `t1`.`coll_id`";
$this->output->writeln("");
$this->output->writeln(sprintf("<info> ----------------- Compute coll_id_from to working table ----------------- %s</info>",
$this->dry ? " -- NOT PLAYED IN DRY MODE --" : ""
)
);
$this->output->writeln("");
if ($this->show_sql) {
$this->output->writeln($sql);
}
$stmt = $databox->get_connection()->prepare($sql);
}
if(!$this->dry) {
$stmt->execute();
$ret = $stmt->rowCount();
$stmt->closeCursor();
}
return $ret;
}
private function copyReults(\databox $databox)
{
$this->playSQL(
$databox,
[
'msg' => "Copy result back to \"log_docs\"",
'sql' => "UPDATE `tmp_colls` AS `t` INNER JOIN `log_docs` AS `d`\n"
. " ON ISNULL(`d`.`coll_id`)\n"
. " AND `t`.`record_id` = `d`.`record_id`\n"
. " AND `d`.`id` >= `t`.`from_id`\n"
. " AND (`d`.`id` < `t`.`to_id` OR ISNULL(`t`.`to_id`))\n"
. " SET `d`.`coll_id_from` = IF(`action`='collection', `t`.`coll_id_from`, NULL),\n"
. " `d`.`coll_id` = `t`.`coll_id`",
'code' => null,
'playdry' => self::PLAYDRY_NONE,
]
);
$this->playSQL(
$databox,
[
'msg' => "Copy result back to \"log_view\"",
'sql' => "UPDATE `log_view` AS `v` INNER JOIN `tmp_colls` AS `t`\n"
. " ON ISNULL(`v`.`coll_id`)\n"
. " AND `t`.`record_id` = `v`.`record_id`\n"
. " AND `v`.`date` >= `t`.`from_date`\n"
. " AND (`v`.`date` < `t`.`to_date` OR ISNULL(`t`.`to_date`))\n"
. " SET `v`.`coll_id` = `t`.`coll_id`",
'code' => null,
'playdry' => self::PLAYDRY_NONE,
]
);
}
private function playSQL(\databox $databox, Array $work)
{
$this->output->writeln("");
$this->output->writeln(sprintf("<info> ----------------- %s ----------------- %s</info>",
$work['msg'],
$this->dry && !($work['playdry'] & self::PLAYDRY_SQL) ? " -- NOT PLAYED IN DRY MODE --" : ""
)
);
$this->output->writeln("");
if ($this->show_sql) {
$this->output->writeln($work['sql']);
}
$stmt = null;
if(!$this->dry || ($work['playdry'] & self::PLAYDRY_SQL)) {
$stmt = $databox->get_connection()->prepare($work['sql']);
$stmt->execute();
}
if($work['code'] && (!$this->dry || ($work['playdry'] & self::PLAYDRY_CODE))) {
$code = $work['code'];
$code($stmt);
}
if(!$this->dry || ($work['playdry'] & self::PLAYDRY_SQL)) {
$stmt->closeCursor();
}
}
}

View File

@@ -50,6 +50,7 @@ class CollectionController extends Controller
$query = $this->createUserQuery(); $query = $this->createUserQuery();
$admins = $query->on_base_ids([$bas_id]) $admins = $query->on_base_ids([$bas_id])
->who_have_right([\ACL::ORDER_MASTER]) ->who_have_right([\ACL::ORDER_MASTER])
->include_templates(true)
->execute() ->execute()
->get_results(); ->get_results();
} }

View File

@@ -160,6 +160,9 @@ class DataboxesController extends Controller
try { try {
$connectionSettings = $this->buildSettingsFromRequest($request); $connectionSettings = $this->buildSettingsFromRequest($request);
\phrasea::clear_sbas_params($this->app);
$databox = $databoxService->mountDatabox($dbName, $this->app->getAuthenticatedUser(), $connectionSettings); $databox = $databoxService->mountDatabox($dbName, $this->app->getAuthenticatedUser(), $connectionSettings);
return $this->app->redirectPath('admin_database', [ return $this->app->redirectPath('admin_database', [
@@ -174,7 +177,8 @@ class DataboxesController extends Controller
catch (\Exception $exception) { catch (\Exception $exception) {
return $this->app->redirectPath('admin_databases', [ return $this->app->redirectPath('admin_databases', [
'success' => 0, 'success' => 0,
'error' => 'mount-failed' // 'error' => 'mount-failed'
'error' => $exception->getMessage()
]); ]);
} }
} }

View File

@@ -314,6 +314,9 @@ class FieldsController extends Controller
->set_readonly($data['readonly']) ->set_readonly($data['readonly'])
->set_type($data['type']) ->set_type($data['type'])
->set_tbranch($data['tbranch']) ->set_tbranch($data['tbranch'])
->set_generate_cterms($data['generate_cterms'])
->set_gui_editable($data['gui_editable'])
->set_gui_visible($data['gui_visible'])
->set_report($data['report']) ->set_report($data['report'])
->setVocabularyControl(null) ->setVocabularyControl(null)
->setVocabularyRestricted(false); ->setVocabularyRestricted(false);
@@ -349,7 +352,7 @@ class FieldsController extends Controller
{ {
return [ return [
'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable', 'aggregable', 'name', 'multi', 'thumbtitle', 'tag', 'business', 'indexable', 'aggregable',
'required', 'separator', 'readonly', 'type', 'tbranch', 'report', 'required', 'separator', 'readonly', 'gui_editable', 'gui_visible' , 'type', 'tbranch', 'generate_cterms', 'report',
'vocabulary-type', 'vocabulary-restricted', 'dces-element', 'labels' 'vocabulary-type', 'vocabulary-restricted', 'dces-element', 'labels'
]; ];
} }

View File

@@ -145,6 +145,7 @@ class SubdefsController extends Controller
$options[Audio::OPTION_AUDIOBITRATE] = $config["audio"]["definitions"][$preset][Audio::OPTION_AUDIOBITRATE]; $options[Audio::OPTION_AUDIOBITRATE] = $config["audio"]["definitions"][$preset][Audio::OPTION_AUDIOBITRATE];
$options[Audio::OPTION_AUDIOSAMPLERATE] = $config["audio"]["definitions"][$preset][Audio::OPTION_AUDIOSAMPLERATE]; $options[Audio::OPTION_AUDIOSAMPLERATE] = $config["audio"]["definitions"][$preset][Audio::OPTION_AUDIOSAMPLERATE];
$options[Audio::OPTION_ACODEC] = $config["audio"]["definitions"][$preset][Audio::OPTION_ACODEC]; $options[Audio::OPTION_ACODEC] = $config["audio"]["definitions"][$preset][Audio::OPTION_ACODEC];
$options[Audio::OPTION_AUDIOCHANNEL] = $config["audio"]["definitions"][$preset][Audio::OPTION_AUDIOCHANNEL];
foreach ($config["audio"]["definitions"][$preset][Subdef::OPTION_DEVICE] as $devices) { foreach ($config["audio"]["definitions"][$preset][Subdef::OPTION_DEVICE] as $devices) {
$options[Subdef::OPTION_DEVICE][] = $devices; $options[Subdef::OPTION_DEVICE][] = $devices;
} }
@@ -211,7 +212,7 @@ class SubdefsController extends Controller
{ {
$mapping = [ $mapping = [
Type::TYPE_IMAGE => [Subdef::TYPE_IMAGE, Subdef::TYPE_PDF], Type::TYPE_IMAGE => [Subdef::TYPE_IMAGE, Subdef::TYPE_PDF],
Type::TYPE_VIDEO => [Subdef::TYPE_IMAGE, Subdef::TYPE_VIDEO, Subdef::TYPE_ANIMATION], Type::TYPE_VIDEO => [Subdef::TYPE_IMAGE, Subdef::TYPE_VIDEO, Subdef::TYPE_ANIMATION, Subdef::TYPE_AUDIO],
Type::TYPE_AUDIO => [Subdef::TYPE_IMAGE, Subdef::TYPE_AUDIO], Type::TYPE_AUDIO => [Subdef::TYPE_IMAGE, Subdef::TYPE_AUDIO],
Type::TYPE_DOCUMENT => [Subdef::TYPE_IMAGE, Subdef::TYPE_FLEXPAPER, Subdef::TYPE_PDF], Type::TYPE_DOCUMENT => [Subdef::TYPE_IMAGE, Subdef::TYPE_FLEXPAPER, Subdef::TYPE_PDF],
Type::TYPE_FLASH => [Subdef::TYPE_IMAGE] Type::TYPE_FLASH => [Subdef::TYPE_IMAGE]
@@ -525,29 +526,44 @@ class SubdefsController extends Controller
], ],
Subdef::TYPE_AUDIO => [ Subdef::TYPE_AUDIO => [
"definitions" => [ "definitions" => [
"Low AAC 96 kbit/s" => [ "Low MP3 96 kbit/s" => [
Audio::OPTION_AUDIOBITRATE => "100", Audio::OPTION_AUDIOBITRATE => "100",
Audio::OPTION_AUDIOSAMPLERATE => "8000", Audio::OPTION_AUDIOSAMPLERATE => "8000",
Audio::OPTION_ACODEC => "libmp3lame", Audio::OPTION_ACODEC => "libmp3lame",
Subdef::OPTION_DEVICE => ["all"] Subdef::OPTION_DEVICE => ["all"]
], ],
"Normal AAC 128 kbit/s" => [ "Normal MP3 128 kbit/s" => [
Audio::OPTION_AUDIOBITRATE => "180", Audio::OPTION_AUDIOBITRATE => "180",
Audio::OPTION_AUDIOSAMPLERATE => "44100", Audio::OPTION_AUDIOSAMPLERATE => "44100",
Audio::OPTION_ACODEC => "libmp3lame", Audio::OPTION_ACODEC => "libmp3lame",
Subdef::OPTION_DEVICE => ["all"] Subdef::OPTION_DEVICE => ["all"]
], ],
"High AAC 320 kbit/s" => [ "High MP3 320 kbit/s" => [
Audio::OPTION_AUDIOBITRATE => "230", Audio::OPTION_AUDIOBITRATE => "230",
Audio::OPTION_AUDIOSAMPLERATE => "50000", Audio::OPTION_AUDIOSAMPLERATE => "50000",
Audio::OPTION_ACODEC => "libmp3lame", Audio::OPTION_ACODEC => "libmp3lame",
Subdef::OPTION_DEVICE => ["all"] Subdef::OPTION_DEVICE => ["all"]
], ],
"Wave Mono 16 kHz" => [
Audio::OPTION_AUDIOBITRATE => "256",
Audio::OPTION_AUDIOSAMPLERATE => "16000",
Audio::OPTION_ACODEC => "pcm_s16le",
Audio::OPTION_AUDIOCHANNEL => "mono",
Subdef::OPTION_DEVICE => ["all"]
],
"Wave Mono 8 kHz" => [
Audio::OPTION_AUDIOBITRATE => "128",
Audio::OPTION_AUDIOSAMPLERATE => "8000",
Audio::OPTION_ACODEC => "pcm_s16le",
Audio::OPTION_AUDIOCHANNEL => "mono",
Subdef::OPTION_DEVICE => ["all"]
],
], ],
"form" => [ "form" => [
Audio::OPTION_AUDIOBITRATE => "slide", Audio::OPTION_AUDIOBITRATE => "slide",
Audio::OPTION_AUDIOSAMPLERATE => "select", Audio::OPTION_AUDIOSAMPLERATE => "select",
Audio::OPTION_ACODEC => "select", Audio::OPTION_ACODEC => "select",
Audio::OPTION_AUDIOCHANNEL => "select",
Subdef::OPTION_DEVICE => "checkbox", Subdef::OPTION_DEVICE => "checkbox",
], ],
], ],

View File

@@ -233,6 +233,7 @@ class UserController extends Controller
->who_have_right($have_right) ->who_have_right($have_right)
->who_have_not_right($have_not_right) ->who_have_not_right($have_not_right)
->on_base_ids($on_base) ->on_base_ids($on_base)
->include_templates(true)
->execute() ->execute()
->get_results(); ->get_results();

View File

@@ -89,9 +89,10 @@ use Alchemy\Phrasea\Status\StatusStructure;
use Alchemy\Phrasea\TaskManager\LiveInformation; use Alchemy\Phrasea\TaskManager\LiveInformation;
use Alchemy\Phrasea\Utilities\NullableDateTime; use Alchemy\Phrasea\Utilities\NullableDateTime;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use JMS\TranslationBundle\Annotation\Ignore; use Guzzle\Http\Client as Guzzle;
use League\Fractal\Resource\Item; use League\Fractal\Resource\Item;
use media_subdef; use media_subdef;
use Neutron\TemporaryFilesystem\TemporaryFilesystemInterface;
use Symfony\Component\Form\Form; use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -594,6 +595,9 @@ class V1Controller extends Controller
], ],
'separator' => $databox_field->get_separator(), 'separator' => $databox_field->get_separator(),
'thesaurus_branch' => $databox_field->get_tbranch(), 'thesaurus_branch' => $databox_field->get_tbranch(),
'generate_cterms' => $databox_field->get_generate_cterms(),
'gui_editable' => $databox_field->get_gui_editable(),
'gui_visible' => $databox_field->get_gui_visible(),
'type' => $databox_field->get_type(), 'type' => $databox_field->get_type(),
'indexable' => $databox_field->is_indexable(), 'indexable' => $databox_field->is_indexable(),
'multivalue' => $databox_field->is_multi(), 'multivalue' => $databox_field->is_multi(),
@@ -906,19 +910,6 @@ class V1Controller extends Controller
public function addRecordAction(Request $request) public function addRecordAction(Request $request)
{ {
if (count($request->files->get('file')) == 0) {
return $this->getBadRequestAction($request, 'Missing file parameter');
}
$file = $request->files->get('file');
if (!$file instanceof UploadedFile) {
return $this->getBadRequestAction($request, 'You can upload one file at time');
}
if (!$file->isValid()) {
return $this->getBadRequestAction($request, 'Data corrupted, please try again');
}
if (!$request->get('base_id')) { if (!$request->get('base_id')) {
return $this->getBadRequestAction($request, 'Missing base_id parameter'); return $this->getBadRequestAction($request, 'Missing base_id parameter');
} }
@@ -931,16 +922,57 @@ class V1Controller extends Controller
))->createResponse(); ))->createResponse();
} }
// Add file extension if (count($request->files->get('file')) == 0) {
$uploadedFilename = $file->getRealPath(); if(count($request->get('url')) == 0) {
return $this->getBadRequestAction($request, 'Missing file parameter');
}
else {
// upload via url
$url = $request->get('url');
$pi = pathinfo($url); // filename, extension
$renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); /** @var TemporaryFilesystemInterface $tmpFs */
$tmpFs = $this->app['temporary-filesystem'];
$tempfile = $tmpFs->createTemporaryFile('download_', null, $pi['extension']);
$this->getFilesystem()->rename($uploadedFilename, $renamedFilename); try {
$guzzle = new Guzzle($url);
$res = $guzzle->get("", [], ['save_to' => $tempfile])->send();
}
catch (\Exception $e) {
return $this->getBadRequestAction($request, sprintf('Error "%s" downloading "%s"', $e->getMessage(), $url));
}
$media = $this->app->getMediaFromUri($renamedFilename); if($res->getStatusCode() !== 200) {
return $this->getBadRequestAction($request, sprintf('Error %s downloading "%s"', $res->getStatusCode(), $url));
}
$Package = new File($this->app, $media, $collection, $file->getClientOriginalName()); $originalName = $pi['filename'] . '.' . $pi['extension'];
$uploadedFilename = $newPathname = $tempfile;
}
}
else {
// upload via file
$file = $request->files->get('file');
if (!$file instanceof UploadedFile) {
return $this->getBadRequestAction($request, 'You can upload one file at time');
}
if (!$file->isValid()) {
return $this->getBadRequestAction($request, 'Data corrupted, please try again');
}
$uploadedFilename = $file->getPathname();
$originalName = $file->getClientOriginalName();
$newPathname = $file->getPathname() . '.' . $file->getClientOriginalExtension();
if (false === rename($file->getPathname(), $newPathname)) {
return Result::createError($request, 403, 'Error while renaming file')->createResponse();
}
}
$media = $this->app->getMediaFromUri($newPathname);
$Package = new File($this->app, $media, $collection, $originalName);
if ($request->get('status')) { if ($request->get('status')) {
$Package->addAttribute(new Status($this->app, $request->get('status'))); $Package->addAttribute(new Status($this->app, $request->get('status')));
@@ -985,6 +1017,11 @@ class V1Controller extends Controller
$nosubdef = $request->get('nosubdefs') === '' || \p4field::isyes($request->get('nosubdefs')); $nosubdef = $request->get('nosubdefs') === '' || \p4field::isyes($request->get('nosubdefs'));
$this->getBorderManager()->process($session, $Package, $callback, $behavior, $nosubdef); $this->getBorderManager()->process($session, $Package, $callback, $behavior, $nosubdef);
// remove $newPathname on temporary directory
if ($newPathname !== $uploadedFilename) {
@rename($newPathname, $uploadedFilename);
}
$ret = ['entity' => null]; $ret = ['entity' => null];
if ($output instanceof \record_adapter) { if ($output instanceof \record_adapter) {
@@ -1056,6 +1093,11 @@ class V1Controller extends Controller
} }
} }
// remove $newPathname on temporary directory
if ($renamedFilename !== $uploadedFilename) {
@rename($renamedFilename, $uploadedFilename);
}
return Result::create($request, $ret)->createResponse(); return Result::create($request, $ret)->createResponse();
} }
@@ -1966,7 +2008,7 @@ class V1Controller extends Controller
return $this->getBadRequestAction($request); return $this->getBadRequestAction($request);
} }
$datas = substr($datas, 0, ($n)) . $value . substr($datas, ($n + 2)); $datas = substr($datas, 0, ($n)) . $value . substr($datas, ($n + 1));
} }
$record->setStatus(strrev($datas)); $record->setStatus(strrev($datas));
@@ -2570,8 +2612,18 @@ class V1Controller extends Controller
foreach ($recordsData as $data) { foreach ($recordsData as $data) {
$records[] = $this->addOrDelStoryRecord($story, $data, $action); $records[] = $this->addOrDelStoryRecord($story, $data, $action);
if($action === 'ADD' && !$cover_set && isset($data->{'use_as_cover'}) && $data->{'use_as_cover'} === true) { if($action === 'ADD' && !$cover_set && isset($data->{'use_as_cover'}) && $data->{'use_as_cover'} === true) {
$coverSource = [];
if (isset($data->{'thumbnail_cover_source'})) {
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
}
if (isset($data->{'preview_cover_source'})) {
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
}
// because we can try many records as cover source, we let it fail // because we can try many records as cover source, we let it fail
$cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true) !== false); $cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true, $coverSource) !== false);
} }
} }
@@ -2625,14 +2677,26 @@ class V1Controller extends Controller
$story = new \record_adapter($this->app, $databox_id, $story_id); $story = new \record_adapter($this->app, $databox_id, $story_id);
$coverSource = [];
if (isset($data->{'thumbnail_cover_source'})) {
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
}
if (isset($data->{'preview_cover_source'})) {
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
}
// we do NOT let "setStoryCover()" fail : pass false as last arg // we do NOT let "setStoryCover()" fail : pass false as last arg
$record_key = $this->setStoryCover($story, $data->{'record_id'}, false); $record_key = $this->setStoryCover($story, $data->{'record_id'}, false, $coverSource);
return Result::create($request, array($record_key))->createResponse(); return Result::create($request, array($record_key))->createResponse();
} }
protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false) protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false, $coverSource = [])
{ {
$coverSource = array_merge(['thumbnail_cover_source' => 'thumbnail', 'preview_cover_source' => 'preview'], $coverSource);
try { try {
$record = new \record_adapter($this->app, $story->getDataboxId(), $record_id); $record = new \record_adapter($this->app, $story->getDataboxId(), $record_id);
} catch (\Exception_Record_AdapterNotFound $e) { } catch (\Exception_Record_AdapterNotFound $e) {
@@ -2644,18 +2708,22 @@ class V1Controller extends Controller
$this->app->abort(404, sprintf('Record identified by databox_id %s and record_id %s is not in the story', $story->getDataboxId(), $record_id)); $this->app->abort(404, sprintf('Record identified by databox_id %s and record_id %s is not in the story', $story->getDataboxId(), $record_id));
} }
if ($record->getType() !== 'image' && $record->getType() !== 'video') { // taking account all record type as a cover
// this can fail so we can loop on many records during story creation... // if ($record->getType() !== 'image' && $record->getType() !== 'video') {
if($can_fail) { // // this can fail so we can loop on many records during story creation...
return false; // if($can_fail) {
} // return false;
$this->app->abort(403, sprintf('Record identified by databox_id %s and record_id %s is not an image nor a video', $story->getDataboxId(), $record_id)); // }
} // $this->app->abort(403, sprintf('Record identified by databox_id %s and record_id %s is not an image nor a video', $story->getDataboxId(), $record_id));
// }
foreach ($record->get_subdefs() as $name => $value) { foreach ($record->get_subdefs() as $name => $value) {
if (!in_array($name, array('thumbnail', 'preview'))) { if (!($key = array_search($name, $coverSource))) {
continue; continue;
} }
$name = ($key == 'thumbnail_cover_source') ? 'thumbnail': 'preview';
$media = $this->app->getMediaFromUri($value->getRealPath()); $media = $this->app->getMediaFromUri($value->getRealPath());
$this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview $this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview
$this->getDataboxLogger($story->getDatabox())->log( $this->getDataboxLogger($story->getDatabox())->log(

View File

@@ -74,10 +74,10 @@ class PermalinkController extends AbstractDelivery
public function deliverPermaview(Request $request, $sbas_id, $record_id, $subdef) public function deliverPermaview(Request $request, $sbas_id, $record_id, $subdef)
{ {
return $this->doDeliverPermaview($sbas_id, $record_id, $request->query->get('token'), $subdef); return $this->doDeliverPermaview($sbas_id, $record_id, $request->query->get('token'), $subdef, $request->query->get('t'));
} }
private function doDeliverPermaview($sbas_id, $record_id, $token, $subdefName) private function doDeliverPermaview($sbas_id, $record_id, $token, $subdefName, $currentTime = null)
{ {
$databox = $this->findDataboxById($sbas_id); $databox = $this->findDataboxById($sbas_id);
$record = $this->retrieveRecord($databox, $token, $record_id, $subdefName); $record = $this->retrieveRecord($databox, $token, $record_id, $subdefName);
@@ -105,6 +105,7 @@ class PermalinkController extends AbstractDelivery
'token' => $token, 'token' => $token,
'record' => $record, 'record' => $record,
'recordUrl' => $information->getUrl(), 'recordUrl' => $information->getUrl(),
'currentTime' => $currentTime
]); ]);
} }

View File

@@ -75,6 +75,9 @@ class EditController extends Controller
'format' => '', 'format' => '',
'explain' => '', 'explain' => '',
'tbranch' => $meta->get_tbranch(), 'tbranch' => $meta->get_tbranch(),
'generate_cterms' => $meta->get_generate_cterms(),
'gui_editable' => $meta->get_gui_editable(),
'gui_visible' => $meta->get_gui_visible(),
'maxLength' => $meta->get_tag() 'maxLength' => $meta->get_tag()
->getMaxLength(), ->getMaxLength(),
'minLength' => $meta->get_tag() 'minLength' => $meta->get_tag()

View File

@@ -38,7 +38,7 @@ class LazaretController extends Controller
* *
* @param Request $request The current request * @param Request $request The current request
* *
* @return Response * @return String
*/ */
public function listElement(Request $request) public function listElement(Request $request)
{ {
@@ -70,7 +70,7 @@ class LazaretController extends Controller
public function getElement($file_id) public function getElement($file_id)
{ {
$ret = ['success' => false, 'message' => '', 'result' => []]; $ret = ['success' => false, 'message' => '', 'result' => []];
/* @var LazaretFile $lazaretFile */ /* @var LazaretFile $lazaretFile */
$lazaretFile = $this->getLazaretFileRepository()->find($file_id); $lazaretFile = $this->getLazaretFileRepository()->find($file_id);
@@ -126,6 +126,16 @@ class LazaretController extends Controller
$ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep); $ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep);
try{
// get the new record
$record = \Collection::getByBaseId($this->app, $request->request->get('bas_id'))->get_databox()->get_record($ret['result']['record_id']);
$postStatus = (array) $request->request->get('status');
// update status
$this->updateRecordStatus($record, $postStatus);
}catch(\Exception $e){
$ret['message'] = $this->app->trans('An error occured when wanting to change status!');
}
return $this->app->json($ret); return $this->app->json($ret);
} }
@@ -216,6 +226,7 @@ class LazaretController extends Controller
return $this->app->json($ret); return $this->app->json($ret);
} }
$postStatus = (array) $request->request->get('status');
$path = $this->app['tmp.lazaret.path'] . '/'; $path = $this->app['tmp.lazaret.path'] . '/';
$lazaretFileName = $path .$lazaretFile->getFilename(); $lazaretFileName = $path .$lazaretFile->getFilename();
@@ -233,6 +244,9 @@ class LazaretController extends Controller
'' ''
); );
// update status
$this->updateRecordStatus($record, $postStatus);
//Delete lazaret file //Delete lazaret file
$manager = $this->getEntityManager(); $manager = $this->getEntityManager();
$manager->remove($lazaretFile); $manager->remove($lazaretFile);
@@ -278,6 +292,35 @@ class LazaretController extends Controller
); );
} }
/**
* @param Request $request
* @param $databox_id
* @param $record_id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function getDestinationStatus(Request $request, $databox_id, $record_id)
{
if (!$request->isXmlHttpRequest()) {
$this->app->abort(400);
}
$record = new \record_adapter($this->app, (int) $databox_id, (int) $record_id);
$databox = $this->findDataboxById($databox_id);
$statusStructure = $databox->getStatusStructure();
$recordsStatuses = [];
foreach ($statusStructure as $status) {
// make the key as a string for the json usage in javascript
$bit = "'".$status['bit']."'";
if (!isset($recordsStatuses[$bit])) {
$recordsStatuses[$bit] = $status;
}
$statusSet = \databox_status::bitIsSet($record->getStatusBitField(), $status['bit']);
if (!isset($recordsStatuses[$bit]['flag'])) {
$recordsStatuses[$bit]['flag'] = (int) $statusSet;
}
}
return $this->app->json(['status' => $recordsStatuses]);
}
/** /**
* @return LazaretFileRepository * @return LazaretFileRepository
*/ */
@@ -293,4 +336,32 @@ class LazaretController extends Controller
{ {
return $this->app['border-manager']; return $this->app['border-manager'];
} }
/**
* Set new status to selected record
*
* @param \record_adapter $record
* @param array $postStatus
* @return array|null
*/
private function updateRecordStatus(\record_adapter $record, array $postStatus)
{
$sbasId = $record->getDataboxId();
if (isset($postStatus[$sbasId]) && is_array($postStatus[$sbasId])) {
$postStatus = $postStatus[$sbasId];
$currentStatus = strrev($record->getStatus());
$newStatus = '';
foreach (range(0, 31) as $i) {
$newStatus .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : $currentStatus[$i];
}
$record->setStatus(strrev($newStatus));
$this->getDataboxLogger($record->getDatabox())
->log($record, \Session_Logger::EVENT_STATUS, '', '');
return [
'current_status' => $currentStatus,
'new_status' => $newStatus,
];
}
return null;
}
} }

View File

@@ -114,6 +114,7 @@ class MoveCollectionController extends Controller
$trashCollectionsBySbasId = []; $trashCollectionsBySbasId = [];
foreach ($records as $record) { foreach ($records as $record) {
$oldCollectionId = $record->getCollection()->get_coll_id();
$record->move_to_collection($collection, $this->getApplicationBox()); $record->move_to_collection($collection, $this->getApplicationBox());
if ($request->request->get("chg_coll_son") == "1") { if ($request->request->get("chg_coll_son") == "1") {
@@ -130,7 +131,7 @@ class MoveCollectionController extends Controller
$trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection(); $trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection();
} }
if ($trashCollectionsBySbasId[$sbasId] !== null) { if ($trashCollectionsBySbasId[$sbasId] !== null) {
if ($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id() && $collection->get_coll_id() !== $trashCollectionsBySbasId[$sbasId]->get_coll_id()) { if ($oldCollectionId == $trashCollectionsBySbasId[$sbasId]->get_coll_id() && $collection->get_coll_id() !== $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
// record is already in trash so active it // record is already in trash so active it
foreach ($record->get_subdefs() as $subdef) { foreach ($record->get_subdefs() as $subdef) {
if (($pl = $subdef->get_permalink())) { if (($pl = $subdef->get_permalink())) {

View File

@@ -9,6 +9,7 @@
*/ */
namespace Alchemy\Phrasea\Controller\Prod; namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Controller\RecordsRequest;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -16,6 +17,8 @@ use Symfony\Component\HttpFoundation\Response;
class PropertyController extends Controller class PropertyController extends Controller
{ {
use DataboxLoggerAware;
/** /**
* Display Status property * Display Status property
* *
@@ -198,6 +201,9 @@ class PropertyController extends Controller
$record->setStatus(strrev($newStatus)); $record->setStatus(strrev($newStatus));
$this->getDataboxLogger($record->getDatabox())
->log($record, \Session_Logger::EVENT_STATUS, '', '');
return [ return [
'current_status' => $currentStatus, 'current_status' => $currentStatus,
'new_status' => $newStatus, 'new_status' => $newStatus,

View File

@@ -463,6 +463,8 @@ class PushController extends Controller
} }
try { try {
$manager = $this->getEntityManager();
$password = $this->getRandomGenerator()->generateString(128); $password = $this->getRandomGenerator()->generateString(128);
$user = $this->getUserManipulator()->createUser($email, $password, $email); $user = $this->getUserManipulator()->createUser($email, $password, $email);
@@ -476,12 +478,15 @@ class PushController extends Controller
$user->setCompany($request->request->get('company')); $user->setCompany($request->request->get('company'));
} }
if ($request->request->get('job')) { if ($request->request->get('job')) {
$user->setCompany($request->request->get('job')); $user->setJob($request->request->get('job'));
} }
if ($request->request->get('form_geonameid')) { if ($request->request->get('city')) {
$this->getUserManipulator()->setGeonameId($user, $request->request->get('form_geonameid')); $this->getUserManipulator()->setGeonameId($user, $request->request->get('city'));
} }
$manager->persist($user);
$manager->flush();
$result['message'] = $this->app->trans('User successfully created'); $result['message'] = $this->app->trans('User successfully created');
$result['success'] = true; $result['success'] = true;
$result['user'] = $this->formatUser($user); $result['user'] = $this->formatUser($user);

View File

@@ -161,7 +161,32 @@ class QueryController extends Controller
$result = $engine->query($query, $options); $result = $engine->query($query, $options);
if ($this->getSettings()->getUserSetting($user, 'start_page') === 'LAST_QUERY') { if ($this->getSettings()->getUserSetting($user, 'start_page') === 'LAST_QUERY') {
$userManipulator->setUserSetting($user, 'start_page_query', $query); // try to save the "fulltext" query which will be restored on next session
try {
// local code to find "FULLTEXT" value from jsonQuery
$findFulltext = function($clause) use(&$findFulltext) {
if(array_key_exists('_ux_zone', $clause) && $clause['_ux_zone']=='FULLTEXT') {
return $clause['value'];
}
if($clause['type']=='CLAUSES') {
foreach($clause['clauses'] as $c) {
if(($r = $findFulltext($c)) !== null) {
return $r;
}
}
}
return null;
};
$userManipulator->setUserSetting($user, 'last_jsonquery', (string)$request->request->get('jsQuery'));
$jsQuery = @json_decode((string)$request->request->get('jsQuery'), true);
if(($ft = $findFulltext($jsQuery['query'])) !== null) {
$userManipulator->setUserSetting($user, 'start_page_query', $ft);
}
}
catch(\Exception $e) {
// no-op
}
} }
// log array of collectionIds (from $options) for each databox // log array of collectionIds (from $options) for each databox
@@ -189,7 +214,7 @@ class QueryController extends Controller
if (min($d2top, $d2bottom) < 4) { if (min($d2top, $d2bottom) < 4) {
if ($d2bottom < 4) { if ($d2bottom < 4) {
if($page != 1){ if($page != 1){
$string .= "<a id='PREV_PAGE' class='btn btn-primary btn-mini'></a>"; $string .= "<a id='PREV_PAGE' class='btn btn-primary btn-mini icon-baseline-chevron_left-24px'></a>";
} }
for ($i = 1; ($i <= 4 && (($i <= $npages) === true)); $i++) { for ($i = 1; ($i <= 4 && (($i <= $npages) === true)); $i++) {
if ($i == $page) if ($i == $page)
@@ -198,13 +223,13 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>'; $string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
} }
if ($npages > 4) if ($npages > 4)
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini'></a>"; $string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini icon icon-baseline-chevron_right-24px'></a>";
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action" data-page="' . $npages . '" id="last"></a>'; $string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action icon icon-double-arrows" data-page="' . $npages . '" id="last"></a>';
} else { } else {
$start = $npages - 4; $start = $npages - 4;
if (($start) > 0){ if (($start) > 0){
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"></a>'; $string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"><span class="icon icon-double-arrows icon-inverse"></span></a>';
$string .= '<a id="PREV_PAGE" class="btn btn-primary btn-mini"></a>'; $string .= '<a id="PREV_PAGE" class="btn btn-primary btn-mini icon icon-baseline-chevron_left-24px"></a>';
}else }else
$start = 1; $start = 1;
for ($i = ($start); $i <= $npages; $i++) { for ($i = ($start); $i <= $npages; $i++) {
@@ -214,11 +239,11 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>'; $string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
} }
if($page < $npages){ if($page < $npages){
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini'></a>"; $string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini icon icon-baseline-chevron_right-24px'></a>";
} }
} }
} else { } else {
$string .= '<a class="btn btn-primary btn-mini btn-mini search-navigate-action" data-page="1" id="first"></a>'; $string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"><span class="icon icon-double-arrows icon-inverse"></span></a>';
for ($i = ($page - 2); $i <= ($page + 2); $i++) { for ($i = ($page - 2); $i <= ($page + 2); $i++) {
if ($i == $page) if ($i == $page)
@@ -227,10 +252,10 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>'; $string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
} }
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action" data-page="' . $npages . '" id="last"></a>'; $string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action icon icon-double-arrows" data-page="' . $npages . '" id="last"></a>';
} }
} }
$string .= '<div style="display:none;"><div id="NEXT_PAGE"></div><div id="PREV_PAGE"></div></div>'; $string .= '<div style="display:none;"><div id="NEXT_PAGE" class="icon icon-baseline-chevron_right-24px"></div><div id="PREV_PAGE" class="icon icon-baseline-chevron_left-24px"></div></div>';
$explain = $this->render( $explain = $this->render(
"prod/results/infos.html.twig", "prod/results/infos.html.twig",
@@ -291,7 +316,7 @@ class QueryController extends Controller
</tfoot> </tfoot>
</table></div></div>' </table></div></div>'
. '</div><a href="#" class="search-display-info" data-infos="' . str_replace('"', '&quot;', $explain) . '">' . '</div><a href="#" class="search-display-info" data-infos="' . str_replace('"', '&quot;', $explain) . '">'
. $this->app->trans('%total% reponses', ['%total%' => '<span>'.$result->getTotal().'</span>']) . '</a>'; . $this->app->trans('%total% reponses', ['%total%' => '<span>'.number_format($result->getTotal(),null, null, ' ').'</span>']) . '</a>';
$json['infos'] = $infoResult; $json['infos'] = $infoResult;
$json['navigationTpl'] = $string; $json['navigationTpl'] = $string;
@@ -323,9 +348,14 @@ class QueryController extends Controller
// add technical fields // add technical fields
$fieldLabels = []; $fieldsInfosByName = [];
foreach(ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) { foreach(ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) {
$fieldLabels[$k] = $this->app->trans($f['label']); $fieldsInfosByName[$k] = $f;
$fieldsInfosByName[$k]['trans_label'] = $this->app->trans($f['label']);
$fieldsInfosByName[$k]['labels'] = [];
foreach($this->app->getAvailableLanguages() as $locale => $lng) {
$fieldsInfosByName[$k]['labels'][$locale] = $this->app->trans($f['label'], [], "messages", $locale);
}
} }
// add databox fields // add databox fields
@@ -337,13 +367,24 @@ class QueryController extends Controller
foreach ($databox->get_meta_structure() as $field) { foreach ($databox->get_meta_structure() as $field) {
$name = $field->get_name(); $name = $field->get_name();
$fieldsInfos[$sbasId][$name] = [ $fieldsInfos[$sbasId][$name] = [
'label' => $field->get_label($this->app['locale']), 'label' => $field->get_label($this->app['locale']),
'type' => $field->get_type(), 'labels' => $field->get_labels(),
'type' => $field->get_type(),
'business' => $field->isBusiness(), 'business' => $field->isBusiness(),
'multi' => $field->is_multi(), 'multi' => $field->is_multi(),
]; ];
if (!isset($fieldLabels[$name])) {
$fieldLabels[$name] = $field->get_label($this->app['locale']); // infos on the "same" field (by name) on multiple databoxes !!!
// label(s) can be inconsistants : the first databox wins
if (!isset($fieldsInfosByName[$name])) {
$fieldsInfosByName[$name] = [
'label' => $field->get_label($this->app['locale']),
'labels' => $field->get_labels(),
'type' => $field->get_type(),
'field' => $field->get_name(),
'trans_label' => $field->get_label($this->app['locale']),
];
$field->get_label($this->app['locale']);
} }
} }
} }
@@ -382,14 +423,29 @@ class QueryController extends Controller
// populates facets (aggregates) // populates facets (aggregates)
$facets = []; $facets = [];
// $facetClauses = [];
foreach ($result->getFacets() as $facet) { foreach ($result->getFacets() as $facet) {
$facetName = $facet['name']; $facetName = $facet['name'];
$facet['label'] = isset($fieldLabels[$facetName]) ? $fieldLabels[$facetName] : $facetName; if(array_key_exists($facetName, $fieldsInfosByName)) {
$facets[] = $facet; $f = $fieldsInfosByName[$facetName];
$facet['label'] = $f['trans_label'];
$facet['labels'] = $f['labels'];
$facet['type'] = strtoupper($f['type']) . "-AGGREGATE";
$facets[] = $facet;
// $facetClauses[] = [
// 'type' => strtoupper($f['type']) . "-AGGREGATE",
// 'field' => $f['field'],
// 'facet' => $facet
// ];
}
} }
// $json['jsq'] = $facetClauses;
$json['facets'] = $facets; $json['facets'] = $facets;
$json['phrasea_props'] = $proposals; $json['phrasea_props'] = $proposals;
$json['total_answers'] = (int) $result->getAvailable(); $json['total_answers'] = (int) $result->getAvailable();
@@ -413,7 +469,6 @@ class QueryController extends Controller
$json['results'] = $this->render($template, ['results'=> $result]); $json['results'] = $this->render($template, ['results'=> $result]);
} }
return $this->app->json($json); return $this->app->json($json);
} }

View File

@@ -90,35 +90,44 @@ class RecordController extends Controller
} }
$recordCaptions["technicalInfo"] = $record->getPositionFromTechnicalInfos(); $recordCaptions["technicalInfo"] = $record->getPositionFromTechnicalInfos();
// escape record title before rendering
$recordTitle = explode("</span>", $record->get_title());
if (count($recordTitle) >1) {
$recordTitle[1] = htmlspecialchars($recordTitle[1]);
$recordTitle = implode("</span>", $recordTitle);
} else {
$recordTitle = htmlspecialchars($record->get_title());
}
return $this->app->json([ return $this->app->json([
"desc" => $this->render('prod/preview/caption.html.twig', [ "desc" => $this->render('prod/preview/caption.html.twig', [
'record' => $record, 'record' => $record,
'highlight' => $query, 'highlight' => $query,
'searchEngine' => $searchEngine, 'searchEngine' => $searchEngine,
'searchOptions' => $options, 'searchOptions' => $options,
]), ]),
"recordCaptions"=> $recordCaptions, "recordCaptions" => $recordCaptions,
"html_preview" => $this->render('common/preview.html.twig', [ "html_preview" => $this->render('common/preview.html.twig', [
'record' => $record 'record' => $record
]), ]),
"others" => $this->render('prod/preview/appears_in.html.twig', [ "others" => $this->render('prod/preview/appears_in.html.twig', [
'parents' => $record->get_grouping_parents(), 'parents' => $record->get_grouping_parents(),
'baskets' => $record->get_container_baskets($this->getEntityManager(), $this->getAuthenticatedUser()), 'baskets' => $record->get_container_baskets($this->getEntityManager(), $this->getAuthenticatedUser()),
]), ]),
"current" => $train, "current" => $train,
"record" => $currentRecord, "record" => $currentRecord,
"history" => $this->render('prod/preview/short_history.html.twig', [ "history" => $this->render('prod/preview/short_history.html.twig', [
'record' => $record, 'record' => $record,
]), ]),
"popularity" => $this->render('prod/preview/popularity.html.twig', [ "popularity" => $this->render('prod/preview/popularity.html.twig', [
'record' => $record, 'record' => $record,
]), ]),
"tools" => $this->render('prod/preview/tools.html.twig', [ "tools" => $this->render('prod/preview/tools.html.twig', [
'record' => $record, 'record' => $record,
]), ]),
"pos" => $record->getNumber(), "pos" => $record->getNumber(),
"title" => $record->get_title(), "title" => $recordTitle,
"databox_name" => $record->getDatabox()->get_dbname(), "databox_name" => $record->getDatabox()->get_dbname(),
"collection_name" => $record->getCollection()->get_name(), "collection_name" => $record->getCollection()->get_name(),
"collection_logo" => $record->getCollection()->getLogo($record->getBaseId(), $this->app), "collection_logo" => $record->getCollection()->getLogo($record->getBaseId(), $this->app),
]); ]);

View File

@@ -15,12 +15,11 @@ use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
use Alchemy\Phrasea\Exception\SessionNotFound; use Alchemy\Phrasea\Exception\SessionNotFound;
use Alchemy\Phrasea\Feed\Aggregate; use Alchemy\Phrasea\Feed\Aggregate;
use Alchemy\Phrasea\Helper; use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\Model\Entities\UserSetting; use Alchemy\Phrasea\Helper\WorkZone as WorkzoneHelper;
use Alchemy\Phrasea\Model\Repositories\FeedRepository; use Alchemy\Phrasea\Model\Repositories\FeedRepository;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class RootController extends Controller class RootController extends Controller
{ {
use Application\Helper\FirewallAware; use Application\Helper\FirewallAware;
@@ -41,12 +40,11 @@ class RootController extends Controller
public function indexAction(Request $request) { public function indexAction(Request $request) {
try { try {
\Session_Logger::updateClientInfos($this->app, 1); \Session_Logger::updateClientInfos($this->app, 1);
} catch (SessionNotFound $e) { }
catch (SessionNotFound $e) {
return $this->app->redirectPath('logout'); return $this->app->redirectPath('logout');
} }
$css = [];
$user = $this->getAuthenticatedUser(); $user = $this->getAuthenticatedUser();
$cssfile = $this->getSettings()->getUserSetting($user, 'css'); $cssfile = $this->getSettings()->getUserSetting($user, 'css');
@@ -85,6 +83,22 @@ class RootController extends Controller
/** @var \Closure $filter */ /** @var \Closure $filter */
$filter = $this->app['plugin.filter_by_authorization']; $filter = $this->app['plugin.filter_by_authorization'];
/* prepare work to extend whole taskbar... later
$menus = [
'push' => ['native'=>true, 'n'=>0],
'tools' => ['native'=>true, 'n'=>0],
];
/ ** @var ActionBarPluginInterface $plugin * /
foreach($filter('actionbar') as $kplugin=>$plugin) {
foreach($plugin->getActionBar() as $kmenu=>$menu) {
if(!array_key_exists($kmenu, $menus)) {
$menus[$kmenu] = ['native'=>false, 'n'=>0];
}
$menus[$kmenu]['n']++;
}
}
*/
$plugins = [ $plugins = [
'workzone' => $filter('workzone'), 'workzone' => $filter('workzone'),
'actionbar' => $filter('actionbar'), 'actionbar' => $filter('actionbar'),
@@ -92,7 +106,7 @@ class RootController extends Controller
return $this->render('prod/index.html.twig', [ return $this->render('prod/index.html.twig', [
'module_name' => 'Production', 'module_name' => 'Production',
'WorkZone' => new Helper\WorkZone($this->app, $request), 'WorkZone' => new WorkzoneHelper($this->app, $request),
'module_prod' => $helper, 'module_prod' => $helper,
'search_datas' => $helper->get_search_datas(), 'search_datas' => $helper->get_search_datas(),
'cssfile' => $cssfile, 'cssfile' => $cssfile,
@@ -105,7 +119,7 @@ class RootController extends Controller
'feeds' => $feeds, 'feeds' => $feeds,
'aggregate' => $aggregate, 'aggregate' => $aggregate,
'GV_google_api' => $conf->get(['registry', 'webservices', 'google-charts-enabled']), 'GV_google_api' => $conf->get(['registry', 'webservices', 'google-charts-enabled']),
'geocodingProviders' => $conf->get(['geocoding-providers']), 'geocodingProviders' => $conf->get(['geocoding-providers']),
'search_status' => \databox_status::getSearchStatus($this->app), 'search_status' => \databox_status::getSearchStatus($this->app),
'thesau_js_list' => $thjslist, 'thesau_js_list' => $thjslist,
'thesau_json_sbas' => json_encode($sbas), 'thesau_json_sbas' => json_encode($sbas),

View File

@@ -26,6 +26,7 @@ use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Model\Entities\LazaretSession; use Alchemy\Phrasea\Model\Entities\LazaretSession;
use DataURI\Exception\Exception as DataUriException; use DataURI\Exception\Exception as DataUriException;
use DataURI\Parser; use DataURI\Parser;
use Guzzle\Http\Client as Guzzle;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -76,6 +77,30 @@ class UploadController extends Controller
]); ]);
} }
public function getHead(Request $request)
{
$response = [
'content-type' => null,
'content-length' => null,
'basename' => null
];
try {
$url = $request->get('url');
$basename = pathinfo($url, PATHINFO_BASENAME);
$guzzle = new Guzzle($url);
$res = $guzzle->head("")->send();
$response['content-type'] = $res->getContentType();
$response['content-length'] = $res->getContentLength();
$response['basename'] = $basename;
}
catch (\Exception $e) {
// no-op : head will return no info but will not crash
}
return $this->app->json($response);
}
/** /**
* Upload processus * Upload processus
* *
@@ -98,7 +123,7 @@ class UploadController extends Controller
'message' => '', 'message' => '',
'element' => '', 'element' => '',
'reasons' => [], 'reasons' => [],
'id' => '', 'id' => '',
]; ];
if (null === $request->files->get('files')) { if (null === $request->files->get('files')) {
@@ -119,18 +144,44 @@ class UploadController extends Controller
throw new AccessDeniedHttpException('User is not allowed to add record on this collection'); throw new AccessDeniedHttpException('User is not allowed to add record on this collection');
} }
/** @var UploadedFile $file */
$file = current($request->files->get('files')); $file = current($request->files->get('files'));
if (!$file->isValid()) { if (!$file->isValid()) {
throw new BadRequestHttpException('Uploaded file is invalid'); throw new BadRequestHttpException('Uploaded file is invalid');
} }
try { if ($file->getClientOriginalName() === "blob" && $file->getClientMimeType() === "application/json") {
// a "upload by url" was done, we receive a tiny json that contains url.
$json = json_decode(file_get_contents($file->getRealPath()), true);
$url = $json['url'];
$pi = pathinfo($url); // filename, extension
$tempfile = $this->getTemporaryFilesystem()->createTemporaryFile('download_', null, $pi['extension']);
try {
$guzzle = new Guzzle($url);
$res = $guzzle->get("", [], ['save_to' => $tempfile])->send();
}
catch (\Exception $e) {
throw new BadRequestHttpException(sprintf('Error "%s" downloading "%s"', $e->getMessage(), $url));
}
if($res->getStatusCode() !== 200) {
throw new BadRequestHttpException(sprintf('Error %s downloading "%s"', $res->getStatusCode(), $url));
}
$uploadedFilename = $renamedFilename = $tempfile;
$originalName = $pi['filename'] . '.' . $pi['extension'];
} else {
// Add file extension, so mediavorus can guess file type for octet-stream file // Add file extension, so mediavorus can guess file type for octet-stream file
$uploadedFilename = $file->getRealPath(); $uploadedFilename = $file->getRealPath();
$renamedFilename = null; $renamedFilename = null;
if(!empty($this->app['conf']->get(['main', 'storage', 'tmp_files']))){ if(!empty($this->app['conf']->get(['main', 'storage', 'tmp_files']))) {
$tmpStorage = \p4string::addEndSlash($this->app['conf']->get(['main', 'storage', 'tmp_files'])).'upload/'; $tmpStorage = \p4string::addEndSlash($this->app['conf']->get(['main', 'storage', 'tmp_files'])).'upload/';
if(!is_dir($tmpStorage)){ if(!is_dir($tmpStorage)){
@@ -139,12 +190,16 @@ class UploadController extends Controller
$renamedFilename = $tmpStorage. pathinfo($file->getRealPath(), PATHINFO_FILENAME) .'.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); $renamedFilename = $tmpStorage. pathinfo($file->getRealPath(), PATHINFO_FILENAME) .'.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
}else{ } else {
$renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); $renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
} }
$this->getFilesystem()->rename($uploadedFilename, $renamedFilename); $this->getFilesystem()->rename($uploadedFilename, $renamedFilename);
$originalName = $file->getClientOriginalName();
}
try {
$media = $this->app->getMediaFromUri($renamedFilename); $media = $this->app->getMediaFromUri($renamedFilename);
$collection = \collection::getByBaseId($this->app, $base_id); $collection = \collection::getByBaseId($this->app, $base_id);
@@ -153,7 +208,7 @@ class UploadController extends Controller
$this->getEntityManager()->persist($lazaretSession); $this->getEntityManager()->persist($lazaretSession);
$packageFile = new File($this->app, $media, $collection, $file->getClientOriginalName()); $packageFile = new File($this->app, $media, $collection, $originalName);
$postStatus = $request->request->get('status'); $postStatus = $request->request->get('status');
@@ -184,7 +239,9 @@ class UploadController extends Controller
$code = $this->getBorderManager()->process( $lazaretSession, $packageFile, $callback, $forceBehavior); $code = $this->getBorderManager()->process( $lazaretSession, $packageFile, $callback, $forceBehavior);
$this->getFilesystem()->rename($renamedFilename, $uploadedFilename); if($renamedFilename !== $uploadedFilename) {
$this->getFilesystem()->rename($renamedFilename, $uploadedFilename);
}
if (!!$forceBehavior) { if (!!$forceBehavior) {
$reasons = []; $reasons = [];
@@ -310,15 +367,17 @@ class UploadController extends Controller
$postMaxSize = PHP_INT_MAX; $postMaxSize = PHP_INT_MAX;
} }
$r = 0;
switch (strtolower(substr($postMaxSize, -1))) { switch (strtolower(substr($postMaxSize, -1))) {
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case 'g': case 'g':
$postMaxSize *= 1024; $r += 10;
/** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */
case 'm': case 'm':
$postMaxSize *= 1024; $r += 10;
case 'k': case 'k':
$postMaxSize *= 1024; $r += 10;
$postMaxSize = ((int)($postMaxSize))<<$r;
} }
return min(UploadedFile::getMaxFilesize(), (int) $postMaxSize); return min(UploadedFile::getMaxFilesize(), (int) $postMaxSize);

View File

@@ -1,802 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Report;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
use Goodby\CSV\Export\Standard\Exporter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ActivityController extends Controller
{
/**
* Display connexions report group by user
*
* @param Request $request
* @return JsonResponse
*/
public function doReportConnexionsByUsers(Request $request)
{
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
$activity->setBound("user", true);
//set Limit
if ($activity->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$activity->setLimit($page, $limit);
} else {
$activity->setLimit(false, false);
}
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->getConnexionBase(false, $request->request->get('on', 'user'));
return $this->getCSVResponse($activity, 'activity_connection_base');
}
$report = $activity->getConnexionBase(false, $request->request->get('on', 'user'));
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => false,
'title' => false,
]);
}
/**
* Display download report group by user
*
* @param Request $request
* @return JsonResponse
*/
public function doReportDownloadsByUsers(Request $request)
{
$conf = [
'user' => [$this->app->trans('report:: utilisateur'), 0, 1, 0, 0],
'nbdoc' => [$this->app->trans('report:: nombre de documents'), 0, 0, 0, 0],
'nbprev' => [$this->app->trans('report:: nombre de preview'), 0, 0, 0, 0],
];
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
//set Limit
if ($activity->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$activity->setLimit($page, $limit);
} else {
$activity->setLimit(false, false);
}
$report = $activity->getDetailDownload($conf, $request->request->get('on'));
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
return $this->getCSVResponse($activity, 'activity_detail_download');
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => false,
'title' => false,
]);
}
/**
* Display the most asked question
*
* @param Request $request
* @return JsonResponse
*/
public function doReportBestOfQuestions(Request $request)
{
$conf = [
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'nb_rep' => [$this->app->trans('report:: nombre de reponses'), 0, 0, 0, 0]
];
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setLimit(1, $request->request->get('limit', 20));
$activity->setTop(20);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$activity->getTopQuestion($conf);
return $this->getCSVResponse($activity, 'activity_questions_best_of');
}
$report = $activity->getTopQuestion($conf);
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => false,
'title' => false
]);
}
/**
* Display report about questions that return no result
*
* @param Request $request
* @return JsonResponse
*/
public function doReportNoBestOfQuestions(Request $request)
{
$conf = [
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'nb_rep' => [$this->app->trans('report:: nombre de reponses'), 0, 0, 0, 0]
];
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
//set Limit
if ($activity->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$activity->setLimit($page, $limit);
} else {
$activity->setLimit(false, false);
}
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$activity->getTopQuestion($conf, true);
return $this->getCSVResponse($activity, 'activity_top_ten_questions');
}
$report = $activity->getTopQuestion($conf, true);
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => false,
'title' => false
]);
}
/**
* Display an overview of connexion among hours of the da
*
* @param Request $request
* @return JsonResponse
*/
public function doReportSiteActiviyPerHours(Request $request)
{
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$activity->getActivityPerHours();
return $this->getCSVResponse($activity, 'activity_per_hours');
}
$report = $activity->getActivityPerHours();
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => true,
'is_doc' => false
]),
'display_nav' => false,
'title' => false
]);
}
/**
* Display an overview of downloaded document grouped by day
*
* @param Request $request
* @return JsonResponse
*/
public function doReportSiteActivityPerDays(Request $request)
{
$conf = [
'ddate' => [$this->app->trans('report:: jour'), 0, 0, 0, 0],
'total' => [$this->app->trans('report:: total des telechargements'), 0, 0, 0, 0],
'preview' => [$this->app->trans('report:: preview'), 0, 0, 0, 0],
'document' => [$this->app->trans('report:: document'), 0, 0, 0, 0]
];
$activity = new \module_report_activity(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
//set Limit
if ($activity->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$activity->setLimit($page, $limit);
} else {
$activity->setLimit(false, false);
}
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$activity->getDownloadByBaseByDay($conf);
return $this->getCSVResponse($activity, 'activity_db_by_base_by_day');
}
$report = $activity->getDownloadByBaseByDay($conf);
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => false,
'title' => false,
]);
}
/**
* Display report about pushed documents
*
* @param Request $request
* @return JsonResponse
*/
public function doReportPushedDocuments(Request $request)
{
$conf = [
'user' => ['', 1, 0, 1, 1],
'getter' => ["Destinataire", 1, 0, 1, 1],
'date' => ['', 1, 0, 1, 1],
'record_id' => ['', 1, 1, 1, 1],
'file' => ['', 1, 0, 1, 1],
'mime' => ['', 1, 0, 1, 1],
];
$activity = new \module_report_push(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$this->doReport($request, $activity, $conf);
return $this->getCSVResponse($activity, 'activity_pushed_documents');
}
$report = $this->doReport($request, $activity, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record'],
]);
}
/**
* Display report about added documents
*
* @param Request $request
* @return JsonResponse
*/
public function doReportAddedDocuments(Request $request)
{
$conf = [
'user' => ['', 1, 0, 1, 1],
'date' => ['', 1, 0, 1, 1],
'record_id' => ['', 1, 1, 1, 1],
'file' => ['', 1, 0, 1, 1],
'mime' => ['', 1, 0, 1, 1],
];
$activity = new \module_report_add(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$this->doReport($request, $activity, $conf);
return $this->getCSVResponse($activity, 'activity_added_documents');
}
$report = $this->doReport($request, $activity, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record'],
]);
}
/**
* Display report about edited documents
*
* @param Request $request
* @return JsonResponse
*/
public function doReportEditedDocuments(Request $request)
{
$conf = [
'user' => ['', 1, 0, 1, 1],
'date' => ['', 1, 0, 1, 1],
'record_id' => ['', 1, 1, 1, 1],
'file' => ['', 1, 0, 1, 1],
'mime' => ['', 1, 0, 1, 1],
];
$activity = new \module_report_edit(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$this->doReport($request, $activity, $conf);
return $this->getCSVResponse($activity, 'activity_edited_documents');
}
$report = $this->doReport($request, $activity, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record'],
]);
}
/**
* Display report about validated documents
*
* @param Request $request
* @return JsonResponse
*/
public function doReportValidatedDocuments(Request $request)
{
$conf = [
'user' => ['', 1, 0, 1, 1],
'getter' => ["Destinataire", 1, 0, 1, 1],
'date' => ['', 1, 0, 1, 1],
'record_id' => ['', 1, 1, 1, 1],
'file' => ['', 1, 0, 1, 1],
'mime' => ['', 1, 0, 1, 1],
];
$activity = new \module_report_validate(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$this->doReport($request, $activity, $conf);
return $this->getCSVResponse($activity, 'activity_validated_documents');
}
$report = $this->doReport($request, $activity, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record'],
]);
}
/**
* Display report about documents sent by mail
*
* @param Request $request
* @return JsonResponse
*/
public function doReportSentDocuments(Request $request)
{
$conf = [
'user' => ['', 1, 0, 1, 1],
'date' => ['', 1, 0, 1, 1],
'record_id' => ['', 1, 1, 1, 1],
'file' => ['', 1, 0, 1, 1],
'mime' => ['', 1, 0, 1, 1],
'comment' => [$this->app->trans('Receiver'), 1, 0, 1, 1],
];
$activity = new \module_report_sent(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$activity->setConfig(false);
if ($request->request->get('printcsv') == 'on') {
$activity->setHasLimit(false);
$activity->setPrettyString(false);
$this->doReport($request, $activity, $conf);
return $this->getCSVResponse($activity, 'activity_send_documents');
}
$report = $this->doReport($request, $activity, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record'],
]);
}
/**
* Set Report configuration according to request parameters
*
* @param Request $request A request instance
* @param \module_report $report A report instance
* @param Array $conf A report column configuration
* @param Boolean $what Whether to group on a particular field or not
* @return Array
*/
private function doReport(Request $request, \module_report $report, $conf, $what = false)
{
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report'])) {
if (isset($conf['user'])) {
unset($conf['user']);
}
if (isset($conf['ip'])) {
unset($conf['ip']);
}
}
//save initial conf
$base_conf = $conf;
//format conf according user preferences
if ('' !== $columnsList = $request->request->get('list_column', '')) {
$new_conf = $conf;
$columns = explode(",", $columnsList);
foreach (array_keys($conf) as $col) {
if (!in_array($col, $columns)) {
unset($new_conf[$col]);
}
}
$conf = $new_conf;
}
//display content of a table column when user click on it
if ($request->request->get('conf') == 'on') {
return $this->app->json(['liste' => $this->render('report/listColumn.html.twig', [
'conf' => $base_conf
]), "title" => $this->app->trans("configuration")]);
}
//set order
if (('' !== $order = $request->request->get('order', '')) && ('' !== $field = $request->request->get('champ', ''))) {
$report->setOrder($field, $order);
}
//work on filters
$mapColumnTitleToSqlField = $report->getTransQueryString();
$currentfilter = [];
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
$currentfilter = @unserialize(urldecode($serializedFilter));
}
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
$field = current(explode(' ', $filterColumn));
$value = $request->request->get('filter_value', '');
if ($request->request->get('liste') == 'on') {
return $this->app->json(['diag' => $this->render('report/colFilter.html.twig', [
'result' => $report->colFilter($field),
'field' => $field
]), "title" => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
}
if ($field === $value) {
$filter->removeFilter($field);
} else {
$filter->addFilter($field, '=', $value);
}
}
//set new request filter if user asking for them
if ($request->request->get('precise') == 1) {
$filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
} elseif ($request->request->get('precise') == 2) {
$filter->addFilter('record_id', '=', $request->request->get('word', ''));
}
//set filters to current report
$report->setFilter($filter->getTabFilter());
$report->setActiveColumn($filter->getActiveColumn());
$report->setPostingFilter($filter->getPostingFilter());
// display a new arraywhere results are group
if ('' !== $groupby = $request->request->get('groupby', '')) {
$report->setConfig(false);
$groupby = current(explode(' ', $groupby));
$reportArray = $report->buildReport(false, $groupby);
if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
$groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
} else {
$groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => true,
'is_plot' => false,
'is_doc' => false,
]),
'display_nav' => false,
'title' => $this->app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField]),
]);
}
//set Limit
if ($report->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$report->setLimit($page, $limit);
} else {
$report->setLimit(false, false);
}
//time to build our report
if (false === $what) {
$reportArray = $report->buildReport($conf);
} else {
$reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
}
return $reportArray;
}
private function getCSVResponse(\module_report $report, $type)
{
// set headers
$headers = [];
foreach (array_keys($report->getDisplay()) as $k) {
$headers[$k] = $k;
}
// set headers as first row
$result = $report->getResult();
array_unshift($result, $headers);
$collection = new CallbackCollection($result, function ($row) use ($report) {
// restrict to displayed fields
return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
});
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
/** @var Exporter $exporter */
$exporter = $this->app['csv.exporter'];
$response = new CSVFileResponse($filename, function () use ($exporter, $collection) {
$exporter->export('php://output', $collection);
});
return $response;
}
}

View File

@@ -1,502 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Report;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
use Goodby\CSV\Export\Standard\Exporter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class InformationController extends Controller
{
/**
* Display information about a user
*
* @param Request $request
* @return JsonResponse
*/
public function doReportInformationUser(Request $request)
{
$conf = [
'config' => [
'photo' => [$this->app->trans('report:: document'), 0, 0, 0, 0],
'record_id' => [$this->app->trans('report:: record id'), 0, 0, 0, 0],
'date' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
'type' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
'titre' => [$this->app->trans('report:: titre'), 0, 0, 0, 0],
'taille' => [$this->app->trans('report:: poids'), 0, 0, 0, 0]
],
'conf' => [
'identifiant' => [$this->app->trans('report:: identifiant'), 0, 0, 0, 0],
'nom' => [$this->app->trans('report:: nom'), 0, 0, 0, 0],
'mail' => [$this->app->trans('report:: email'), 0, 0, 0, 0],
'adresse' => [$this->app->trans('report:: adresse'), 0, 0, 0, 0],
'tel' => [$this->app->trans('report:: telephone'), 0, 0, 0, 0]
],
'config_cnx' => [
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
'appli' => [$this->app->trans('report:: modules'), 0, 0, 0, 0],
],
'config_dl' => [
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
'record_id' => [$this->app->trans('report:: record id'), 0, 1, 0, 0],
'final' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
'coll_id' => [$this->app->trans('report:: collections'), 0, 0, 0, 0],
'comment' => [$this->app->trans('report:: commentaire'), 0, 0, 0, 0],
],
'config_ask' => [
'search' => [$this->app->trans('report:: question'), 0, 0, 0, 0],
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0]
]
];
$report = null;
$html = $html_info = '';
$from = $request->request->get('from', '');
$on = $request->request->get('on', '');
$selectValue = $request->request->get('user', '');
if ('' === $selectValue) {
$this->app->abort(400);
}
if ('' !== $on && $this->getConf()->get(['registry', 'modules', 'anonymous-report']) == true) {
$conf['conf'] = [
$on => [$on, 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0]
];
}
if ($from == 'CNXU' || $from == 'CNX') {
$report = new \module_report_connexion(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_array = $conf['config_cnx'];
$title = $this->app->trans('report:: historique des connexions');
} elseif ($from == 'USR' || $from == 'GEN') {
$report = new \module_report_download(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_array = $conf['config_dl'];
$title = $this->app->trans('report:: historique des telechargements');
} elseif ($from == 'ASK') {
$report = new \module_report_question(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_array = $conf['config_ask'];
$title = $this->app->trans('report:: historique des questions');
}
if ($report) {
$mapColumnTitleToSqlField = $report->getTransQueryString();
$currentfilter = [];
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
$currentfilter = @unserialize(urldecode($serializedFilter));
}
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
$field = current(explode(' ', $filterColumn));
$value = $request->request->get('filter_value', '');
if ($request->request->get('liste') == 'on') {
return $this->app->json([
'diag' => $this->render('report/colFilter.html.twig', [
'result' => $report->colFilter($field),
'field' => $field
]),
'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
}
if ($field === $value) {
$filter->removeFilter($field);
} else {
$filter->addFilter($field, '=', $value);
}
}
if ('' !== $selectValue && '' !== $from) {
$filter->addfilter('usrid', '=', $selectValue);
} elseif ('' !== $on && '' !== $selectValue) {
$filter->addfilter($on, '=', $selectValue);
}
if ($report instanceof \module_report_download) {
$report->setIsInformative(true);
}
$report->setFilter($filter->getTabFilter());
$report->setOrder('ddate', 'DESC');
$report->setConfig(false);
$report->setTitle($title);
$report->setHasLimit(false);
$reportArray = $report->buildReport($conf_array);
if ($request->request->get('printcsv') == 'on') {
$report->setPrettyString(false);
return $this->getCSVResponse($report, 'info_user');
}
$html = $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => $report instanceof \module_report_download,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]);
}
$info = new \module_report_nav(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$info->setPeriode('');
$info->setCsv(false);
$infoArray = $info->buildTabGrpInfo(
null !== $report ? $report->getReq() : '',
null !== $report ? $report->getParams() : [],
$selectValue,
$conf['conf'],
$on
);
if (false == $this->app['conf']->get(['registry', 'modules', 'anonymous-report'])) {
$html_info = $this->render('report/ajax_data_content.html.twig', [
'result' => isset($infoArray['report']) ? $infoArray['report'] : $infoArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]);
$title = ('' === $on && isset($infoArray['result'])) ? $infoArray['result'][0]['identifiant'] : $selectValue;
} else {
$title = $selectValue;
}
return $this->app->json([
'rs' => sprintf('%s%s', $html_info, $html),
'display_nav' => false,
'title' => $title
]);
}
/**
* Display a browser version
*
* @param Request $request
* @return JsonResponse
*/
public function doReportInformationBrowser(Request $request)
{
$conf = [
'version' => [$this->app->trans('report::version'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0]
];
$info = new \module_report_nav(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$info->setCsv(false);
$info->setConfig(false);
if ('' === $browser = $request->request->get('user', '')) {
$this->app->abort(400);
}
$reportArray = $info->buildTabInfoNav($conf, $browser);
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => false,
'title' => $browser
]);
}
/**
* Display information about a document
*
* @param Request $request
* @return JsonResponse
*/
public function doReportInformationDocument(Request $request)
{
$config = [
'photo' => [$this->app->trans('report:: document'), 0, 0, 0, 0],
'record_id' => [$this->app->trans('report:: record id'), 0, 0, 0, 0],
'date' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
'type' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
'titre' => [$this->app->trans('report:: titre'), 0, 0, 0, 0],
'taille' => [$this->app->trans('report:: poids'), 0, 0, 0, 0]
];
$config_dl = [
'ddate' => [$this->app->trans('report:: date'), 0, 0, 0, 0],
'user' => [$this->app->trans('report:: utilisateurs'), 0, 0, 0, 0],
'final' => [$this->app->trans('phrseanet:: sous definition'), 0, 0, 0, 0],
'coll_id' => [$this->app->trans('report:: collections'), 0, 0, 0, 0],
'comment' => [$this->app->trans('report:: commentaire'), 0, 0, 0, 0],
'fonction' => [$this->app->trans('report:: fonction'), 0, 0, 0, 0],
'activite' => [$this->app->trans('report:: activite'), 0, 0, 0, 0],
'pays' => [$this->app->trans('report:: pays'), 0, 0, 0, 0],
'societe' => [$this->app->trans('report:: societe'), 0, 0, 0, 0]
];
//format conf according user preferences
if ('' !== $columnsList = $request->request->get('list_column', '')) {
$new_conf = $config_dl;
$columns = explode(',', $columnsList);
foreach (array_keys($config_dl) as $col) {
if (!in_array($col, $columns)) {
unset($new_conf[$col]);
}
}
$config_dl = $new_conf;
}
try {
$record = new \record_adapter(
$this->app,
$request->request->get('sbasid'),
$request->request->get('rid')
);
} catch (\Exception $e) {
$this->app->abort(404);
}
$what = new \module_report_nav(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$what->setPeriode('');
$what->setCsv(false);
$what->setPrint(false);
/** @var \record_adapter $record */
$reportArray = $what->buildTabUserWhat(
$record->getBaseId(),
$record->getRecordId(),
$config
);
$title = $what->getTitle();
$html = $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]);
$from = $request->request->get('from', '');
if ('TOOL' === $from) {
$what->setTitle('');
return $this->app->json([
'rs' => $html,
'display_nav' => false,
'title' => $title
]);
}
if ('DASH' !== $from && 'PUSHDOC' !== $from) {
$download = new \module_report_download(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$mapColumnTitleToSqlField = $download->getTransQueryString();
$currentfilter = [];
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
$currentfilter = @unserialize(urldecode($serializedFilter));
}
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
$field = current(explode(' ', $filterColumn));
$value = $request->request->get('filter_value', '');
if ($request->request->get('liste') == 'on') {
return $this->app->json([
'diag' => $this->render('report/colFilter.html.twig', [
'result' => $download->colFilter($field),
'field' => $field
]),
'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])
]);
}
if ($field === $value) {
$filter->removeFilter($field);
} else {
$filter->addFilter($field, '=', $value);
}
}
$filter->addfilter('record_id', '=', $record->getRecordId());
$download->setFilter($filter->getTabFilter());
$download->setOrder('ddate', 'DESC');
$download->setTitle($this->app->trans('report:: historique des telechargements'));
$download->setConfig(false);
$reportArray = $download->buildReport($config_dl);
if ($request->request->get('printcsv') == 'on') {
$download->setPrettyString(false);
return $this->getCSVResponse($download, 'info_document');
}
$html .= $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]);
return $this->app->json([
'rs' => $html,
'display_nav' => false,
'title' => $title
]);
}
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report']) == false && $from !== 'DOC' && $from !== 'DASH' && $from !== 'GEN' && $from !== 'PUSHDOC') {
$conf = [
'identifiant' => [$this->app->trans('report:: identifiant'), 0, 0, 0, 0],
'nom' => [$this->app->trans('report:: nom'), 0, 0, 0, 0],
'mail' => [$this->app->trans('report:: email'), 0, 0, 0, 0],
'adresse' => [$this->app->trans('report:: adresse'), 0, 0, 0, 0],
'tel' => [$this->app->trans('report:: telephone'), 0, 0, 0, 0]
];
$info = new \module_report_nav(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$info->setPeriode('');
$info->setConfig(false);
$info->setTitle($this->app->trans('report:: utilisateur'));
$reportArray = $info->buildTabGrpInfo(false, [], $request->request->get('user'), $conf, false);
if ($request->request->get('printcsv') == 'on' && isset($download)) {
return $this->getCSVResponse($this->app, $info, 'info_user');
}
$html .= $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]);
return $this->app->json([
'rs' => $html,
'display_nav' => false,
'title' => $title
]);
}
return $this->app->json([
'rs' => $html,
'display_nav' => false,
'title' => $title
]);
}
private function getCSVResponse(\module_report $report, $type)
{
// set headers
$headers = [];
foreach (array_keys($report->getDisplay()) as $k) {
$headers[$k] = $k;
}
// set headers as first row
$result = $report->getResult();
array_unshift($result, $headers);
$collection = new CallbackCollection($result, function ($row) use ($report) {
// restrict fields to the displayed ones
return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
});
/** @var Exporter $exporter */
$exporter = $this->app['csv.exporter'];
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
$response = new CSVFileResponse($filename, function () use ($exporter, $collection) {
$exporter->export('php://output', $collection);
});
return $response;
}
}

View File

@@ -10,12 +10,8 @@
namespace Alchemy\Phrasea\Controller\Report; namespace Alchemy\Phrasea\Controller\Report;
use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Response\CSVFileResponse;
use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
use Goodby\CSV\Export\Standard\Exporter;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class RootController extends Controller class RootController extends Controller
{ {
@@ -53,22 +49,34 @@ class RootController extends Controller
$granted = []; $granted = [];
foreach ($this->getAclForUser()->get_granted_base([\ACL::CANREPORT]) as $collection) { $acl = $this->getAclForUser();
if (!isset($granted[$collection->get_sbas_id()])) { foreach ($acl->get_granted_base([\ACL::CANREPORT]) as $collection) {
$granted[$collection->get_sbas_id()] = [ $sbas_id = $collection->get_sbas_id();
'id' => $collection->get_sbas_id(), if (!isset($granted[$sbas_id])) {
'name' => $collection->get_databox()->get_viewname(), $granted[$sbas_id] = [
'collections' => [] 'id' => $sbas_id,
'name' => $collection->get_databox()->get_viewname(),
'collections' => [],
'metas' => []
]; ];
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
// skip the fields that can't be reported
if (!$meta->is_report() || ($meta->isBusiness() && !$acl->can_see_business_fields($collection->get_databox()))) {
continue;
}
$granted[$sbas_id]['metas'][] = $meta->get_name();
}
} }
$granted[$collection->get_sbas_id()]['collections'][] = [ $granted[$sbas_id]['collections'][] = [
'id' => $collection->get_coll_id(), 'id' => $collection->get_coll_id(),
'base_id' => $collection->get_base_id(), 'base_id' => $collection->get_base_id(),
'name' => $collection->get_name() 'name' => $collection->get_name(),
]; ];
} }
$conf = $this->getConf(); $conf = $this->getConf();
return $this->render('report/report_layout_child.html.twig', [ return $this->render('report/report_layout_child.html.twig', [
'ajax_dash' => true, 'ajax_dash' => true,
'dashboard' => null, 'dashboard' => null,
@@ -82,594 +90,4 @@ class RootController extends Controller
'ajax_chart' => false 'ajax_chart' => false
]); ]);
} }
/**
* Gets available collections where current user can see report and
* format date
*
* @param Request $request
* @return JsonResponse
*/
public function initReport(Request $request)
{
$popbases = $request->request->get('popbases', []);
if ('' === $dmin = $request->request->get('dmin', '')) {
$dmin = date('Y') . '-' . date('m') . '-01';
}
if ('' === $dmax = $request->request->get('dmax', '')) {
$dmax = date('Y') . '-' . date('m') . '-' . date('d');
}
$dmin = \DateTime::createFromFormat('Y-m-d H:i:s', sprintf('%s 00:00:00', $dmin));
$dmax = \DateTime::createFromFormat('Y-m-d H:i:s', sprintf('%s 23:59:59', $dmax));
//get user's sbas & collections selection from popbases
$selection = [];
$liste = $id_sbas = '';
$i = 0;
foreach (array_fill_keys($popbases, 0) as $key => $val) {
$exp = explode('_', $key);
if ($exp[0] != $id_sbas && $i != 0) {
$selection[$id_sbas]['liste'] = $liste;
$liste = '';
}
$selection[$exp[0]][] = $exp[1];
$liste .= (empty($liste) ? '' : ',') . $exp[1];
$id_sbas = $exp[0];
$i ++;
}
//fill the last entry
$selection[$id_sbas]['liste'] = $liste;
return $this->render('report/ajax_report_content.html.twig', [
'selection' => $selection,
'anonymous' => $this->getConf()->get(['registry', 'modules', 'anonymous-report']),
'ajax' => true,
'dmin' => $dmin->format('Y-m-d H:i:s'),
'dmax' => $dmax->format('Y-m-d H:i:s'),
]);
}
/**
* Display instance connexion report
*
* @param Request $request
* @return JsonResponse
*/
public function doReportConnexions(Request $request)
{
$cnx = new \module_report_connexion(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf = [
'user' => [$this->app->trans('phraseanet::utilisateurs'), 1, 1, 1, 1],
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
'ip' => [$this->app->trans('report:: IP'), 1, 0, 0, 0],
'appli' => [$this->app->trans('report:: modules'), 1, 0, 0, 0],
'fonction' => [$this->app->trans('report::fonction'), 1, 1, 1, 1],
'activite' => [$this->app->trans('report::activite'), 1, 1, 1, 1],
'pays' => [$this->app->trans('report::pays'), 1, 1, 1, 1],
'societe' => [$this->app->trans('report::societe'), 1, 1, 1, 1]
];
if ($request->request->get('printcsv') == 'on') {
$cnx->setHasLimit(false);
$cnx->setPrettyString(false);
$this->doReport($request, $cnx, $conf);
return $this->getCSVResponse($cnx, 'connections');
}
$report = $this->doReport($request, $cnx, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record']
]);
}
/**
* Display instance questions report
*
* @param Request $request
* @return JsonResponse
*/
public function doReportQuestions(Request $request)
{
$questions = new \module_report_question(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf = [
'user' => [$this->app->trans('report:: utilisateur'), 1, 1, 1, 1],
'search' => [$this->app->trans('report:: question'), 1, 0, 1, 1],
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
'fonction' => [$this->app->trans('report:: fonction'), 1, 1, 1, 1],
'activite' => [$this->app->trans('report:: activite'), 1, 1, 1, 1],
'pays' => [$this->app->trans('report:: pays'), 1, 1, 1, 1],
'societe' => [$this->app->trans('report:: societe'), 1, 1, 1, 1]
];
if ($request->request->get('printcsv') == 'on') {
$questions->setHasLimit(false);
$questions->setPrettyString(false);
$this->doReport($request, $questions, $conf);
return $this->getCSVResponse($questions, 'questions');
}
$report = $this->doReport($request, $questions, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record']
]);
}
/**
* Display instance download report
*
* @param Request $request
* @return JsonResponse
*/
public function doReportDownloads(Request $request)
{
$download = new \module_report_download(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_pref = [];
foreach (\module_report::getPreff($this->app, $request->request->get('sbasid')) as $field) {
$conf_pref[strtolower($field)] = [$field, 0, 0, 0, 0];
}
$conf = array_merge([
'user' => [$this->app->trans('report:: utilisateurs'), 1, 1, 1, 1],
'ddate' => [$this->app->trans('report:: date'), 1, 0, 1, 1],
'record_id' => [$this->app->trans('report:: record id'), 1, 1, 1, 1],
'final' => [$this->app->trans('phrseanet:: sous definition'), 1, 0, 1, 1],
'coll_id' => [$this->app->trans('report:: collections'), 1, 0, 1, 1],
'comment' => [$this->app->trans('report:: commentaire'), 1, 0, 0, 0],
'fonction' => [$this->app->trans('report:: fonction'), 1, 1, 1, 1],
'activite' => [$this->app->trans('report:: activite'), 1, 1, 1, 1],
'pays' => [$this->app->trans('report:: pays'), 1, 1, 1, 1],
'societe' => [$this->app->trans('report:: societe'), 1, 1, 1, 1]
], $conf_pref);
if ($request->request->get('printcsv') == 'on') {
$download->setHasLimit(false);
$download->setPrettyString(false);
$this->doReport($request, $download, $conf);
$r = $this->getCSVResponse($download, 'download');
return $r;
}
$report = $this->doReport($request, $download, $conf);
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record']
]);
}
/**
* Display instance document report
*
* @param Request $request
* @return JsonResponse
*/
public function doReportDocuments(Request $request)
{
$document = new \module_report_download(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_pref = [];
foreach (\module_report::getPreff($this->app, $request->request->get('sbasid')) as $field) {
$conf_pref[$field] = array($field, 0, 0, 0, 0);
}
$conf = array_merge([
'telechargement' => [$this->app->trans('report:: telechargements'), 1, 0, 0, 0],
'record_id' => [$this->app->trans('report:: record id'), 1, 1, 1, 0],
'final' => [$this->app->trans('phraseanet:: sous definition'), 1, 0, 1, 1],
'file' => [$this->app->trans('report:: fichier'), 1, 0, 0, 1],
'mime' => [$this->app->trans('report:: type'), 1, 0, 1, 1],
'size' => [$this->app->trans('report:: taille'), 1, 0, 1, 1]
], $conf_pref);
if ($request->request->get('printcsv') == 'on') {
$document->setHasLimit(false);
$document->setPrettyString(false);
$this->doReport($request, $document, $conf, 'record_id');
$r = $this->getCSVResponse($document, 'documents');
return $r;
}
$report = $this->doReport($request, $document, $conf, 'record_id');
if ($report instanceof Response) {
return $report;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => true
]),
'display_nav' => $report['display_nav'], // do we display the prev and next button ?
'next' => $report['next_page'], //Number of the next page
'prev' => $report['previous_page'], //Number of the previoous page
'page' => $report['page'], //The current page
'filter' => ((sizeof($report['filter']) > 0) ? serialize($report['filter']) : ''), //the serialized filters
'col' => $report['active_column'], //all the columns where a filter is applied
'limit' => $report['nb_record']
]);
}
/**
* Display information about client (browser, resolution etc ...)
*
* @param Request $request
* @return JsonResponse
*/
public function doReportClients(Request $request)
{
$nav = new \module_report_nav(
$this->app,
$request->request->get('dmin'),
$request->request->get('dmax'),
$request->request->get('sbasid'),
$request->request->get('collection')
);
$conf_nav = [
'nav' => [$this->app->trans('report:: navigateur'), 0, 1, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
];
$conf_combo = [
'combo' => [$this->app->trans('report:: navigateurs et plateforme'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
];
$conf_os = [
'os' => [$this->app->trans('report:: plateforme'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
];
$conf_res = [
'res' => [$this->app->trans('report:: resolution'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
];
$conf_mod = [
'appli' => [$this->app->trans('report:: module'), 0, 0, 0, 0],
'nb' => [$this->app->trans('report:: nombre'), 0, 0, 0, 0],
'pourcent' => [$this->app->trans('report:: pourcentage'), 0, 0, 0, 0]
];
$report = [
'nav' => $nav->buildTabNav($conf_nav),
'os' => $nav->buildTabOs($conf_os),
'res' => $nav->buildTabRes($conf_res),
'mod' => $nav->buildTabModule($conf_mod),
'combo' => $nav->buildTabCombo($conf_combo)
];
if ($request->request->get('printcsv') == 'on') {
$result = [];
$result[] = array_keys($conf_nav);
foreach ($report['nav']['result'] as $row) {
$result[] = array_values($row);
};
$result[] = array_keys($conf_os);
foreach ($report['os']['result'] as $row) {
$result[] = array_values($row);
};
$result[] = array_keys($conf_res);
foreach ($report['res']['result'] as $row) {
$result[] = array_values($row);
};
$result[] = array_keys($conf_mod);
foreach ($report['mod']['result'] as $row) {
$result[] = array_values($row);
};
$result[] = array_keys($conf_combo);
foreach ($report['combo']['result'] as $row) {
$result[] = array_values($row);
};
/** @var Exporter $exporter */
$exporter = $this->app['csv.exporter'];
$filename = sprintf('report_export_info_%s.csv', date('Ymd'));
$response = new CSVFileResponse($filename, function () use ($exporter, $result) {
$exporter->export('php://output', $result);
});
return $response;
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($report['report']) ? $report['report'] : $report,
'is_infouser' => false,
'is_nav' => true,
'is_groupby' => false,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => false,
'title' => false
]);
}
/**
* Set Report configuration according to request parameters
*
* @param Request $request A request instance
* @param \module_report $report A report instance
* @param Array $conf A report column configuration
* @param Boolean $what Whether to group on a particular field or not
* @return Array
*/
private function doReport(Request $request, \module_report $report, $conf, $what = false)
{
if ($this->getConf()->get(['registry', 'modules', 'anonymous-report']) == true) {
if (isset($conf['user'])) {
unset($conf['user']);
}
if (isset($conf['ip'])) {
unset($conf['ip']);
}
}
//save initial conf
$base_conf = $conf;
//format conf according user preferences
if ('' !== $columnsList = $request->request->get('list_column', '')) {
$new_conf = $conf;
$columns = explode(',', $columnsList);
foreach (array_keys($conf) as $col) {
if (!in_array($col, $columns)) {
unset($new_conf[$col]);
}
}
$conf = $new_conf;
}
//display content of a table column when user click on it
if ($request->request->get('conf') == 'on') {
return $this->app->json(['liste' => $this->render('report/listColumn.html.twig', [
'conf' => $base_conf
]), 'title' => $this->app->trans('configuration')]);
}
//set order
if (('' !== $order = $request->request->get('order', '')) && ('' !== $field = $request->request->get('champ', ''))) {
$report->setOrder($field, $order);
}
//work on filters
$mapColumnTitleToSqlField = $report->getTransQueryString();
$currentfilter = [];
if ('' !== $serializedFilter = $request->request->get('liste_filter', '')) {
$currentfilter = @unserialize(urldecode($serializedFilter));
}
$filter = new \module_report_filter($this->app, $currentfilter, $mapColumnTitleToSqlField);
if ('' !== $filterColumn = $request->request->get('filter_column', '')) {
$field = current(explode(' ', $filterColumn));
$value = $request->request->get('filter_value', '');
if ($request->request->get('liste') == 'on') {
return $this->app->json(['diag' => $this->render('report/colFilter.html.twig', [
'result' => $report->colFilter($field),
'field' => $field
]), 'title' => $this->app->trans('filtrer les resultats sur la colonne %colonne%', ['%colonne%' => $field])]);
}
if ($field === $value) {
$filter->removeFilter($field);
} else {
$filter->addFilter($field, '=', $value);
}
}
//set new request filter if user asking for them
if ($request->request->get('precise') == 1) {
$filter->addFilter('xml', 'LIKE', $request->request->get('word', ''));
} elseif ($request->request->get('precise') == 2) {
$filter->addFilter('record_id', '=', $request->request->get('word', ''));
}
//set filters to current report
$report->setFilter($filter->getTabFilter());
$report->setActiveColumn($filter->getActiveColumn());
$report->setPostingFilter($filter->getPostingFilter());
// display a new arraywhere results are group
if ('' !== $groupby = $request->request->get('groupby', '')) {
$report->setConfig(false);
$groupby = current(explode(' ', $groupby));
$reportArray = $report->buildReport(false, $groupby);
if (count($reportArray['allChamps']) > 0 && count($reportArray['display']) > 0) {
$groupField = isset($reportArray['display'][$reportArray['allChamps'][0]]['title']) ? $reportArray['display'][$reportArray['allChamps'][0]]['title'] : '';
} else {
$groupField = isset($conf[strtolower($groupby)]['title']) ? $conf[strtolower($groupby)]['title'] : '';
}
return $this->app->json([
'rs' => $this->render('report/ajax_data_content.html.twig', [
'result' => isset($reportArray['report']) ? $reportArray['report'] : $reportArray,
'is_infouser' => false,
'is_nav' => false,
'is_groupby' => true,
'is_plot' => false,
'is_doc' => false
]),
'display_nav' => false,
'title' => $this->app->trans('Groupement des resultats sur le champ %name%', ['%name%' => $groupField])
]);
}
//set Limit
if ($report->getEnableLimit()
&& ('' !== $page = $request->request->get('page', ''))
&& ('' !== $limit = $request->request->get('limit', ''))) {
$report->setLimit($page, $limit);
} else {
$report->setLimit(false, false);
}
//time to build our report
if (false === $what) {
$reportArray = $report->buildReport($conf);
} else {
$reportArray = $report->buildReport($conf, $what, $request->request->get('tbl', false));
}
return $reportArray;
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
private function getCSVResponse(\module_report $report, $type)
{
// set headers
$headers = [];
foreach (array_keys($report->getDisplay()) as $k) {
$headers[$k] = $k;
}
// set headers as first row
$result = $report->getResult();
array_unshift($result, $headers);
$collection = new CallbackCollection($result, function ($row) use ($headers) {
// restrict fields to the displayed ones
// return array_map("strip_tags", array_intersect_key($row, $report->getDisplay()));
$ret = array();
foreach($headers as $f) {
$ret[$f] = array_key_exists($f, $row) ? strip_tags($row[$f]) : '';
}
return $ret;
});
$filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
/** @var Exporter $exporter */
$exporter = $this->app['csv.exporter'];
$cb = function () use ($exporter, $collection) {
$exporter->export('php://output', $collection);
};
$response = new CSVFileResponse($filename, $cb);
return $response;
}
} }

View File

@@ -17,20 +17,27 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
use Alchemy\Phrasea\Application\Helper\NotifierAware; use Alchemy\Phrasea\Application\Helper\NotifierAware;
use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder; use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder;
use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\ControllerProvider\Root\Login;
use Alchemy\Phrasea\Core\Configuration\RegistrationManager; use Alchemy\Phrasea\Core\Configuration\RegistrationManager;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm; use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm;
use Alchemy\Phrasea\Model\Entities\ApiApplication; use Alchemy\Phrasea\Model\Entities\ApiApplication;
use Alchemy\Phrasea\Model\Entities\FtpCredential; use Alchemy\Phrasea\Model\Entities\FtpCredential;
use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Session;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Manipulator\ApiAccountManipulator; use Alchemy\Phrasea\Model\Manipulator\ApiAccountManipulator;
use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator;
use Alchemy\Phrasea\Model\Manipulator\BasketManipulator;
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator; use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
use Alchemy\Phrasea\Model\Manipulator\UserManipulator; use Alchemy\Phrasea\Model\Manipulator\UserManipulator;
use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository; use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository;
use Alchemy\Phrasea\Model\Repositories\ApiApplicationRepository; use Alchemy\Phrasea\Model\Repositories\ApiApplicationRepository;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\FeedPublisherRepository;
use Alchemy\Phrasea\Model\Repositories\TokenRepository; use Alchemy\Phrasea\Model\Repositories\TokenRepository;
use Alchemy\Phrasea\Model\Repositories\ValidationSessionRepository;
use Alchemy\Phrasea\Notification\Mail\MailRequestAccountDelete;
use Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate; use Alchemy\Phrasea\Notification\Mail\MailRequestEmailUpdate;
use Alchemy\Phrasea\Notification\Mail\MailSuccessAccountDelete;
use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Receiver;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -201,6 +208,7 @@ class AccountController extends Controller
*/ */
public function accountAccess() public function accountAccess()
{ {
//var_dump($this->getRegistrationManager()->getRegistrationSummary($this->getAuthenticatedUser()));die;
return $this->render('account/access.html.twig', [ return $this->render('account/access.html.twig', [
'inscriptions' => $this->getRegistrationManager()->getRegistrationSummary($this->getAuthenticatedUser()) 'inscriptions' => $this->getRegistrationManager()->getRegistrationSummary($this->getAuthenticatedUser())
]); ]);
@@ -298,13 +306,102 @@ class AccountController extends Controller
$manager = $this->getEventManager(); $manager = $this->getEventManager();
$user = $this->getAuthenticatedUser(); $user = $this->getAuthenticatedUser();
$repo_baskets = $this->getBasketRepository();
$baskets = $repo_baskets->findActiveValidationAndBasketByUser($user);
$apiAccounts = $this->getApiAccountRepository()->findByUser($user);
$ownedFeeds = $this->getFeedPublisherRepository()->findBy(['user' => $user, 'owner' => true]);
$initiatedValidations = $this->getValidationSessionRepository()->findby(['initiator' => $user, ]);
return $this->render('account/account.html.twig', [ return $this->render('account/account.html.twig', [
'user' => $user, 'user' => $user,
'evt_mngr' => $manager, 'evt_mngr' => $manager,
'notifications' => $manager->list_notifications_available($user), 'notifications' => $manager->list_notifications_available($user),
'baskets' => $baskets,
'api_accounts' => $apiAccounts,
'owned_feeds' => $ownedFeeds,
'initiated_validations' => $initiatedValidations,
]); ]);
} }
/**
* @param Request $request
* @return RedirectResponse
*/
public function processDeleteAccount(Request $request)
{
$user = $this->getAuthenticatedUser();
if($this->app['conf']->get(['user_account', 'deleting_policies', 'email_confirmation'])) {
// send email confirmation
try {
$receiver = Receiver::fromUser($user);
} catch (InvalidArgumentException $e) {
$this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
return $this->app->redirectPath('account');
}
$token = $this->getTokenManipulator()->createAccountDeleteToken($user, $user->getEmail());
$url = $this->app->url('account_confirm_delete', ['token' => $token->getValue()]);
$mail = MailRequestAccountDelete::create($this->app, $receiver);
$mail->setUserOwner($user);
$mail->setButtonUrl($url);
$mail->setExpiration($token->getExpiration());
$this->deliver($mail);
$this->app->addFlash('info', $this->app->trans('phraseanet::account: A confirmation e-mail has been sent. Please follow the instructions contained to continue account deletion'));
return $this->app->redirectPath('account');
} else {
$this->doDeleteAccount($user);
$response = $this->app->redirectPath('homepage', [
'redirect' => $request->query->get("redirect")
]);
$response->headers->clearCookie('persistent');
$response->headers->clearCookie('last_act');
return $response;
}
}
public function confirmDeleteAccount(Request $request)
{
if (($tokenValue = $request->query->get('token')) !== null ) {
if (null === $token = $this->getTokenRepository()->findValidToken($tokenValue)) {
$this->app->addFlash('error', $this->app->trans('Token not found'));
return $this->app->redirectPath('account');
}
$user = $token->getUser();
// delete account and datas
$this->doDeleteAccount($user);
$this->getTokenManipulator()->delete($token);
}
$response = $this->app->redirectPath('homepage', [
'redirect' => $request->query->get("redirect")
]);
$response->headers->clearCookie('persistent');
$response->headers->clearCookie('last_act');
return $response;
}
/** /**
* Update account information * Update account information
* *
@@ -405,6 +502,57 @@ class AccountController extends Controller
return $this->app->redirectPath('account'); return $this->app->redirectPath('account');
} }
/**
* @param User $user
*/
private function doDeleteAccount(User $user)
{
// basket
$repo_baskets = $this->getBasketRepository();
$baskets = $repo_baskets->findActiveByUser($user);
$this->getBasketManipulator()->removeBaskets($baskets);
// application
$applications = $this->getApiApplicationRepository()->findByUser($user);
$this->getApiApplicationManipulator()->deleteApiApplications($applications);
// revoke access and delete phraseanet user account
$list = array_keys($this->app['repo.collections-registry']->getBaseIdMap());
try {
$this->app->getAclForUser($user)->revoke_access_from_bases($list);
}
catch (\Exception $e) {
// one or more access could not be revoked ? the user will not be phantom
$this->app->addFlash('error', $this->app->trans('phraseanet::error: failed to revoke some user access'));
}
if ($this->app->getAclForUser($user)->is_phantom()) {
// send confirmation email: the account has been deleted
try {
$receiver = Receiver::fromUser($user);
$mail = MailSuccessAccountDelete::create($this->app, $receiver);
}
catch (InvalidArgumentException $e) {
$this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
$mail = null;
}
$this->app['manipulator.user']->delete($user);
if($mail) {
$this->deliver($mail);
}
$this->getAuthenticator()->closeAccount();
$this->app->addFlash('info', $this->app->trans('phraseanet::account The account has been deleted'));
}
}
/** /**
* @return PasswordEncoder * @return PasswordEncoder
*/ */
@@ -500,4 +648,44 @@ class AccountController extends Controller
{ {
return $this->app['events-manager']; return $this->app['events-manager'];
} }
/**
* @return BasketManipulator
*/
private function getBasketManipulator()
{
return $this->app['manipulator.basket'];
}
/**
* @return BasketRepository
*/
private function getBasketRepository()
{
return $this->app['repo.baskets'];
}
/**
* @return ApiApplicationManipulator
*/
private function getApiApplicationManipulator()
{
return $this->app['manipulator.api-application'];
}
/**
* @return FeedPublisherRepository
*/
private function getFeedPublisherRepository()
{
return $this->app['repo.feed-publishers'];
}
/**
* @return ValidationSessionRepository
*/
private function getValidationSessionRepository()
{
return $this->app['repo.validation-session'];
}
} }

View File

@@ -265,7 +265,7 @@ class LoginController extends Controller
return $this->render('login/register-classic.html.twig', array_merge( return $this->render('login/register-classic.html.twig', array_merge(
$this->getDefaultTemplateVariables($request), $this->getDefaultTemplateVariables($request),
[ [
'geonames_server_uri' => str_replace(sprintf('%s:', parse_url($url, PHP_URL_SCHEME)), '', $url), 'geonames_server_uri' => $url,
'form' => $form->createView() 'form' => $form->createView()
])); ]));
} }

View File

@@ -94,10 +94,9 @@ class SessionController extends Controller
} }
/** /**
* Check session state * @param Request $request
*
* @param Request $request
* @return JsonResponse * @return JsonResponse
* @throws \Exception in case "new \DateTime()" fails ?
*/ */
public function updateSession(Request $request) public function updateSession(Request $request)
{ {
@@ -120,7 +119,8 @@ class SessionController extends Controller
return $this->app->json($ret); return $this->app->json($ret);
} }
} else { }
else {
$ret['status'] = 'disconnected'; $ret['status'] = 'disconnected';
return $this->app->json($ret); return $this->app->json($ret);
@@ -128,7 +128,8 @@ class SessionController extends Controller
try { try {
$this->getApplicationBox()->get_connection(); $this->getApplicationBox()->get_connection();
} catch (\Exception $e) { }
catch (\Exception $e) {
return $this->app->json($ret); return $this->app->json($ret);
} }
@@ -148,8 +149,9 @@ class SessionController extends Controller
$module->setModuleId($moduleId); $module->setModuleId($moduleId);
$module->setSession($session); $module->setSession($session);
$manager->persist($module); $manager->persist($module);
} else { }
$manager->persist($session->getModuleById($moduleId)->setUpdated(new \DateTime())); else {
$manager->persist($session->getModuleById($moduleId)->setUpdated($now));
} }
$manager->persist($session); $manager->persist($session);
@@ -231,7 +233,10 @@ class SessionController extends Controller
*/ */
private function getBasketRepository() private function getBasketRepository()
{ {
return $this->getEntityManager()->getRepository('Phraseanet:Basket'); /** @var BasketRepository $ret */
$ret = $this->getEntityManager()->getRepository('Phraseanet:Basket');
return $ret;
} }
/** /**

View File

@@ -806,7 +806,7 @@ class ThesaurusController extends Controller
if (!$t) { if (!$t) {
$t = "..."; $t = "...";
} }
$fullBranch = " / " . $t . $fullBranch; $fullBranch = " / " . htmlspecialchars($t) . $fullBranch;
} }
} }
$nodes = $xpathstruct->query("/record/description/*"); $nodes = $xpathstruct->query("/record/description/*");
@@ -1159,7 +1159,7 @@ class ThesaurusController extends Controller
'1', '1',
null null
); );
$fullpath = $dom->getElementsByTagName("fullpath_html")->item(0)->firstChild->nodeValue; $fullpathHtml = $dom->getElementsByTagName("fullpath_html")->item(0)->firstChild->nodeValue;
$hits = $dom->getElementsByTagName("allhits")->item(0)->firstChild->nodeValue; $hits = $dom->getElementsByTagName("allhits")->item(0)->firstChild->nodeValue;
$languages = $synonyms = []; $languages = $synonyms = [];
@@ -1180,6 +1180,16 @@ class ThesaurusController extends Controller
$languages[$lng_code[0]] = $language; $languages[$lng_code[0]] = $language;
} }
// Escape path between span tag in fullpath_html
preg_match_all("'(<[^><]*>)(.*?)(<[^><]*>)'", $fullpathHtml, $matches, PREG_SET_ORDER);
$safeFullpath = '';
foreach($matches as $match) {
unset($match[0]); // full match result not used
$match[2] = htmlspecialchars($match[2]);
$safeFullpath .= implode('', $match);
}
return $this->render('thesaurus/properties.html.twig', [ return $this->render('thesaurus/properties.html.twig', [
'typ' => $request->get('typ'), 'typ' => $request->get('typ'),
'bid' => $request->get('bid'), 'bid' => $request->get('bid'),
@@ -1187,7 +1197,7 @@ class ThesaurusController extends Controller
'id' => $request->get('id'), 'id' => $request->get('id'),
'dlg' => $request->get('dlg'), 'dlg' => $request->get('dlg'),
'languages' => $languages, 'languages' => $languages,
'fullpath' => $fullpath, 'fullpath' => $safeFullpath,
'hits' => $hits, 'hits' => $hits,
'synonyms' => $synonyms, 'synonyms' => $synonyms,
]); ]);

View File

@@ -1426,12 +1426,7 @@ class ThesaurusXmlHttpController extends Controller
public function searchTermJson(Request $request) public function searchTermJson(Request $request)
{ {
if (null === $lng = $request->get('lng')) { $lng = $request->get('lng');
$data = explode('_', $this->app['locale']);
if (count($data) > 0) {
$lng = $data[0];
}
}
$html = ''; $html = '';
$sbid = (int) $request->get('sbid'); $sbid = (int) $request->get('sbid');
@@ -1485,7 +1480,10 @@ class ThesaurusXmlHttpController extends Controller
$q2 .= ' and starts-with(@k, \'' . \thesaurus::xquery_escape($unicode->remove_indexer_chars($t[1])) . '\')'; $q2 .= ' and starts-with(@k, \'' . \thesaurus::xquery_escape($unicode->remove_indexer_chars($t[1])) . '\')';
} }
$q2 .= ' and @lng=\'' . \thesaurus::xquery_escape($lng) . '\''; if($lng != null){
$q2 .= ' and @lng=\'' . \thesaurus::xquery_escape($lng) . '\'';
}
$q .= ('//sy[' . $q2 . ']'); $q .= ('//sy[' . $q2 . ']');
$nodes = $xpath->query($q); $nodes = $xpath->query($q);

View File

@@ -77,6 +77,7 @@ class ControllerProviderServiceProvider implements ServiceProviderInterface
Prod\Push::class => [], Prod\Push::class => [],
Prod\Query::class => [], Prod\Query::class => [],
Prod\Record::class => [], Prod\Record::class => [],
\Alchemy\Phrasea\Report\ControllerProvider\ProdReportControllerProvider::class => [],
Prod\Root::class => [], Prod\Root::class => [],
Prod\Share::class => [], Prod\Share::class => [],
Prod\Story::class => [], Prod\Story::class => [],
@@ -87,8 +88,6 @@ class ControllerProviderServiceProvider implements ServiceProviderInterface
Prod\Upload::class => [], Prod\Upload::class => [],
Prod\UsrLists::class => [], Prod\UsrLists::class => [],
Prod\WorkZone::class => [], Prod\WorkZone::class => [],
Report\Activity::class => [],
Report\Information::class => [],
Report\Root::class => [], Report\Root::class => [],
Root\Account::class => [], Root\Account::class => [],
Root\Developers::class => [], Root\Developers::class => [],

View File

@@ -82,6 +82,11 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface
->assert('file_id', '\d+') ->assert('file_id', '\d+')
->bind('lazaret_thumbnail'); ->bind('lazaret_thumbnail');
$controllers->get('/{databox_id}/{record_id}/status', 'controller.prod.lazaret:getDestinationStatus')
->assert('databox_id', '\d+')
->assert('record_id', '\d+')
->bind('lazaret_destination_status');
return $controllers; return $controllers;
} }
} }

View File

@@ -25,7 +25,9 @@ class Property implements ControllerProviderInterface, ServiceProviderInterface
public function register(Application $app) public function register(Application $app)
{ {
$app['controller.prod.property'] = $app->share(function (PhraseaApplication $app) { $app['controller.prod.property'] = $app->share(function (PhraseaApplication $app) {
return (new PropertyController($app)); return (new PropertyController($app))
->setDataboxLoggerLocator($app['phraseanet.logger'])
;
}); });
} }

View File

@@ -66,6 +66,9 @@ class Upload implements ControllerProviderInterface, ServiceProviderInterface
$controllers->get('/html5-version/', 'controller.prod.upload:getHtml5UploadForm') $controllers->get('/html5-version/', 'controller.prod.upload:getHtml5UploadForm')
->bind('upload_html5_form'); ->bind('upload_html5_form');
$controllers->get('/head/', 'controller.prod.upload:getHead')
->bind('upload_head');
$controllers->post('/', 'controller.prod.upload:upload') $controllers->post('/', 'controller.prod.upload:upload')
->bind('upload'); ->bind('upload');

View File

@@ -1,81 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\ControllerProvider\Report;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Report\ActivityController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
class Activity implements ControllerProviderInterface, ServiceProviderInterface
{
use ControllerProviderTrait;
public function register(Application $app)
{
$app['controller.report.activity'] = $app->share(function (PhraseaApplication $app) {
return new ActivityController($app);
});
}
public function boot(Application $app)
{
// no-op
}
public function connect(Application $app)
{
$controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($firewall) {
$firewall->requireAccessToModule('report');
});
$controllers->post('/users/connexions', 'controller.report.activity:doReportConnexionsByUsers')
->bind('report_activity_users_connexions');
$controllers->post('/users/downloads', 'controller.report.activity:doReportDownloadsByUsers')
->bind('report_activity_users_downloads');;
$controllers->post('/questions/best-of', 'controller.report.activity:doReportBestOfQuestions')
->bind('report_activity_questions_bestof');
$controllers->post('/questions/no-best-of', 'controller.report.activity:doReportNoBestOfQuestions')
->bind('report_activity_questions_nobestof');
$controllers->post('/instance/hours', 'controller.report.activity:doReportSiteActiviyPerHours')
->bind('report_activity_instance_hours');
$controllers->post('/instance/days', 'controller.report.activity:doReportSiteActivityPerDays')
->bind('report_activity_instance_days');
$controllers->post('/documents/pushed', 'controller.report.activity:doReportPushedDocuments')
->bind('report_activity_documents_pushed');
$controllers->post('/documents/added', 'controller.report.activity:doReportAddedDocuments')
->bind('report_activity_documents_added');
$controllers->post('/documents/edited', 'controller.report.activity:doReportEditedDocuments')
->bind('report_activity_documents_edited');
$controllers->post('/documents/validated', 'controller.report.activity:doReportValidatedDocuments')
->bind('report_activity_documents_validated');
$controllers->post('/documents/sent', 'controller.report.activity:doReportSentDocuments')
->bind('report_activity_documents_sent');
return $controllers;
}
}

View File

@@ -1,57 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\ControllerProvider\Report;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Report\InformationController;
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ServiceProviderInterface;
class Information implements ControllerProviderInterface, ServiceProviderInterface
{
use ControllerProviderTrait;
public function register(Application $app)
{
$app['controller.report.information'] = $app->share(function (PhraseaApplication $app) {
return new InformationController($app);
});
}
public function boot(Application $app)
{
// no-op
}
public function connect(Application $app)
{
$controllers = $this->createAuthenticatedCollection($app);
$firewall = $this->getFirewall($app);
$controllers->before(function () use ($firewall) {
$firewall->requireAccessToModule('report');
});
$controllers->post('/user', 'controller.report.information:doReportInformationUser')
->bind('report_infomations_user');
$controllers->post('/browser', 'controller.report.information:doReportInformationBrowser')
->bind('report_infomations_browser');
$controllers->post('/document', 'controller.report.information:doReportInformationDocument')
->bind('report_infomations_document');
return $controllers;
}
}

View File

@@ -52,6 +52,14 @@ class Account implements ControllerProviderInterface, ServiceProviderInterface
$controllers->get('/', 'account.controller:displayAccount') $controllers->get('/', 'account.controller:displayAccount')
->bind('account'); ->bind('account');
// allow to delete phraseanet account
$controllers->get('/delete/process', 'account.controller:processDeleteAccount')
->bind('account_process_delete');
$controllers->get('/delete/confirm', 'account.controller:confirmDeleteAccount')
->bind('account_confirm_delete');
// Updates current logged in user account // Updates current logged in user account
$controllers->post('/', 'account.controller:updateAccount') $controllers->post('/', 'account.controller:updateAccount')
->bind('submit_update_account'); ->bind('submit_update_account');

View File

@@ -41,7 +41,8 @@ class DisplaySettingService
'css' => '000000', 'css' => '000000',
'start_page_query' => '', 'start_page_query' => '',
'order_collection_by' => self::ORDER_BY_ADMIN, 'order_collection_by' => self::ORDER_BY_ADMIN,
'start_page' => 'QUERY', 'start_page' => 'LAST_QUERY',
'last_jsonquery' => '',
'rollover_thumbnail' => 'caption', 'rollover_thumbnail' => 'caption',
'technical_display' => '1', 'technical_display' => '1',
'doctype_display' => '1', 'doctype_display' => '1',

View File

@@ -176,7 +176,7 @@ class RegistrationManager
} }
if ($isTimeLimited && $isOutDated && $isPending) { if ($isTimeLimited && $isOutDated && $isPending) {
$userRegistration['type'] = 'out-time'; $userRegistration['type'] = 'out-dated';
return $userRegistration; return $userRegistration;
} }

View File

@@ -146,7 +146,7 @@ class RegistryFormManipulator
], ],
'webservices' => [ 'webservices' => [
'google-charts-enabled' => true, 'google-charts-enabled' => true,
'geonames-server' => 'http://geonames.alchemyasp.com/', 'geonames-server' => 'https://geonames.alchemyasp.com/',
'captchas-enabled' => false, 'captchas-enabled' => false,
'recaptcha-public-key' => '', 'recaptcha-public-key' => '',
'recaptcha-private-key' => '', 'recaptcha-private-key' => '',

View File

@@ -66,6 +66,8 @@ class DatabaseMaintenanceService
public function upgradeDatabase(\base $base, $applyPatches) public function upgradeDatabase(\base $base, $applyPatches)
{ {
$this->reconnect();
$recommends = []; $recommends = [];
$allTables = []; $allTables = [];
@@ -126,6 +128,8 @@ class DatabaseMaintenanceService
*/ */
public function alterTableEngine($tableName, $engine, array & $recommends) public function alterTableEngine($tableName, $engine, array & $recommends)
{ {
$this->reconnect();
$sql = 'ALTER TABLE `' . $tableName . '` ENGINE = ' . $engine; $sql = 'ALTER TABLE `' . $tableName . '` ENGINE = ' . $engine;
try { try {
@@ -145,6 +149,8 @@ class DatabaseMaintenanceService
*/ */
public function createTable(\SimpleXMLElement $table) public function createTable(\SimpleXMLElement $table)
{ {
$this->reconnect();
$field_stmt = $defaults_stmt = []; $field_stmt = $defaults_stmt = [];
$create_stmt = "CREATE TABLE IF NOT EXISTS `" . $table['name'] . "` ("; $create_stmt = "CREATE TABLE IF NOT EXISTS `" . $table['name'] . "` (";
@@ -270,6 +276,8 @@ class DatabaseMaintenanceService
public function upgradeTable(\SimpleXMLElement $table) public function upgradeTable(\SimpleXMLElement $table)
{ {
$this->reconnect();
$correct_table = ['fields' => [], 'indexes' => [], 'collation' => []]; $correct_table = ['fields' => [], 'indexes' => [], 'collation' => []];
$alter = $alter_pre = $return = []; $alter = $alter_pre = $return = [];
@@ -476,6 +484,8 @@ class DatabaseMaintenanceService
} }
foreach ($alter_pre as $a) { foreach ($alter_pre as $a) {
$this->reconnect();
try { try {
$this->connection->exec($a); $this->connection->exec($a);
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -488,6 +498,8 @@ class DatabaseMaintenanceService
} }
foreach ($alter as $a) { foreach ($alter as $a) {
$this->reconnect();
try { try {
$this->connection->exec($a); $this->connection->exec($a);
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -561,6 +573,7 @@ class DatabaseMaintenanceService
$this->app['swiftmailer.transport'] = null; $this->app['swiftmailer.transport'] = null;
foreach ($list_patches as $patch) { foreach ($list_patches as $patch) {
// Gets doctrine migrations required for current patch // Gets doctrine migrations required for current patch
foreach ($patch->getDoctrineMigrations() as $doctrineVersion) { foreach ($patch->getDoctrineMigrations() as $doctrineVersion) {
/** @var \Doctrine\DBAL\Migrations\Version $version */ /** @var \Doctrine\DBAL\Migrations\Version $version */
@@ -579,6 +592,8 @@ class DatabaseMaintenanceService
// Execute migration if not marked as migrated and not already applied by an older patch // Execute migration if not marked as migrated and not already applied by an older patch
if (!$migration->isAlreadyApplied()) { if (!$migration->isAlreadyApplied()) {
$this->reconnect();
$version->execute('up'); $version->execute('up');
continue; continue;
} }
@@ -586,10 +601,14 @@ class DatabaseMaintenanceService
// Or mark it as migrated // Or mark it as migrated
$version->markMigrated(); $version->markMigrated();
} else { } else {
$this->reconnect();
$version->execute('up'); $version->execute('up');
} }
} }
$this->reconnect();
if (false === $patch->apply($base, $this->app)) { if (false === $patch->apply($base, $this->app)) {
$success = false; $success = false;
} }
@@ -597,4 +616,12 @@ class DatabaseMaintenanceService
return $success; return $success;
} }
private function reconnect()
{
if($this->connection->ping() === false) {
$this->connection->close();
$this->connection->connect();
}
}
} }

View File

@@ -66,6 +66,9 @@ class RepositoriesServiceProvider implements ServiceProviderInterface
$app['repo.validation-participants'] = $app->share(function (PhraseaApplication $app) { $app['repo.validation-participants'] = $app->share(function (PhraseaApplication $app) {
return $app['orm.em']->getRepository('Phraseanet:ValidationParticipant'); return $app['orm.em']->getRepository('Phraseanet:ValidationParticipant');
}); });
$app['repo.validation-session'] = $app->share(function (PhraseaApplication $app) {
return $app['orm.em']->getRepository('Phraseanet:ValidationSession');
});
$app['repo.story-wz'] = $app->share(function (PhraseaApplication $app) { $app['repo.story-wz'] = $app->share(function (PhraseaApplication $app) {
return $app['orm.em']->getRepository('Phraseanet:StoryWZ'); return $app['orm.em']->getRepository('Phraseanet:StoryWZ');
}); });

View File

@@ -16,7 +16,7 @@ class Version
/** /**
* @var string * @var string
*/ */
private $number = '4.1.0-alpha.12'; private $number = '4.1.0-alpha.18a';
/** /**
* @var string * @var string

View File

@@ -36,6 +36,9 @@ final class DbalDataboxFieldRepository implements DataboxFieldRepository
'label_fr', 'label_fr',
'label_de', 'label_de',
'label_nl', 'label_nl',
'generate_cterms',
'gui_editable',
'gui_visible',
]; ];
/** @var DataboxFieldFactory */ /** @var DataboxFieldFactory */

View File

@@ -201,6 +201,8 @@ class FilesystemService
return 'ogg'; return 'ogg';
case 'libmp3lame': case 'libmp3lame':
return 'mp3'; return 'mp3';
case 'pcm_s16le':
return 'wav';
} }
return null; return null;

View File

@@ -11,28 +11,29 @@
namespace Alchemy\Phrasea\Helper; namespace Alchemy\Phrasea\Helper;
use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Model\Entities\Basket as BasketEntity; use Alchemy\Phrasea\Model\Entities\Basket as BasketEntity;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
use Doctrine\Common\Collections\ArrayCollection;
class WorkZone extends Helper class WorkZone extends Helper
{ {
const BASKETS = 'baskets'; const BASKETS = 'baskets';
const STORIES = 'stories'; const STORIES = 'stories';
const VALIDATIONS = 'validations'; const VALIDATIONS = 'validations';
/** /**
*
* Returns an ArrayCollection containing three keys : * Returns an ArrayCollection containing three keys :
* - self::BASKETS : an ArrayCollection of the actives baskets * - self::BASKETS : an ArrayCollection of the actives baskets (Non Archived)
* (Non Archived)
* - self::STORIES : an ArrayCollection of working stories * - self::STORIES : an ArrayCollection of working stories
* - self::VALIDATIONS : the validation people are waiting from me * - self::VALIDATIONS : the validation people are waiting from me
* *
* @return \Doctrine\Common\Collections\ArrayCollection * @param null|string $sort "date"|"name"
* @return ArrayCollection
*/ */
public function getContent($sort) public function getContent($sort = null)
{ {
/* @var $repo_baskets Alchemy\Phrasea\Model\Repositories\BasketRepository */ /* @var $repo_baskets BasketRepository */
$repo_baskets = $this->app['repo.baskets']; $repo_baskets = $this->app['repo.baskets'];
$sort = in_array($sort, ['date', 'name']) ? $sort : 'name'; $sort = in_array($sort, ['date', 'name']) ? $sort : 'name';
@@ -42,7 +43,7 @@ class WorkZone extends Helper
$baskets = $repo_baskets->findActiveByUser($this->app->getAuthenticatedUser(), $sort); $baskets = $repo_baskets->findActiveByUser($this->app->getAuthenticatedUser(), $sort);
// force creation of a default basket // force creation of a default basket
if (0 === count($baskets)) { if (count($baskets) === 0) {
$basket = new BasketEntity(); $basket = new BasketEntity();
$basket->setName($this->app->trans('Default basket')); $basket->setName($this->app->trans('Default basket'));
@@ -55,7 +56,7 @@ class WorkZone extends Helper
$validations = $repo_baskets->findActiveValidationByUser($this->app->getAuthenticatedUser(), $sort); $validations = $repo_baskets->findActiveValidationByUser($this->app->getAuthenticatedUser(), $sort);
/* @var $repo_stories Alchemy\Phrasea\Model\Repositories\StoryWZRepository */ /* @var $repo_stories StoryWZRepository */
$repo_stories = $this->app['repo.story-wz']; $repo_stories = $this->app['repo.story-wz'];
$stories = $repo_stories->findByUser($this->app, $this->app->getAuthenticatedUser(), $sort); $stories = $repo_stories->findByUser($this->app, $this->app->getAuthenticatedUser(), $sort);

View File

@@ -19,6 +19,7 @@ class Audio extends Provider
const OPTION_THREADS = 'threads'; const OPTION_THREADS = 'threads';
const OPTION_ACODEC = 'acodec'; const OPTION_ACODEC = 'acodec';
const OPTION_AUDIOSAMPLERATE = 'audiosamplerate'; const OPTION_AUDIOSAMPLERATE = 'audiosamplerate';
const OPTION_AUDIOCHANNEL = 'audiochannel';
public function __construct(TranslatorInterface $translator) public function __construct(TranslatorInterface $translator)
{ {
@@ -29,9 +30,12 @@ class Audio extends Provider
47250, 48000, 50000, 50400, 88200, 96000 47250, 48000, 50000, 50400, 88200, 96000
]; ];
$audioChannel = ['mono', 'stereo'];
$this->registerOption(new OptionType\Range($this->translator->trans('Audio Birate'), self::OPTION_AUDIOBITRATE, 32, 320, 128, 32)); $this->registerOption(new OptionType\Range($this->translator->trans('Audio Birate'), self::OPTION_AUDIOBITRATE, 32, 320, 128, 32));
$this->registerOption(new OptionType\Enum($this->translator->trans('AudioSamplerate'), self::OPTION_AUDIOSAMPLERATE, $AVaudiosamplerate)); $this->registerOption(new OptionType\Enum($this->translator->trans('AudioSamplerate'), self::OPTION_AUDIOSAMPLERATE, $AVaudiosamplerate));
$this->registerOption(new OptionType\Enum($this->translator->trans('Audio Codec'), self::OPTION_ACODEC, ['libmp3lame', 'flac'], 'libmp3lame')); $this->registerOption(new OptionType\Enum($this->translator->trans('Audio Codec'), self::OPTION_ACODEC, ['libmp3lame', 'flac', 'pcm_s16le'], 'libmp3lame'));
$this->registerOption(new OptionType\Enum($this->translator->trans('Audio channel'), self::OPTION_AUDIOCHANNEL, $audioChannel));
} }
public function getType() public function getType()
@@ -53,7 +57,21 @@ class Audio extends Provider
$this->spec->setAudioCodec($this->getOption(self::OPTION_ACODEC)->getValue()); $this->spec->setAudioCodec($this->getOption(self::OPTION_ACODEC)->getValue());
$this->spec->setAudioSampleRate($this->getOption(self::OPTION_AUDIOSAMPLERATE)->getValue()); $this->spec->setAudioSampleRate($this->getOption(self::OPTION_AUDIOSAMPLERATE)->getValue());
$this->spec->setAudioKiloBitrate($this->getOption(self::OPTION_AUDIOBITRATE)->getValue()); $this->spec->setAudioKiloBitrate($this->getOption(self::OPTION_AUDIOBITRATE)->getValue());
$this->spec->setAudioChannels($this->getChannelNumber($this->getOption(self::OPTION_AUDIOCHANNEL)->getValue()));
return $this->spec; return $this->spec;
} }
private function getChannelNumber($audioChannel)
{
switch($audioChannel)
{
case 'mono':
return 1;
case 'stereo':
return 2;
default:
return null;
}
}
} }

View File

@@ -61,7 +61,7 @@ class SubdefGenerator
public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null) public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null)
{ {
if ($record->get_hd_file() !== null) { if ($record->get_hd_file() !== null && $record->get_hd_file()->getMimeType() == "application/x-indesign") {
$mediaSource = $this->mediavorus->guess($record->get_hd_file()->getPathname()); $mediaSource = $this->mediavorus->guess($record->get_hd_file()->getPathname());
$metadatas = $mediaSource->getMetadatas(); $metadatas = $mediaSource->getMetadatas();
@@ -69,15 +69,27 @@ class SubdefGenerator
if(!isset($this->tmpFilesystem)){ if(!isset($this->tmpFilesystem)){
$this->tmpFilesystem = Manager::create(); $this->tmpFilesystem = Manager::create();
} }
$tmpDir = $this->tmpFilesystem->createTemporaryDirectory(); $tmpDir = $this->tmpFilesystem->createTemporaryDirectory(0777, 500);
try { $files = $this->app['exiftool.preview-extractor']->extract($record->get_hd_file()->getPathname(), $tmpDir);
$this->app['filesystem']->dumpFile($tmpDir.'/file.jpg', $metadatas->get('XMP-xmp:PageImage')->getValue()->asString());
$this->tmpFilePath = $tmpDir.'/file.jpg'; $selected = null;
} catch (\Exception $e) { $size = null;
$this->logger->error(sprintf('Unable to write temporary file : %s', $e->getMessage()));
foreach ($files as $file) {
if ($file->isDir() || $file->isDot()) {
continue;
}
if (is_null($selected) || $file->getSize() > $size) {
$selected = $file->getPathname();
$size = $file->getSize();
}
} }
if ($selected) {
$this->tmpFilePath = $selected;
}
} }
} }

View File

@@ -73,6 +73,9 @@ class SubdefSubstituer
$this->createMediaSubdef($record, 'document', $media); $this->createMediaSubdef($record, 'document', $media);
$record->setMimeType($media->getFile()->getMimeType());
$record->setType($media->getType());
$record->write_metas(); $record->write_metas();
if ($shouldSubdefsBeRebuilt) { if ($shouldSubdefsBeRebuilt) {

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Metadata;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Databox\DataboxRepository; use Alchemy\Phrasea\Databox\DataboxRepository;
use Alchemy\Phrasea\Metadata\Tag\NoSource; use Alchemy\Phrasea\Metadata\Tag\NoSource;
use DateTime;
use PHPExiftool\Driver\Metadata\Metadata; use PHPExiftool\Driver\Metadata\Metadata;
class PhraseanetMetadataSetter class PhraseanetMetadataSetter
@@ -66,8 +67,16 @@ class PhraseanetMetadataSetter
continue; continue;
} }
$data['value'] = $value; if ($field->get_type() == 'date') {
try {
$dateTime = new DateTime($value);
$value = $dateTime->format('Y/m/d H:i:s');
} catch (\Exception $e) {
// $value unchanged
}
}
$data['value'] = $value;
$metadataInRecordFormat[] = $data; $metadataInRecordFormat[] = $data;
} }
} }

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Model\Entities; namespace Alchemy\Phrasea\Model\Entities;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Mapping\Annotation as Gedmo;
use \record_adapter; use \record_adapter;
@@ -474,4 +475,32 @@ class LazaretFile
return $merged; return $merged;
} }
/**
* @param Application $app
* @return array|null
*/
public function getStatus(Application $app)
{
/**@var LazaretAttribute $atribute*/
foreach ($this->attributes as $atribute) {
if ($atribute->getName() == AttributeInterface::NAME_STATUS) {
$databox = $this->getCollection($app)->get_databox();
$statusStructure = $databox->getStatusStructure();
$recordsStatuses = [];
foreach ($statusStructure as $status) {
$bit = $status['bit'];
if (!isset($recordsStatuses[$bit])) {
$recordsStatuses[$bit] = $status;
}
$statusSet = \databox_status::bitIsSet(bindec($atribute->getValue()), $bit);
if (!isset($recordsStatuses[$bit]['flag'])) {
$recordsStatuses[$bit]['flag'] = (int) $statusSet;
}
}
return $recordsStatuses;
}
}
return null;
}
} }

View File

@@ -18,7 +18,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* @ORM\Table(name="ValidationSessions") * @ORM\Table(name="ValidationSessions")
* @ORM\Entity * @ORM\Entity(repositoryClass="Alchemy\Phrasea\Model\Repositories\ValidationSessionRepository")
*/ */
class ValidationSession class ValidationSession
{ {

View File

@@ -57,6 +57,14 @@ class ApiApplicationManipulator implements ManipulatorInterface
$this->om->flush(); $this->om->flush();
} }
public function deleteApiApplications(array $applications)
{
foreach ($applications as $application) {
$this->om->remove($application);
}
$this->om->flush();
}
public function update(ApiApplication $application) public function update(ApiApplication $application)
{ {
$this->om->persist($application); $this->om->persist($application);

View File

@@ -118,4 +118,12 @@ class BasketManipulator
$this->manager->remove($basket); $this->manager->remove($basket);
$this->manager->flush(); $this->manager->flush();
} }
public function removeBaskets(array $baskets)
{
foreach ($baskets as $basket) {
$this->manager->remove($basket);
}
$this->manager->flush();
}
} }

View File

@@ -226,6 +226,8 @@ class LazaretManipulator
$this->entityManager->remove($lazaretFile); $this->entityManager->remove($lazaretFile);
$this->entityManager->flush(); $this->entityManager->flush();
$ret['result']['record_id'] = $record->getRecordId();
$ret['success'] = true; $ret['success'] = true;
} catch (\Exception $e) { } catch (\Exception $e) {
$ret['message'] = $this->app->trans('An error occured'); $ret['message'] = $this->app->trans('An error occured');

View File

@@ -26,6 +26,7 @@ class TokenManipulator implements ManipulatorInterface
const TYPE_FEED_ENTRY = 'FEED_ENTRY'; const TYPE_FEED_ENTRY = 'FEED_ENTRY';
const TYPE_PASSWORD = 'password'; const TYPE_PASSWORD = 'password';
const TYPE_ACCOUNT_UNLOCK = 'account-unlock'; const TYPE_ACCOUNT_UNLOCK = 'account-unlock';
const TYPE_ACCOUNT_DELETE = 'account-delete';
const TYPE_DOWNLOAD = 'download'; const TYPE_DOWNLOAD = 'download';
const TYPE_MAIL_DOWNLOAD = 'mail-download'; const TYPE_MAIL_DOWNLOAD = 'mail-download';
const TYPE_EMAIL = 'email'; const TYPE_EMAIL = 'email';
@@ -167,6 +168,16 @@ class TokenManipulator implements ManipulatorInterface
return $this->create($user, self::TYPE_ACCOUNT_UNLOCK, new \DateTime('+3 days')); return $this->create($user, self::TYPE_ACCOUNT_UNLOCK, new \DateTime('+3 days'));
} }
/**
* @param User $user
*
* @return Token
*/
public function createAccountDeleteToken(User $user, $email)
{
return $this->create($user, self::TYPE_ACCOUNT_DELETE, new \DateTime('+1 hour'), $email);
}
/** /**
* @param User $user * @param User $user
* *

View File

@@ -54,21 +54,24 @@ class BasketRepository extends EntityRepository
/** /**
* Returns all basket for a given user that are not marked as archived * Returns all basket for a given user that are not marked as archived
* *
* @param User $user * @param User $user
* @param null|string $sort
* @return Basket[] * @return Basket[]
*/ */
public function findActiveByUser(User $user, $sort = null) public function findActiveByUser(User $user, $sort = null)
{ {
$dql = 'SELECT b // checked : 4 usages, "b.elements" is useless
FROM Phraseanet:Basket b $dql = "SELECT b\n"
LEFT JOIN b.elements e . " FROM Phraseanet:Basket b\n"
WHERE b.user = :usr_id // . " LEFT JOIN b.elements e\n" //
AND b.archived = false'; . " WHERE b.user = :usr_id\n"
. " AND b.archived = false";
if ($sort == 'date') { if ($sort == 'date') {
$dql .= ' ORDER BY b.created DESC'; $dql .= "\n ORDER BY b.created DESC";
} elseif ($sort == 'name') { }
$dql .= ' ORDER BY b.name ASC'; elseif ($sort == 'name') {
$dql .= "\n ORDER BY b.name ASC";
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
@@ -80,24 +83,27 @@ class BasketRepository extends EntityRepository
/** /**
* Returns all unread basket for a given user that are not marked as archived * Returns all unread basket for a given user that are not marked as archived
* *
* @param User $user * @param User $user
* @return Basket[] * @return Basket[]
*/ */
public function findUnreadActiveByUser(User $user) public function findUnreadActiveByUser(User $user)
{ {
$dql = 'SELECT b // checked : 2 usages, "b.elements" is useless
FROM Phraseanet:Basket b $dql = "SELECT b\n"
JOIN b.elements e . " FROM Phraseanet:Basket b\n"
LEFT JOIN b.validation s // . " JOIN b.elements e\n"
LEFT JOIN s.participants p . " LEFT JOIN b.validation s\n"
WHERE b.archived = false . " LEFT JOIN s.participants p\n"
AND ( . " WHERE b.archived = false\n"
(b.user = :usr_id_owner AND b.isRead = false) . " AND (\n"
OR (b.user != :usr_id_ownertwo . " (b.user = :usr_id_owner AND b.isRead = false)\n"
AND p.user = :usr_id_participant . " OR \n"
AND p.is_aware = false) . " (b.user != :usr_id_ownertwo\n"
) . " AND p.user = :usr_id_participant\n"
AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())'; . " AND p.is_aware = false\n"
. " AND s.expires > CURRENT_TIMESTAMP()\n"
. " )\n"
. " )";
$params = [ $params = [
'usr_id_owner' => $user->getId(), 'usr_id_owner' => $user->getId(),
@@ -115,11 +121,22 @@ class BasketRepository extends EntityRepository
* Returns all baskets that are in validation session not expired and * Returns all baskets that are in validation session not expired and
* where a specified user is participant (not owner) * where a specified user is participant (not owner)
* *
* @param User $user * @param User $user
* @param null|string $sort
* @return Basket[] * @return Basket[]
*/ */
public function findActiveValidationByUser(User $user, $sort = null) public function findActiveValidationByUser(User $user, $sort = null)
{ {
// checked : 2 usages, "b.elements" seems useless.
$dql = "SELECT b\n"
. "FROM Phraseanet:Basket b\n"
// . " JOIN b.elements e\n"
// . " JOIN e.validation_datas v\n"
. " JOIN b.validation s\n"
. " JOIN s.participants p\n"
. "WHERE b.user != ?1 AND p.user = ?2\n"
. " AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())";
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
JOIN b.elements e JOIN b.elements e
@@ -130,9 +147,9 @@ class BasketRepository extends EntityRepository
AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP()) '; AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP()) ';
if ($sort == 'date') { if ($sort == 'date') {
$dql .= ' ORDER BY b.created DESC'; $dql .= "\nORDER BY b.created DESC";
} elseif ($sort == 'name') { } elseif ($sort == 'name') {
$dql .= ' ORDER BY b.name ASC'; $dql .= "\nORDER BY b.name ASC";
} }
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
@@ -152,10 +169,11 @@ class BasketRepository extends EntityRepository
*/ */
public function findUserBasket($basket_id, User $user, $requireOwner) public function findUserBasket($basket_id, User $user, $requireOwner)
{ {
$dql = 'SELECT b // checked : 3 usages, "b.elements e" seems useless
FROM Phraseanet:Basket b $dql = "SELECT b\n"
LEFT JOIN b.elements e . " FROM Phraseanet:Basket b\n"
WHERE b.id = :basket_id'; // . " LEFT JOIN b.elements e\n"
. " WHERE b.id = :basket_id";
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$query->setParameters(['basket_id' => $basket_id]); $query->setParameters(['basket_id' => $basket_id]);
@@ -188,7 +206,7 @@ class BasketRepository extends EntityRepository
public function findContainingRecordForUser(\record_adapter $record, User $user) public function findContainingRecordForUser(\record_adapter $record, User $user)
{ {
// todo : check "e.sbas_id = e.sbas_id" ???
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
JOIN b.elements e JOIN b.elements e
@@ -210,30 +228,31 @@ class BasketRepository extends EntityRepository
{ {
switch ($type) { switch ($type) {
case self::RECEIVED: case self::RECEIVED:
$dql = 'SELECT b // todo : check when called, and if "LEFT JOIN b.elements e" is usefull
FROM Phraseanet:Basket b $dql = "SELECT b\n"
JOIN b.elements e . "FROM Phraseanet:Basket b\n"
WHERE b.user = :usr_id AND b.pusher_id IS NOT NULL'; . " JOIN b.elements e\n"
. "WHERE b.user = :usr_id AND b.pusher_id IS NOT NULL";
$params = [ $params = [
'usr_id' => $user->getId() 'usr_id' => $user->getId()
]; ];
break; break;
case self::VALIDATION_DONE: case self::VALIDATION_DONE:
$dql = 'SELECT b // todo : check when called, and if "LEFT JOIN b.elements e" is usefull
FROM Phraseanet:Basket b $dql = "SELECT b\n"
JOIN b.elements e . "FROM Phraseanet:Basket b\n"
JOIN b.validation s . " JOIN b.elements e\n"
JOIN s.participants p . " JOIN b.validation s\n"
WHERE b.user != ?1 AND p.user = ?2'; . " JOIN s.participants p\n"
. "WHERE b.user != ?1 AND p.user = ?2";
$params = [ $params = [
1 => $user->getId() 1 => $user->getId(),
, 2 => $user->getId() 2 => $user->getId()
]; ];
break; break;
case self::VALIDATION_SENT: case self::VALIDATION_SENT:
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
JOIN b.elements e
JOIN b.validation v JOIN b.validation v
WHERE b.user = :usr_id'; WHERE b.user = :usr_id';
$params = [ $params = [
@@ -243,7 +262,6 @@ class BasketRepository extends EntityRepository
case self::MYBASKETS: case self::MYBASKETS:
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
LEFT JOIN b.elements e
LEFT JOIN b.validation s LEFT JOIN b.validation s
LEFT JOIN s.participants p LEFT JOIN s.participants p
WHERE (b.user = :usr_id)'; WHERE (b.user = :usr_id)';
@@ -252,6 +270,7 @@ class BasketRepository extends EntityRepository
]; ];
break; break;
default: default:
// todo : check when called, and if "LEFT JOIN b.elements e" is usefull
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
LEFT JOIN b.elements e LEFT JOIN b.elements e
@@ -297,6 +316,7 @@ class BasketRepository extends EntityRepository
*/ */
public function findActiveValidationAndBasketByUser(User $user, $sort = null) public function findActiveValidationAndBasketByUser(User $user, $sort = null)
{ {
// todo : check caller and if "LEFT JOIN b.elements e" is usefull
$dql = 'SELECT b $dql = 'SELECT b
FROM Phraseanet:Basket b FROM Phraseanet:Basket b
LEFT JOIN b.elements e LEFT JOIN b.elements e

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Model\Repositories;
use Doctrine\ORM\EntityRepository;
/**
* ValidationSessionRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class ValidationSessionRepository extends EntityRepository
{
}

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Model\Types; namespace Alchemy\Phrasea\Model\Types;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
class BinaryString extends Type class BinaryString extends Type
@@ -23,10 +24,21 @@ class BinaryString extends Type
return static::BINARY_STRING; return static::BINARY_STRING;
} }
/**
* {@inheritdoc}
*
* @see: https://blog.vandenbrand.org/2015/06/25/creating-a-custom-doctrine-dbal-type-the-right-way/
* about the reason of the COMMENT in the column
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{ {
if ($platform->getName() === 'mysql') { if ($platform->getName() === 'mysql') {
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)." ". $platform->getCollationFieldDeclaration('utf8_bin'); /** @var MySqlPlatform $platform */
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)
// . " CHARACTER SET utf8"
. " " . $platform->getColumnCollationDeclarationSQL('utf8_bin')
. " COMMENT '(DC2Type:binary_string)'"
;
} }
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
@@ -39,4 +51,12 @@ class BinaryString extends Type
{ {
return $platform->getVarcharDefaultLength(); return $platform->getVarcharDefaultLength();
} }
/**
* @inheritdoc
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
} }

View File

@@ -17,6 +17,8 @@ use Alchemy\Phrasea\Notification\ReceiverInterface;
abstract class AbstractMail implements MailInterface abstract class AbstractMail implements MailInterface
{ {
const MAIL_SKIN = 'default';
/** @var Application */ /** @var Application */
protected $app; protected $app;
/** @var EmitterInterface */ /** @var EmitterInterface */
@@ -59,6 +61,7 @@ abstract class AbstractMail implements MailInterface
'expiration' => $this->getExpiration(), 'expiration' => $this->getExpiration(),
'buttonUrl' => $this->getButtonURL(), 'buttonUrl' => $this->getButtonURL(),
'buttonText' => $this->getButtonText(), 'buttonText' => $this->getButtonText(),
'mailSkin' => $this->getMailSkin(),
]); ]);
} }
@@ -166,6 +169,14 @@ abstract class AbstractMail implements MailInterface
$this->url = $url; $this->url = $url;
} }
/**
* @return string
*/
public function getMailSkin()
{
return self::MAIL_SKIN;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@@ -0,0 +1,105 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Notification\Mail;
use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User;
class MailRequestAccountDelete extends AbstractMailWithLink
{
const MAIL_SKIN = 'warning';
/** @var User */
private $user;
/**
* Set the user owner
*
* @param User $userOwner
*/
public function setUserOwner(User $userOwner)
{
$this->user = $userOwner;
}
/**
* {@inheritdoc}
*/
public function getSubject()
{
return $this->app->trans('Email:deletion:request:subject Delete account confirmation');
}
/**
* {@inheritdoc}
*/
public function getMessage()
{
if (!$this->user) {
throw new LogicException('You must set a user before calling getMessage');
}
return $this->app->trans("Email:deletion:request:message Hello %civility% %firstName% %lastName%.
We have received an account deletion request for your account on %urlInstance%, please confirm this deletion by clicking on the link below.
If you are not at the origin of this request, please change your password as soon as possible %resetPassword%
Link is valid for one hour.", [
'%civility%' => $this->getOwnerCivility(),
'%firstName%'=> $this->user->getFirstName(),
'%lastName%' => $this->user->getLastName(),
'%urlInstance%' => '<a href="'.$this->getPhraseanetURL().'">'.$this->getPhraseanetURL().'</a>',
'%resetPassword%' => '<a href="'.$this->app->url('reset_password').'">'.$this->app->url('reset_password').'</a>',
]);
}
/**
* {@inheritdoc}
*/
public function getButtonText()
{
return $this->app->trans('Email:deletion:request:textButton Delete my account');
}
/**
* {@inheritdoc}
*/
public function getButtonURL()
{
return $this->url;
}
/**
* {@inheritdoc}
*/
public function getMailSkin()
{
return self::MAIL_SKIN;
}
private function getOwnerCivility()
{
if (!$this->user) {
throw new LogicException('You must set a user before calling getMessage');
}
$civilities = [
User::GENDER_MISS => 'Miss',
User::GENDER_MRS => 'Mrs',
User::GENDER_MR => 'Mr',
];
if (array_key_exists($this->user->getGender(), $civilities)) {
return $civilities[$this->user->getGender()];
} else {
return '';
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Notification\Mail;
class MailSuccessAccountDelete extends AbstractMail
{
/**
* {@inheritdoc}
*/
public function getSubject()
{
return $this->app->trans('Delete account successfull');
}
/**
* {@inheritdoc}
*/
public function getMessage()
{
return $this->app->trans('Your phraseanet account on %urlInstance% has been deleted!', ['%urlInstance%' => '<a href="'.$this->getPhraseanetURL().'">'.$this->getPhraseanetURL().'</a>']);
}
/**
* {@inheritdoc}
*/
public function getButtonText()
{
}
/**
* {@inheritdoc}
*/
public function getButtonURL()
{
}
}

Some files were not shown because too many files have changed in this diff Show More