Browse Source

new: [framadate] adding charm

framadate
Valentin Lab 6 years ago
parent
commit
3d685e994a
  1. 123
      framadate/hooks/init
  2. 28
      framadate/hooks/postgres_database-relation-joined
  3. 19
      framadate/hooks/publish_dir-relation-joined
  4. 50
      framadate/lib/common
  5. 34
      framadate/metadata.yml
  6. 2830
      framadate/patch/composer.json.patch
  7. 23
      framadate/patch/find-all-poll-date.patch
  8. 39
      framadate/patch/postgresql-compatibility.patch
  9. 12
      framadate/patch/protect-unset.patch
  10. 13
      framadate/patch/typo-poll-creation.patch
  11. 433
      framadate/src/init.sql

123
framadate/hooks/init

@ -0,0 +1,123 @@
#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
. lib/common
set -e
if ! [ -e "$FRAMADATE_CODE" ]; then
git clone --depth 1 -b v1.2.0-alpha.1 \
https://framagit.org/framasoft/framadate/framadate.git \
"$FRAMADATE_CODE"
mv "$FRAMADATE_CODE"/{htaccess.txt,.htaccess}
(
cd "$FRAMADATE_CODE"
patch -p1
) < <(cat patch/*.patch)
fi
if ! [ -e "$FRAMADATE_CODE/vendor" ]; then
dcomposer global require "hirak/prestissimo:^0.3" \
--prefer-dist \
--no-progress \
--no-suggest \
--classmap-authoritative \
--ignore-platform-reqs
fi
cfg_dir=$(cfg_dir_init) || exit 1
cd "$cfg_dir" || exit 1
FRAMADATE_OPTS=(
title:NOMAPPLICATION
admin-mail:ADRESSEMAILADMIN
auto-response-mail:ADRESSEMAILREPONSEAUTO
default-language:DEFAULT_LANGUAGE
)
cat <<EOF > config.php
<?php
EOF
for opt in "${FRAMADATE_OPTS[@]}"; do
yaml_opt=${opt%%:*}
php_opt=${opt##*:}
value=$(options-get "$yaml_opt") || exit 1
echo "const $php_opt = '$value';" >> config.php || exit 1
done
cat <<'EOF' >> config.php
// List of supported languages, fake constant as arrays can be used as constants only in PHP >=5.6
$ALLOWED_LANGUAGES = [
'fr' => 'Français',
'en' => 'English',
'oc' => 'Occitan',
'es' => 'Español',
'de' => 'Deutsch',
'nl' => 'Dutch',
'it' => 'Italiano',
'br' => 'Brezhoneg',
];
// Path to image file with the title
const IMAGE_TITRE = 'images/logo-framadate.png';
// Clean URLs, boolean
const URL_PROPRE = true;
// Use REMOTE_USER data provided by web server
const USE_REMOTE_USER = true;
// Path to the log file
const LOG_FILE = 'log/stdout.log';
// Days (after expiration date) before purging a poll
const PURGE_DELAY = 60;
// Max slots per poll
const MAX_SLOTS_PER_POLL = 366;
// Number of seconds before we allow to resend an "Remember Edit Link" email.
const TIME_EDIT_LINK_EMAIL = 60;
// Config
$config = [
/* general config */
'use_smtp' => true, // use email for polls creation/modification/responses notification
'smtp_options' => [
'host' => 'localhost', // SMTP server (you could add many servers (main and backup for example) : use ";" like separator
'auth' => false, // Enable SMTP authentication
'username' => '', // SMTP username
'password' => '', // SMTP password
'secure' => '', // Enable encryption (false, tls or ssl)
'port' => 25, // TCP port to connect to
],
/* home */
'show_what_is_that' => true, // display "how to use" section
'show_the_software' => true, // display technical information about the software
'show_cultivate_your_garden' => true, // display "development and administration" information
/* create_classic_poll.php / create_date_poll.php */
'default_poll_duration' => 180, // default values for the new poll duration (number of days).
/* create_classic_poll.php */
'user_can_add_img_or_link' => true, // user can add link or URL when creating his poll.
'markdown_editor_by_default' => true, // The markdown editor for the description is enabled by default
'provide_fork_awesome' => true, // Whether the build-in fork-awesome should be provided
];
EOF

28
framadate/hooks/postgres_database-relation-joined

@ -0,0 +1,28 @@
#!/bin/bash
. lib/common
set -e
PASSWORD="$(relation-get password)"
USER="$(relation-get user)"
DBNAME="$(relation-get dbname)"
cfg_dir=$(cfg_dir_init) || exit 1
cd "$cfg_dir" || exit 1
cat <<EOF >> config.php
const DB_CONNECTION_STRING = 'pgsql:host=$TARGET_SERVICE_NAME;dbname=$DBNAME;port=5432';
const DB_DRIVER = 'pdo_pgsql';
const DB_NAME = '$DBNAME';
const DB_HOST = '$TARGET_SERVICE_NAME';
const DB_PORT = '5432';
const DB_USER= '$USER';
const DB_PASSWORD = '$PASSWORD';
const TABLENAME_PREFIX = 'fd_';
const MIGRATION_TABLE = 'migration';
EOF

19
framadate/hooks/publish_dir-relation-joined

@ -0,0 +1,19 @@
#!/bin/bash
. lib/common
set -e
domain=$(relation-get domain) || exit 1
location=$DATASTORE/$BASE_SERVICE_NAME/var/www/$domain
if ! [ -e "$location/app/inc/init.php" ]; then
cp -av "$FRAMADATE_CODE/app/inc/"* "$location/app/inc/"
fi
cfg_dir=$(cfg_dir_init) || exit 1
cd "$cfg_dir"
echo "const APP_URL = '$domain';" >> config.php

50
framadate/lib/common

@ -0,0 +1,50 @@
# -*- mode: sh -*-
COMPOSER_DIR="$SERVICE_CONFIGSTORE/root/.composer"
FRAMADATE_CODE="$SERVICE_CONFIGSTORE/opt/apps/framadate"
dcomposer() {
docker run --rm -v "$COMPOSER_DIR:/root/.composer" \
-v "$FRAMADATE_CODE:/opt/apps/framadate" \
-w "/opt/apps/framadate" \
--env "COMPOSER_ALLOW_SUPERUSER=1" \
composer:latest "-vvv" "--working-dir=/opt/apps/framadate" "$@"
}
cfg_dir_init() {
local locations candidate_location cfg_dir
if [ "$BASE_SERVICE_NAME" ]; then
candidate_location=("$DATASTORE/$BASE_SERVICE_NAME/var/www/"*"/app/inc/")
else
candidate_location=("$DATASTORE/$SERVICE_NAME/var/www/"*"/app/inc/")
fi
locations=()
for location in "${candidate_location[@]}"; do
[ -d "${location[0]}" ] || continue
locations+=("$location")
done
case "${#locations[@]}" in
0)
debug "Relation publish-dir did not yet copy config files"
## not yet copied
cfg_dir="$FRAMADATE_CODE/app/inc/"
;;
1)
debug "Relation publish-dir already copied config files"
cfg_dir="${locations[0]}"
;;
*)
err "Unexpected: there are more than one directory in $DATASTORE/$BASE_SERVICE_NAME/var/www/"
exit 1
;;
esac
debug "found location: $cfg_dir" >&2
echo "$cfg_dir"
}

34
framadate/metadata.yml

@ -0,0 +1,34 @@
description: Framadate
subordinate: true
host-resources:
- /etc/timezone
default-options:
title: "Framadate"
admin-mail: "admin@example.com"
auto-response-mail: "no@reply"
default-language: fr
uses:
publish-dir:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
database: "HTTP Publishing"
scope: container
default-options:
location: !var-expand "$CONFIGSTORE/$BASE_SERVICE_NAME/opt/apps/framadate"
data-dirs:
- tpl_c
- app/inc
- log
postgres-database:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
database: "main storage"
default-options:
init-sql: !file-content "$BASE_CHARM_PATH/src/init.sql"

2830
framadate/patch/composer.json.patch
File diff suppressed because it is too large
View File

23
framadate/patch/find-all-poll-date.patch

@ -0,0 +1,23 @@
diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php
index 4a1e6ea..7cedca1 100644
--- a/app/classes/Framadate/Repositories/PollRepository.php
+++ b/app/classes/Framadate/Repositories/PollRepository.php
@@ -202,7 +202,17 @@ class PollRepository extends AbstractRepository {
$prepared->execute();
- return $prepared->fetchAll();
+ $polls = $prepared->fetchAll();
+
+ foreach ($polls as $poll) {
+ /**
+ * Hack to make date a proper DateTime
+ */
+ $poll->creation_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->creation_date, $this->connect->getDatabasePlatform());
+ $poll->end_date = Type::getType(Type::DATETIME)->convertToPhpValue($poll->end_date, $this->connect->getDatabasePlatform());
+ }
+ return $polls;
+
}
/**

39
framadate/patch/postgresql-compatibility.patch

@ -0,0 +1,39 @@
diff --git a/app/classes/Framadate/Repositories/PollRepository.php b/app/classes/Framadate/Repositories/PollRepository.php
index 78d0860..4a1e6ea 100644
--- a/app/classes/Framadate/Repositories/PollRepository.php
+++ b/app/classes/Framadate/Repositories/PollRepository.php
@@ -163,7 +163,7 @@ class PollRepository extends AbstractRepository {
$request .= "SELECT p.*,";
$request .= " (SELECT count(1) FROM " . Utils::table('vote') . " v WHERE p.id=v.poll_id) votes";
$request .= " FROM " . Utils::table('poll') . " p";
- $request .= " WHERE 1";
+ $request .= " WHERE True";
$values = [];
@@ -189,7 +189,7 @@ class PollRepository extends AbstractRepository {
}
$request .= " ORDER BY p.title ASC";
- $request .= " LIMIT :start, :limit";
+ $request .= " OFFSET :start LIMIT :limit";
$prepared = $this->prepare($request);
@@ -230,11 +230,11 @@ class PollRepository extends AbstractRepository {
// Total count
$prepared = $this->prepare('
SELECT count(1) nb
- FROM ' . Utils::table('poll') . ' p
- WHERE (:id = "" OR p.id LIKE :id)
- AND (:title = "" OR p.title LIKE :title)
- AND (:name = "" OR p.admin_name LIKE :name)
- ORDER BY p.title ASC');
+ FROM ' . Utils::table('poll') . " p
+ WHERE (:id = '' OR p.id LIKE :id)
+ AND (:title = '' OR p.title LIKE :title)
+ AND (:name = '' OR p.admin_name LIKE :name)
+");
$poll = $search === null ? '' : $search['poll'] . '%';
$title = $search === null ? '' : '%' . $search['title'] . '%';

12
framadate/patch/protect-unset.patch

@ -0,0 +1,12 @@
diff --git a/app/inc/init.php b/app/inc/init.php
index 0e8fb19..272d83c 100644
--- a/app/inc/init.php
+++ b/app/inc/init.php
@@ -97,4 +97,6 @@ require_once __DIR__ . '/i18n.php';
require_once __DIR__ . '/smarty.php';
require_once __DIR__ . '/services.php';
-Services::init($connect, $smarty);
+if (isset($connect)) {
+ Services::init($connect, $smarty);
+}

13
framadate/patch/typo-poll-creation.patch

@ -0,0 +1,13 @@
diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php
index ca9eb70..3d9e967 100644
--- a/app/classes/Framadate/Services/PollService.php
+++ b/app/classes/Framadate/Services/PollService.php
@@ -216,7 +216,7 @@ class PollService {
list($poll_id, $admin_poll_id) = $this->createPoll($form);
// Send confirmation by mail if enabled
- if (!is_null($ids)) {
+ if (!is_null($poll_id)) {
// Everything went well
$this->notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id);

433
framadate/src/init.sql

@ -0,0 +1,433 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 10.4
-- Dumped by pg_dump version 10.4
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--
-- Name: comment_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.comment_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: comments_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.comments_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: fd_comment; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.fd_comment (
id integer NOT NULL,
poll_id character varying(64) NOT NULL,
name character varying(64) NOT NULL,
comment text NOT NULL,
date timestamp(0) without time zone DEFAULT ((0)::abstime)::timestamp without time zone NOT NULL
);
--
-- Name: fd_comment_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.fd_comment_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: fd_comment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.fd_comment_id_seq OWNED BY public.fd_comment.id;
--
-- Name: fd_migration_new; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.fd_migration_new (
version character varying(255) NOT NULL
);
--
-- Name: fd_poll; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.fd_poll (
id character varying(64) NOT NULL,
admin_id character varying(255) NOT NULL,
title text NOT NULL,
description text,
admin_name character varying(255) NOT NULL,
admin_mail character varying(255) DEFAULT NULL::character varying,
creation_date timestamp(0) without time zone DEFAULT '2019-05-02 22:18:17'::timestamp without time zone NOT NULL,
end_date timestamp(0) without time zone DEFAULT NULL::timestamp without time zone,
format character varying(255) DEFAULT NULL::character varying,
editable integer DEFAULT 0 NOT NULL,
receivenewvotes boolean DEFAULT false NOT NULL,
active boolean DEFAULT true NOT NULL,
receivenewcomments boolean DEFAULT false NOT NULL,
hidden boolean DEFAULT false NOT NULL,
password_hash character varying(255) DEFAULT NULL::character varying,
results_publicly_visible boolean,
valuemax smallint,
collect_users_mail boolean DEFAULT false NOT NULL,
collect_users_mail_integer smallint DEFAULT 0 NOT NULL
);
--
-- Name: fd_slot; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.fd_slot (
id integer NOT NULL,
poll_id character varying(64) NOT NULL,
title text NOT NULL,
moments text
);
--
-- Name: fd_slot_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.fd_slot_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: fd_slot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.fd_slot_id_seq OWNED BY public.fd_slot.id;
--
-- Name: fd_vote; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.fd_vote (
id integer NOT NULL,
poll_id character varying(64) NOT NULL,
name character varying(255) NOT NULL,
choices character varying(255) NOT NULL,
uniqid character varying(16) NOT NULL,
mail character varying(255) DEFAULT NULL::character varying
);
--
-- Name: fd_vote_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.fd_vote_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: fd_vote_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.fd_vote_id_seq OWNED BY public.fd_vote.id;
--
-- Name: slot_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.slot_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: user_studs_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.user_studs_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: vote_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.vote_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: fd_comment id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.fd_comment ALTER COLUMN id SET DEFAULT nextval('public.fd_comment_id_seq'::regclass);
--
-- Name: fd_slot id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.fd_slot ALTER COLUMN id SET DEFAULT nextval('public.fd_slot_id_seq'::regclass);
--
-- Name: fd_vote id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.fd_vote ALTER COLUMN id SET DEFAULT nextval('public.fd_vote_id_seq'::regclass);
--
-- Data for Name: fd_comment; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.fd_comment (id, poll_id, name, comment, date) FROM stdin;
\.
--
-- Data for Name: fd_migration_new; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.fd_migration_new (version) FROM stdin;
20150101000000
20150102000000
20150102100000
20150117000000
20150402000000
20150405000000
20150624000000
20150918000000
20151012075900
20151012082600
20151028000000
20151205000000
20180220000000
20180411000000
20180419170000
20180419180000
20180419190000
20180525110000
\.
--
-- Data for Name: fd_poll; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.fd_poll (id, admin_id, title, description, admin_name, admin_mail, creation_date, end_date, format, editable, receivenewvotes, active, receivenewcomments, hidden, password_hash, results_publicly_visible, valuemax, collect_users_mail, collect_users_mail_integer) FROM stdin;
\.
--
-- Data for Name: fd_slot; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.fd_slot (id, poll_id, title, moments) FROM stdin;
\.
--
-- Data for Name: fd_vote; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.fd_vote (id, poll_id, name, choices, uniqid, mail) FROM stdin;
\.
--
-- Name: comment_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.comment_seq', 1, false);
--
-- Name: comments_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.comments_seq', 1, false);
--
-- Name: fd_comment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.fd_comment_id_seq', 1, false);
--
-- Name: fd_slot_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.fd_slot_id_seq', 1, false);
--
-- Name: fd_vote_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.fd_vote_id_seq', 1, false);
--
-- Name: slot_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.slot_seq', 1, false);
--
-- Name: user_studs_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.user_studs_seq', 1, false);
--
-- Name: vote_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.vote_seq', 1, false);
--
-- Name: fd_migration_new fd_migration_new_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.fd_migration_new
ADD CONSTRAINT fd_migration_new_pkey PRIMARY KEY (version);
--
-- Name: comment_index_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX comment_index_id ON public.fd_comment USING btree (id);
--
-- Name: comment_index_poll_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX comment_index_poll_id ON public.fd_comment USING btree (poll_id);
--
-- Name: idx_vote_uniqid; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_vote_uniqid ON public.fd_vote USING btree (uniqid);
--
-- Name: poll_index_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX poll_index_id ON public.fd_poll USING btree (id);
--
-- Name: slot_index_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX slot_index_id ON public.fd_slot USING btree (id);
--
-- Name: slot_index_poll_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX slot_index_poll_id ON public.fd_slot USING btree (poll_id);
--
-- Name: vote_index_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX vote_index_id ON public.fd_vote USING btree (id);
--
-- Name: vote_index_poll_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX vote_index_poll_id ON public.fd_vote USING btree (poll_id);
--
-- PostgreSQL database dump complete
--
Loading…
Cancel
Save