diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc2569562a..bc26be3ce8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,9 +73,6 @@ jobs: # subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} # subject-digest: ${{ steps.push.outputs.digest }} # push-to-registry: true - - - name: Create private-files folder - run: docker compose run --rm web mkdir var/private-files - name: Start services run: docker compose up database redis mailhog web --wait --no-build @@ -94,6 +91,9 @@ jobs: - name: Run db-updates run: docker compose exec -T web php mapas/src/tools/apply-updates.php + - + name: Run db-updates + run: docker compose exec -T web php mapas/src/tools/apply-multicore-db-update.php - name: Run migrations run: docker compose exec -T web bin/console -e test doctrine:migrations:migrate --no-interaction diff --git a/api/mapas/app/bin/doctrine b/api/mapas/app/bin/doctrine index de9ece7875..e11e2dd80e 100755 --- a/api/mapas/app/bin/doctrine +++ b/api/mapas/app/bin/doctrine @@ -6,10 +6,22 @@ require dirname(__DIR__, 2) . '/public/bootstrap.php'; use Doctrine\ORM\Tools\Console\ConsoleRunner; use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider; +use Doctrine\Migrations\Tools\Console\Command; $entityManager = $app->em ?? null; -$commands = []; +$commands = [ + new Command\DumpSchemaCommand(), + new Command\ExecuteCommand(), + new Command\GenerateCommand(), + new Command\LatestCommand(), + new Command\ListCommand(), + new Command\MigrateCommand(), + new Command\RollupCommand(), + new Command\StatusCommand(), + new Command\SyncMetadataCommand(), + new Command\VersionCommand(), +]; ConsoleRunner::run( new SingleManagerProvider($entityManager), diff --git a/api/mapas/dev/db/dump.sql b/api/mapas/dev/db/dump.sql index 133e05a92c..92b5dd6119 100644 --- a/api/mapas/dev/db/dump.sql +++ b/api/mapas/dev/db/dump.sql @@ -33,21 +33,6 @@ CREATE SCHEMA tiger_data; ALTER SCHEMA tiger_data OWNER TO mapas; --- --- Name: topology; Type: SCHEMA; Schema: -; Owner: mapas --- - -CREATE SCHEMA topology; - - -ALTER SCHEMA topology OWNER TO mapas; - --- --- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: mapas --- - -COMMENT ON SCHEMA topology IS 'PostGIS Topology schema'; - -- -- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: @@ -2489,580 +2474,580 @@ ALTER TABLE ONLY public.term_relation ALTER COLUMN id SET DEFAULT nextval('publi -- Data for Name: _mesoregiao; Type: TABLE DATA; Schema: public; Owner: mapas -- -COPY public._mesoregiao (gid, id, nm_meso, cd_geocodu, geom) FROM stdin; -\. +-- COPY public._mesoregiao (gid, id, nm_meso, cd_geocodu, geom) FROM stdin; +-- \. + + +-- -- +-- -- Data for Name: _microregiao; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public._microregiao (gid, id, nm_micro, cd_geocodu, geom) FROM stdin; +-- \. + + +-- -- +-- -- Data for Name: _municipios; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public._municipios (gid, id, cd_geocodm, nm_municip, geom) FROM stdin; +-- \. + + +-- -- +-- -- Data for Name: agent; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.agent (id, parent_id, user_id, type, name, location, _geo_location, short_description, long_description, create_timestamp, status, is_verified, public_location, update_timestamp, subsite_id) FROM stdin; +-- 1 \N 1 1 Admin@local \N \N \N \N 2019-03-07 00:00:00 1 f \N 2019-03-07 00:00:00 \N +-- \. + + +-- -- +-- -- Data for Name: agent_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.agent_meta (object_id, key, value, id) FROM stdin; +-- \. + + +-- -- +-- -- Data for Name: agent_relation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.agent_relation (id, agent_id, object_type, object_id, type, has_control, create_timestamp, status) FROM stdin; +-- \. + + +-- -- +-- -- Data for Name: db_update; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.db_update (name, exec_time) FROM stdin; +-- alter tablel term taxonomy type 2019-03-07 23:54:06.885661 +-- new random id generator 2019-03-07 23:54:06.885661 +-- migrate gender 2019-03-07 23:54:06.885661 +-- create table user apps 2019-03-07 23:54:06.885661 +-- create table user_meta 2019-03-07 23:54:06.885661 +-- create seal and seal relation tables 2019-03-07 23:54:06.885661 +-- resize entity meta key columns 2019-03-07 23:54:06.885661 +-- create registration field configuration table 2019-03-07 23:54:06.885661 +-- alter table registration_file_configuration add categories 2019-03-07 23:54:06.885661 +-- create saas tables 2019-03-07 23:54:06.885661 +-- rename saas tables to subsite 2019-03-07 23:54:06.885661 +-- remove parent_url and add alias_url 2019-03-07 23:54:06.885661 +-- verified seal migration 2019-03-07 23:54:06.885661 +-- create update timestamp entities 2019-03-07 23:54:06.885661 +-- alter table role add column subsite_id 2019-03-07 23:54:06.885661 +-- Fix field options field type from registration field configuration 2019-03-07 23:54:06.885661 +-- ADD columns subsite_id 2019-03-07 23:54:06.885661 +-- remove subsite slug column 2019-03-07 23:54:06.885661 +-- add subsite verified_seals column 2019-03-07 23:54:06.885661 +-- update entities last_update_timestamp with user last log timestamp 2019-03-07 23:54:06.885661 +-- Created owner seal relation field 2019-03-07 23:54:06.885661 +-- create table pcache 2019-03-07 23:54:06.885661 +-- function create pcache id sequence 2 2019-03-07 23:54:06.885661 +-- Add field for maximum size from registration field configuration 2019-03-07 23:54:06.885661 +-- Add notification type for compliant and suggestion messages 2019-03-07 23:54:06.885661 +-- create entity revision tables 2019-03-07 23:54:06.885661 +-- ALTER TABLE file ADD COLUMN path 2019-03-07 23:54:06.885661 +-- *_meta drop all indexes again 2019-03-07 23:54:06.885661 +-- recreate *_meta indexes 2019-03-07 23:54:06.885661 +-- create permission cache pending table2 2019-03-07 23:54:06.885661 +-- create opportunity tables 2019-03-07 23:54:06.885661 +-- DROP CONSTRAINT registration_project_fk"); 2019-03-07 23:54:06.885661 +-- fix opportunity parent FK 2019-03-07 23:54:06.885661 +-- fix opportunity type 35 2019-03-07 23:54:06.885661 +-- create opportunity sequence 2019-03-07 23:54:06.885661 +-- update opportunity_meta_id sequence 2019-03-07 23:54:06.885661 +-- rename opportunity_meta key isProjectPhase to isOpportunityPhase 2019-03-07 23:54:06.885661 +-- migrate introInscricoes value to shortDescription 2019-03-07 23:54:06.885661 +-- ALTER TABLE registration ADD consolidated_result 2019-03-07 23:54:06.885661 +-- create evaluation methods tables 2019-03-07 23:54:06.885661 +-- create registration_evaluation table 2019-03-07 23:54:06.885661 +-- ALTER TABLE opportunity ALTER type DROP NOT NULL; 2019-03-07 23:54:06.885661 +-- create seal relation renovation flag field 2019-03-07 23:54:06.885661 +-- create seal relation validate date 2019-03-07 23:54:06.885661 +-- update seal_relation set validate_date 2019-03-07 23:54:06.885661 +-- refactor of entity meta keky value indexes 2019-03-07 23:54:06.885661 +-- DROP index registration_meta_value_idx 2019-03-07 23:54:06.885661 +-- altertable registration_file_and_files_add_order 2019-03-07 23:54:06.885661 +-- replace subsite entidades_habilitadas values 2019-03-07 23:54:06.885661 +-- replace subsite cor entidades values 2019-03-07 23:54:06.885661 +-- ALTER TABLE file ADD private and update 2019-03-07 23:54:06.885661 +-- move private files 2019-03-07 23:54:06.885661 +-- create permission cache sequence 2019-03-07 23:54:06.885661 +-- create evaluation methods sequence 2019-03-07 23:54:06.885661 +-- change opportunity field agent_id not null 2019-03-07 23:54:06.885661 +-- alter table registration add column number 2019-03-07 23:54:06.885661 +-- update registrations set number fixed 2019-03-07 23:54:06.885661 +-- alter table registration add column valuers_exceptions_list 2019-03-07 23:54:06.885661 +-- update taxonomy slug tag 2019-03-07 23:54:06.885661 +-- update taxonomy slug area 2019-03-07 23:54:06.885661 +-- update taxonomy slug linguagem 2019-03-07 23:54:06.885661 +-- recreate pcache 2019-03-07 23:54:19.344941 +-- generate file path 2019-03-07 23:54:19.352266 +-- create entities history entries 2019-03-07 23:54:19.357385 +-- create entities updated revision 2019-03-07 23:54:19.362878 +-- fix update timestamp of revisioned entities 2019-03-07 23:54:19.367904 +-- consolidate registration result 2019-03-07 23:54:19.3728 +-- create avatar thumbs 2019-03-07 23:55:16.963658 +-- CREATE SEQUENCE REGISTRATION SPACE RELATION registration_space_relation_id_seq 2021-02-04 13:50:37.698794 +-- CREATE TABLE spacerelation 2021-02-04 13:50:37.698794 +-- ALTER TABLE registration 2021-02-04 13:50:37.698794 +-- create event attendance table 2021-02-04 13:50:37.698794 +-- create procuration table 2021-02-04 13:50:37.698794 +-- alter table registration_field_configuration add column config 2021-02-04 13:50:37.698794 +-- recreate ALL FKs 2021-02-04 13:50:37.698794 +-- create object_type enum type 2021-02-04 13:50:37.698794 +-- create permission_action enum type 2021-02-04 13:50:37.698794 +-- alter tables to use enum types 2021-02-04 13:50:37.698794 +-- alter table permission_cache_pending add column status 2021-02-04 13:50:37.698794 +-- CREATE VIEW evaluation 2021-02-04 13:50:37.698794 +-- valuer disabling refactor 2021-02-04 13:50:37.698794 +-- \. + + +-- -- +-- -- Data for Name: entity_revision; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.entity_revision (id, user_id, object_id, object_type, create_timestamp, action, message) FROM stdin; +-- 1 1 1 MapasCulturais\\Entities\\Agent 2019-03-07 00:00:00 created Registro criado. +-- \. + + +-- -- +-- -- Data for Name: entity_revision_data; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.entity_revision_data (id, "timestamp", key, value) FROM stdin; +-- 1 2019-03-07 23:54:19 _type 1 +-- 2 2019-03-07 23:54:19 name "Admin@local" +-- 3 2019-03-07 23:54:19 publicLocation null +-- 4 2019-03-07 23:54:19 location {"latitude":0,"longitude":0} +-- 5 2019-03-07 23:54:19 shortDescription null +-- 6 2019-03-07 23:54:19 longDescription null +-- 7 2019-03-07 23:54:19 createTimestamp {"date":"2019-03-07 00:00:00.000000","timezone_type":3,"timezone":"UTC"} +-- 8 2019-03-07 23:54:19 status 1 +-- 9 2019-03-07 23:54:19 updateTimestamp {"date":"2019-03-07 00:00:00.000000","timezone_type":3,"timezone":"UTC"} +-- 10 2019-03-07 23:54:19 _subsiteId null +-- \. + + +-- -- +-- -- Data for Name: entity_revision_revision_data; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- + +-- COPY public.entity_revision_revision_data (revision_id, revision_data_id) FROM stdin; +-- 1 1 +-- 1 2 +-- 1 3 +-- 1 4 +-- 1 5 +-- 1 6 +-- 1 7 +-- 1 8 +-- 1 9 +-- 1 10 +-- \. + + +-- -- +-- -- Data for Name: evaluation_method_configuration; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.evaluation_method_configuration (id, opportunity_id, type) FROM stdin; +-- \. --- --- Data for Name: _microregiao; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public._microregiao (gid, id, nm_micro, cd_geocodu, geom) FROM stdin; -\. +-- -- +-- -- Data for Name: evaluationmethodconfiguration_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.evaluationmethodconfiguration_meta (id, object_id, key, value) FROM stdin; +-- \. --- --- Data for Name: _municipios; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public._municipios (gid, id, cd_geocodm, nm_municip, geom) FROM stdin; -\. +-- -- +-- -- Data for Name: event; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event (id, project_id, name, short_description, long_description, rules, create_timestamp, status, agent_id, is_verified, type, update_timestamp, subsite_id) FROM stdin; +-- \. --- --- Data for Name: agent; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.agent (id, parent_id, user_id, type, name, location, _geo_location, short_description, long_description, create_timestamp, status, is_verified, public_location, update_timestamp, subsite_id) FROM stdin; -1 \N 1 1 Admin@local \N \N \N \N 2019-03-07 00:00:00 1 f \N 2019-03-07 00:00:00 \N -\. +-- -- +-- -- Data for Name: event_attendance; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event_attendance (id, user_id, event_occurrence_id, event_id, space_id, type, reccurrence_string, start_timestamp, end_timestamp, create_timestamp) FROM stdin; +-- \. --- --- Data for Name: agent_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.agent_meta (object_id, key, value, id) FROM stdin; -\. +-- -- +-- -- Data for Name: event_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event_meta (key, object_id, value, id) FROM stdin; +-- \. --- --- Data for Name: agent_relation; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.agent_relation (id, agent_id, object_type, object_id, type, has_control, create_timestamp, status) FROM stdin; -\. +-- -- +-- -- Data for Name: event_occurrence; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event_occurrence (id, space_id, event_id, rule, starts_on, ends_on, starts_at, ends_at, frequency, separation, count, until, timezone_name, status) FROM stdin; +-- \. --- --- Data for Name: db_update; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.db_update (name, exec_time) FROM stdin; -alter tablel term taxonomy type 2019-03-07 23:54:06.885661 -new random id generator 2019-03-07 23:54:06.885661 -migrate gender 2019-03-07 23:54:06.885661 -create table user apps 2019-03-07 23:54:06.885661 -create table user_meta 2019-03-07 23:54:06.885661 -create seal and seal relation tables 2019-03-07 23:54:06.885661 -resize entity meta key columns 2019-03-07 23:54:06.885661 -create registration field configuration table 2019-03-07 23:54:06.885661 -alter table registration_file_configuration add categories 2019-03-07 23:54:06.885661 -create saas tables 2019-03-07 23:54:06.885661 -rename saas tables to subsite 2019-03-07 23:54:06.885661 -remove parent_url and add alias_url 2019-03-07 23:54:06.885661 -verified seal migration 2019-03-07 23:54:06.885661 -create update timestamp entities 2019-03-07 23:54:06.885661 -alter table role add column subsite_id 2019-03-07 23:54:06.885661 -Fix field options field type from registration field configuration 2019-03-07 23:54:06.885661 -ADD columns subsite_id 2019-03-07 23:54:06.885661 -remove subsite slug column 2019-03-07 23:54:06.885661 -add subsite verified_seals column 2019-03-07 23:54:06.885661 -update entities last_update_timestamp with user last log timestamp 2019-03-07 23:54:06.885661 -Created owner seal relation field 2019-03-07 23:54:06.885661 -create table pcache 2019-03-07 23:54:06.885661 -function create pcache id sequence 2 2019-03-07 23:54:06.885661 -Add field for maximum size from registration field configuration 2019-03-07 23:54:06.885661 -Add notification type for compliant and suggestion messages 2019-03-07 23:54:06.885661 -create entity revision tables 2019-03-07 23:54:06.885661 -ALTER TABLE file ADD COLUMN path 2019-03-07 23:54:06.885661 -*_meta drop all indexes again 2019-03-07 23:54:06.885661 -recreate *_meta indexes 2019-03-07 23:54:06.885661 -create permission cache pending table2 2019-03-07 23:54:06.885661 -create opportunity tables 2019-03-07 23:54:06.885661 -DROP CONSTRAINT registration_project_fk"); 2019-03-07 23:54:06.885661 -fix opportunity parent FK 2019-03-07 23:54:06.885661 -fix opportunity type 35 2019-03-07 23:54:06.885661 -create opportunity sequence 2019-03-07 23:54:06.885661 -update opportunity_meta_id sequence 2019-03-07 23:54:06.885661 -rename opportunity_meta key isProjectPhase to isOpportunityPhase 2019-03-07 23:54:06.885661 -migrate introInscricoes value to shortDescription 2019-03-07 23:54:06.885661 -ALTER TABLE registration ADD consolidated_result 2019-03-07 23:54:06.885661 -create evaluation methods tables 2019-03-07 23:54:06.885661 -create registration_evaluation table 2019-03-07 23:54:06.885661 -ALTER TABLE opportunity ALTER type DROP NOT NULL; 2019-03-07 23:54:06.885661 -create seal relation renovation flag field 2019-03-07 23:54:06.885661 -create seal relation validate date 2019-03-07 23:54:06.885661 -update seal_relation set validate_date 2019-03-07 23:54:06.885661 -refactor of entity meta keky value indexes 2019-03-07 23:54:06.885661 -DROP index registration_meta_value_idx 2019-03-07 23:54:06.885661 -altertable registration_file_and_files_add_order 2019-03-07 23:54:06.885661 -replace subsite entidades_habilitadas values 2019-03-07 23:54:06.885661 -replace subsite cor entidades values 2019-03-07 23:54:06.885661 -ALTER TABLE file ADD private and update 2019-03-07 23:54:06.885661 -move private files 2019-03-07 23:54:06.885661 -create permission cache sequence 2019-03-07 23:54:06.885661 -create evaluation methods sequence 2019-03-07 23:54:06.885661 -change opportunity field agent_id not null 2019-03-07 23:54:06.885661 -alter table registration add column number 2019-03-07 23:54:06.885661 -update registrations set number fixed 2019-03-07 23:54:06.885661 -alter table registration add column valuers_exceptions_list 2019-03-07 23:54:06.885661 -update taxonomy slug tag 2019-03-07 23:54:06.885661 -update taxonomy slug area 2019-03-07 23:54:06.885661 -update taxonomy slug linguagem 2019-03-07 23:54:06.885661 -recreate pcache 2019-03-07 23:54:19.344941 -generate file path 2019-03-07 23:54:19.352266 -create entities history entries 2019-03-07 23:54:19.357385 -create entities updated revision 2019-03-07 23:54:19.362878 -fix update timestamp of revisioned entities 2019-03-07 23:54:19.367904 -consolidate registration result 2019-03-07 23:54:19.3728 -create avatar thumbs 2019-03-07 23:55:16.963658 -CREATE SEQUENCE REGISTRATION SPACE RELATION registration_space_relation_id_seq 2021-02-04 13:50:37.698794 -CREATE TABLE spacerelation 2021-02-04 13:50:37.698794 -ALTER TABLE registration 2021-02-04 13:50:37.698794 -create event attendance table 2021-02-04 13:50:37.698794 -create procuration table 2021-02-04 13:50:37.698794 -alter table registration_field_configuration add column config 2021-02-04 13:50:37.698794 -recreate ALL FKs 2021-02-04 13:50:37.698794 -create object_type enum type 2021-02-04 13:50:37.698794 -create permission_action enum type 2021-02-04 13:50:37.698794 -alter tables to use enum types 2021-02-04 13:50:37.698794 -alter table permission_cache_pending add column status 2021-02-04 13:50:37.698794 -CREATE VIEW evaluation 2021-02-04 13:50:37.698794 -valuer disabling refactor 2021-02-04 13:50:37.698794 -\. +-- -- +-- -- Data for Name: event_occurrence_cancellation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event_occurrence_cancellation (id, event_occurrence_id, date) FROM stdin; +-- \. --- --- Data for Name: entity_revision; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.entity_revision (id, user_id, object_id, object_type, create_timestamp, action, message) FROM stdin; -1 1 1 MapasCulturais\\Entities\\Agent 2019-03-07 00:00:00 created Registro criado. -\. +-- -- +-- -- Data for Name: event_occurrence_recurrence; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.event_occurrence_recurrence (id, event_occurrence_id, month, day, week) FROM stdin; +-- \. --- --- Data for Name: entity_revision_data; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.entity_revision_data (id, "timestamp", key, value) FROM stdin; -1 2019-03-07 23:54:19 _type 1 -2 2019-03-07 23:54:19 name "Admin@local" -3 2019-03-07 23:54:19 publicLocation null -4 2019-03-07 23:54:19 location {"latitude":0,"longitude":0} -5 2019-03-07 23:54:19 shortDescription null -6 2019-03-07 23:54:19 longDescription null -7 2019-03-07 23:54:19 createTimestamp {"date":"2019-03-07 00:00:00.000000","timezone_type":3,"timezone":"UTC"} -8 2019-03-07 23:54:19 status 1 -9 2019-03-07 23:54:19 updateTimestamp {"date":"2019-03-07 00:00:00.000000","timezone_type":3,"timezone":"UTC"} -10 2019-03-07 23:54:19 _subsiteId null -\. +-- -- +-- -- Data for Name: file; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.file (id, md5, mime_type, name, object_type, object_id, create_timestamp, grp, description, parent_id, path, private) FROM stdin; +-- \. --- --- Data for Name: entity_revision_revision_data; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.entity_revision_revision_data (revision_id, revision_data_id) FROM stdin; -1 1 -1 2 -1 3 -1 4 -1 5 -1 6 -1 7 -1 8 -1 9 -1 10 -\. +-- -- +-- -- Data for Name: geo_division; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.geo_division (id, parent_id, type, cod, name, geom) FROM stdin; +-- \. --- --- Data for Name: evaluation_method_configuration; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.evaluation_method_configuration (id, opportunity_id, type) FROM stdin; -\. +-- -- +-- -- Data for Name: metadata; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.metadata (object_id, object_type, key, value) FROM stdin; +-- \. --- --- Data for Name: evaluationmethodconfiguration_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.evaluationmethodconfiguration_meta (id, object_id, key, value) FROM stdin; -\. +-- -- +-- -- Data for Name: metalist; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.metalist (id, object_type, object_id, grp, title, description, value, create_timestamp, "order") FROM stdin; +-- \. --- --- Data for Name: event; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event (id, project_id, name, short_description, long_description, rules, create_timestamp, status, agent_id, is_verified, type, update_timestamp, subsite_id) FROM stdin; -\. +-- -- +-- -- Data for Name: notification; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.notification (id, user_id, request_id, message, create_timestamp, action_timestamp, status) FROM stdin; +-- \. --- --- Data for Name: event_attendance; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event_attendance (id, user_id, event_occurrence_id, event_id, space_id, type, reccurrence_string, start_timestamp, end_timestamp, create_timestamp) FROM stdin; -\. +-- -- +-- -- Data for Name: notification_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.notification_meta (id, object_id, key, value) FROM stdin; +-- \. --- --- Data for Name: event_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event_meta (key, object_id, value, id) FROM stdin; -\. +-- -- +-- -- Data for Name: opportunity; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.opportunity (id, parent_id, agent_id, type, name, short_description, long_description, registration_from, registration_to, published_registrations, registration_categories, create_timestamp, update_timestamp, status, subsite_id, object_type, object_id) FROM stdin; +-- \. --- --- Data for Name: event_occurrence; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event_occurrence (id, space_id, event_id, rule, starts_on, ends_on, starts_at, ends_at, frequency, separation, count, until, timezone_name, status) FROM stdin; -\. +-- -- +-- -- Data for Name: opportunity_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.opportunity_meta (id, object_id, key, value) FROM stdin; +-- \. --- --- Data for Name: event_occurrence_cancellation; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event_occurrence_cancellation (id, event_occurrence_id, date) FROM stdin; -\. +-- -- +-- -- Data for Name: pcache; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.pcache (id, user_id, action, create_timestamp, object_type, object_id) FROM stdin; +-- \. --- --- Data for Name: event_occurrence_recurrence; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.event_occurrence_recurrence (id, event_occurrence_id, month, day, week) FROM stdin; -\. +-- -- +-- -- Data for Name: permission_cache_pending; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.permission_cache_pending (id, object_id, object_type, status) FROM stdin; +-- \. --- --- Data for Name: file; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.file (id, md5, mime_type, name, object_type, object_id, create_timestamp, grp, description, parent_id, path, private) FROM stdin; -\. +-- -- +-- -- Data for Name: procuration; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.procuration (token, usr_id, attorney_user_id, action, create_timestamp, valid_until_timestamp) FROM stdin; +-- \. --- --- Data for Name: geo_division; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.geo_division (id, parent_id, type, cod, name, geom) FROM stdin; -\. +-- -- +-- -- Data for Name: project; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.project (id, name, short_description, long_description, create_timestamp, status, agent_id, is_verified, type, parent_id, registration_from, registration_to, update_timestamp, subsite_id) FROM stdin; +-- \. --- --- Data for Name: metadata; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.metadata (object_id, object_type, key, value) FROM stdin; -\. +-- -- +-- -- Data for Name: project_event; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.project_event (id, event_id, project_id, type, status) FROM stdin; +-- \. --- --- Data for Name: metalist; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.metalist (id, object_type, object_id, grp, title, description, value, create_timestamp, "order") FROM stdin; -\. +-- -- +-- -- Data for Name: project_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.project_meta (object_id, key, value, id) FROM stdin; +-- \. --- --- Data for Name: notification; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.notification (id, user_id, request_id, message, create_timestamp, action_timestamp, status) FROM stdin; -\. +-- -- +-- -- Data for Name: registration; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.registration (id, opportunity_id, category, agent_id, create_timestamp, sent_timestamp, status, agents_data, subsite_id, consolidated_result, number, valuers_exceptions_list, space_data) FROM stdin; +-- \. --- --- Data for Name: notification_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.notification_meta (id, object_id, key, value) FROM stdin; -\. +-- -- +-- -- Data for Name: registration_evaluation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.registration_evaluation (id, registration_id, user_id, result, evaluation_data, status) FROM stdin; +-- \. --- --- Data for Name: opportunity; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.opportunity (id, parent_id, agent_id, type, name, short_description, long_description, registration_from, registration_to, published_registrations, registration_categories, create_timestamp, update_timestamp, status, subsite_id, object_type, object_id) FROM stdin; -\. +-- -- +-- -- Data for Name: registration_field_configuration; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.registration_field_configuration (id, opportunity_id, title, description, categories, required, field_type, field_options, max_size, display_order, config) FROM stdin; +-- \. --- --- Data for Name: opportunity_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.opportunity_meta (id, object_id, key, value) FROM stdin; -\. +-- -- +-- -- Data for Name: registration_file_configuration; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.registration_file_configuration (id, opportunity_id, title, description, required, categories, display_order) FROM stdin; +-- \. --- --- Data for Name: pcache; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.pcache (id, user_id, action, create_timestamp, object_type, object_id) FROM stdin; -\. +-- -- +-- -- Data for Name: registration_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.registration_meta (object_id, key, value, id) FROM stdin; +-- \. --- --- Data for Name: permission_cache_pending; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.permission_cache_pending (id, object_id, object_type, status) FROM stdin; -\. +-- -- +-- -- Data for Name: request; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.request (id, request_uid, requester_user_id, origin_type, origin_id, destination_type, destination_id, metadata, type, create_timestamp, action_timestamp, status) FROM stdin; +-- \. --- --- Data for Name: procuration; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.procuration (token, usr_id, attorney_user_id, action, create_timestamp, valid_until_timestamp) FROM stdin; -\. +-- -- +-- -- Data for Name: role; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.role (id, usr_id, name, subsite_id) FROM stdin; +-- 2 1 saasSuperAdmin \N +-- \. --- --- Data for Name: project; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.project (id, name, short_description, long_description, create_timestamp, status, agent_id, is_verified, type, parent_id, registration_from, registration_to, update_timestamp, subsite_id) FROM stdin; -\. +-- -- +-- -- Data for Name: seal; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.seal (id, agent_id, name, short_description, long_description, valid_period, create_timestamp, status, certificate_text, update_timestamp, subsite_id) FROM stdin; +-- 1 1 Selo Mapas Descrição curta Selo Mapas Descrição longa Selo Mapas 0 2019-03-07 23:54:04 1 \N 2019-03-07 00:00:00 \N +-- \. --- --- Data for Name: project_event; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.project_event (id, event_id, project_id, type, status) FROM stdin; -\. +-- -- +-- -- Data for Name: seal_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.seal_meta (id, object_id, key, value) FROM stdin; +-- \. --- --- Data for Name: project_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.project_meta (object_id, key, value, id) FROM stdin; -\. +-- -- +-- -- Data for Name: seal_relation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.seal_relation (id, seal_id, object_id, create_timestamp, status, object_type, agent_id, owner_id, validate_date, renovation_request) FROM stdin; +-- \. --- --- Data for Name: registration; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.registration (id, opportunity_id, category, agent_id, create_timestamp, sent_timestamp, status, agents_data, subsite_id, consolidated_result, number, valuers_exceptions_list, space_data) FROM stdin; -\. +-- -- +-- -- Data for Name: space; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.space (id, parent_id, location, _geo_location, name, short_description, long_description, create_timestamp, status, type, agent_id, is_verified, public, update_timestamp, subsite_id) FROM stdin; +-- \. --- --- Data for Name: registration_evaluation; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.registration_evaluation (id, registration_id, user_id, result, evaluation_data, status) FROM stdin; -\. +-- -- +-- -- Data for Name: space_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- +-- COPY public.space_meta (object_id, key, value, id) FROM stdin; +-- \. --- --- Data for Name: registration_field_configuration; Type: TABLE DATA; Schema: public; Owner: mapas --- -COPY public.registration_field_configuration (id, opportunity_id, title, description, categories, required, field_type, field_options, max_size, display_order, config) FROM stdin; -\. +-- -- +-- -- Data for Name: space_relation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- - --- --- Data for Name: registration_file_configuration; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.registration_file_configuration (id, opportunity_id, title, description, required, categories, display_order) FROM stdin; -\. - - --- --- Data for Name: registration_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.registration_meta (object_id, key, value, id) FROM stdin; -\. - - --- --- Data for Name: request; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.request (id, request_uid, requester_user_id, origin_type, origin_id, destination_type, destination_id, metadata, type, create_timestamp, action_timestamp, status) FROM stdin; -\. - - --- --- Data for Name: role; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.role (id, usr_id, name, subsite_id) FROM stdin; -2 1 saasSuperAdmin \N -\. - - --- --- Data for Name: seal; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.seal (id, agent_id, name, short_description, long_description, valid_period, create_timestamp, status, certificate_text, update_timestamp, subsite_id) FROM stdin; -1 1 Selo Mapas Descrição curta Selo Mapas Descrição longa Selo Mapas 0 2019-03-07 23:54:04 1 \N 2019-03-07 00:00:00 \N -\. - - --- --- Data for Name: seal_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.seal_meta (id, object_id, key, value) FROM stdin; -\. - - --- --- Data for Name: seal_relation; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.seal_relation (id, seal_id, object_id, create_timestamp, status, object_type, agent_id, owner_id, validate_date, renovation_request) FROM stdin; -\. - - --- --- Data for Name: space; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.space (id, parent_id, location, _geo_location, name, short_description, long_description, create_timestamp, status, type, agent_id, is_verified, public, update_timestamp, subsite_id) FROM stdin; -\. +-- COPY public.space_relation (id, space_id, object_id, create_timestamp, status, object_type) FROM stdin; +-- \. --- --- Data for Name: space_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: spatial_ref_sys; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.space_meta (object_id, key, value, id) FROM stdin; -\. +-- COPY public.spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) FROM stdin; +-- \. --- --- Data for Name: space_relation; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: subsite; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.space_relation (id, space_id, object_id, create_timestamp, status, object_type) FROM stdin; -\. +-- COPY public.subsite (id, name, create_timestamp, status, agent_id, url, namespace, alias_url, verified_seals) FROM stdin; +-- \. --- --- Data for Name: spatial_ref_sys; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: subsite_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) FROM stdin; -\. +-- COPY public.subsite_meta (object_id, key, value, id) FROM stdin; +-- \. --- --- Data for Name: subsite; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: term; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.subsite (id, name, create_timestamp, status, agent_id, url, namespace, alias_url, verified_seals) FROM stdin; -\. +-- COPY public.term (id, taxonomy, term, description) FROM stdin; +-- \. --- --- Data for Name: subsite_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.subsite_meta (object_id, key, value, id) FROM stdin; -\. - - --- --- Data for Name: term; Type: TABLE DATA; Schema: public; Owner: mapas --- - -COPY public.term (id, taxonomy, term, description) FROM stdin; -\. - - --- --- Data for Name: term_relation; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: term_relation; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.term_relation (term_id, object_type, object_id, id) FROM stdin; -\. +-- COPY public.term_relation (term_id, object_type, object_id, id) FROM stdin; +-- \. --- --- Data for Name: user_app; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: user_app; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.user_app (public_key, private_key, user_id, name, status, create_timestamp, subsite_id) FROM stdin; -\. +-- COPY public.user_app (public_key, private_key, user_id, name, status, create_timestamp, subsite_id) FROM stdin; +-- \. --- --- Data for Name: user_meta; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: user_meta; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.user_meta (object_id, key, value, id) FROM stdin; -1 deleteAccountToken 54cd760dfca39f8e8c8332d7499bdb44f921dc16 1 -1 localAuthenticationPassword $2y$10$iIXeqhX.4fEAAVZPsbtRde7CFw1ChduCi8NsnXGnJc6TlelY6gf3e 2 -\. +-- COPY public.user_meta (object_id, key, value, id) FROM stdin; +-- 1 deleteAccountToken 54cd760dfca39f8e8c8332d7499bdb44f921dc16 1 +-- 1 localAuthenticationPassword $2y$10$iIXeqhX.4fEAAVZPsbtRde7CFw1ChduCi8NsnXGnJc6TlelY6gf3e 2 +-- \. --- --- Data for Name: usr; Type: TABLE DATA; Schema: public; Owner: mapas --- +-- -- +-- -- Data for Name: usr; Type: TABLE DATA; Schema: public; Owner: mapas +-- -- -COPY public.usr (id, auth_provider, auth_uid, email, last_login_timestamp, create_timestamp, status, profile_id) FROM stdin; -1 1 1 Admin@local 2019-03-08 19:03:34 2019-03-07 00:00:00 1 1 -\. +-- COPY public.usr (id, auth_provider, auth_uid, email, last_login_timestamp, create_timestamp, status, profile_id) FROM stdin; +-- 1 1 1 Admin@local 2019-03-08 19:03:34 2019-03-07 00:00:00 1 1 +-- \. --- --- Data for Name: geocode_settings; Type: TABLE DATA; Schema: tiger; Owner: mapas --- +-- -- +-- -- Data for Name: geocode_settings; Type: TABLE DATA; Schema: tiger; Owner: mapas +-- -- -COPY tiger.geocode_settings (name, setting, unit, category, short_desc) FROM stdin; -\. +-- COPY tiger.geocode_settings (name, setting, unit, category, short_desc) FROM stdin; +-- \. --- --- Data for Name: pagc_gaz; Type: TABLE DATA; Schema: tiger; Owner: mapas --- +-- -- +-- -- Data for Name: pagc_gaz; Type: TABLE DATA; Schema: tiger; Owner: mapas +-- -- -COPY tiger.pagc_gaz (id, seq, word, stdword, token, is_custom) FROM stdin; -\. +-- COPY tiger.pagc_gaz (id, seq, word, stdword, token, is_custom) FROM stdin; +-- \. --- --- Data for Name: pagc_lex; Type: TABLE DATA; Schema: tiger; Owner: mapas --- +-- -- +-- -- Data for Name: pagc_lex; Type: TABLE DATA; Schema: tiger; Owner: mapas +-- -- -COPY tiger.pagc_lex (id, seq, word, stdword, token, is_custom) FROM stdin; -\. +-- COPY tiger.pagc_lex (id, seq, word, stdword, token, is_custom) FROM stdin; +-- \. --- --- Data for Name: pagc_rules; Type: TABLE DATA; Schema: tiger; Owner: mapas --- +-- -- +-- -- Data for Name: pagc_rules; Type: TABLE DATA; Schema: tiger; Owner: mapas +-- -- -COPY tiger.pagc_rules (id, rule, is_custom) FROM stdin; -\. +-- COPY tiger.pagc_rules (id, rule, is_custom) FROM stdin; +-- \. --- --- Data for Name: topology; Type: TABLE DATA; Schema: topology; Owner: mapas --- +-- -- +-- -- Data for Name: topology; Type: TABLE DATA; Schema: topology; Owner: mapas +-- -- -COPY topology.topology (id, name, srid, "precision", hasz) FROM stdin; -\. +-- COPY topology.topology (id, name, srid, "precision", hasz) FROM stdin; +-- \. --- --- Data for Name: layer; Type: TABLE DATA; Schema: topology; Owner: mapas --- +-- -- +-- -- Data for Name: layer; Type: TABLE DATA; Schema: topology; Owner: mapas +-- -- -COPY topology.layer (topology_id, layer_id, schema_name, table_name, feature_column, feature_type, level, child_id) FROM stdin; -\. +-- COPY topology.layer (topology_id, layer_id, schema_name, table_name, feature_column, feature_type, level, child_id) FROM stdin; +-- \. -- diff --git a/api/mapas/src/core/App.php b/api/mapas/src/core/App.php index a945563e9b..4a587b3c8b 100644 --- a/api/mapas/src/core/App.php +++ b/api/mapas/src/core/App.php @@ -438,13 +438,60 @@ function init(array $config) { $this->_initStorage(); - if(defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) + if (defined('DB_UPDATES_FILE') && file_exists(DB_UPDATES_FILE)) { + $this->_firstDbUpdate(); $this->_dbUpdates(); + } $this->applyHookBoundTo($this, 'app.init:after'); return $this; } + function _firstDbUpdate() + { + try { + // Conectar ao banco de dados usando Doctrine DBAL + $connection = $this->em->getConnection(); + + // Verificar a existência da tabela system_role + $schemaManager = $connection->createSchemaManager(); + $tables = $schemaManager->listTableNames(); + + if (in_array('system_role', $tables)) { + echo 'A tabela "system_role" já existe. Nenhuma ação necessária.'; + } else { + // Ler o arquivo SQL + $sqlFile = PROTECTED_PATH . 'dev/db/dump.sql'; + $sql = file_get_contents($sqlFile); + + if ($sql === false) { + throw new Exception("Erro ao ler o arquivo SQL."); + } + + // Filtrar linhas específicas do psql + // $sqlLines = explode("\n", $sql); + // $filteredSqlLines = array_filter($sqlLines, function ($line) { + // // Remover linhas que começam com '\' + // return !preg_match('/^\\\/', trim($line)); + // }); + + // $filteredSql = implode("\n", $filteredSqlLines); + + // Registrar SQL filtrado para depuração + // file_put_contents('filtered_sql.sql', $filteredSql); + + // Dividir o SQL por ';' para assegurar a execução correta de múltiplas queries + $connection->executeStatement($sql); + echo 'Arquivo SQL executado com sucesso.'; + } + } catch (Exception $e) { + // Reverter a transação em caso de erro + if (isset($connection) && $connection->isTransactionActive()) { + $connection->rollBack(); + } + echo 'Erro ao executar o arquivo SQL: ' . $e->getMessage(); + } + } /** * Executa a aplicação * diff --git a/api/mapas/src/db-updates.php b/api/mapas/src/db-updates.php index dbf948eb80..e4ae5e2e75 100644 --- a/api/mapas/src/db-updates.php +++ b/api/mapas/src/db-updates.php @@ -1,4 +1,5 @@ getConnection(); -function __table_exists($table_name) { +function __table_exists($table_name) +{ $app = App::i(); $em = $app->em; $conn = $em->getConnection(); - if($conn->fetchAll("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '$table_name';")){ + if ($conn->fetchAll("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '$table_name';")) { return true; } else { return false; } } -function __sequence_exists($sequence_name) { +function __sequence_exists($sequence_name) +{ $app = App::i(); $em = $app->em; $conn = $em->getConnection(); - if($conn->fetchAll("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = '$sequence_name';")){ + if ($conn->fetchAll("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = 'public' AND sequence_name = '$sequence_name';")) { return true; } else { return false; } } -function __column_exists($table_name, $column_name) { +function __column_exists($table_name, $column_name) +{ $app = App::i(); $em = $app->em; $conn = $em->getConnection(); - if($conn->fetchAll("SELECT column_name FROM information_schema.columns WHERE table_name='$table_name' and column_name='$column_name'")){ + if ($conn->fetchAll("SELECT column_name FROM information_schema.columns WHERE table_name='$table_name' and column_name='$column_name'")) { return true; } else { return false; } } -function __exec($sql){ +function __exec($sql) +{ $app = App::i(); $em = $app->em; $conn = $em->getConnection(); - try{ + try { $conn->executeQuery($sql); } catch (Exception $ex) { echo " @@ -59,11 +64,12 @@ function __exec($sql){ } } -function __try($sql, $cb = null){ - try{ +function __try($sql, $cb = null) +{ + try { __exec($sql); } catch (\Exception $ex) { - if($cb){ + if ($cb) { $cb($ex, $sql); } else { $msg = $ex->getMessage(); @@ -82,19 +88,19 @@ function __try($sql, $cb = null){ $updates = []; $registered_taxonomies = $this->_register['taxonomies']['by-id']; -foreach($registered_taxonomies as $def){ - $updates['update taxonomy slug ' . $def->slug] = function() use( $conn, $def ) { +foreach ($registered_taxonomies as $def) { + $updates['update taxonomy slug ' . $def->slug] = function () use ($conn, $def) { $conn->executeQuery("UPDATE term SET taxonomy = '{$def->slug}' WHERE taxonomy = '{$def->id}'"); }; } return [ - 'UPDATING ENUM TYPES' => function() use($conn) { + 'UPDATING ENUM TYPES' => function () use ($conn) { $reg = \Acelaya\Doctrine\Type\PhpEnumType::getTypeRegistry(); - - foreach ($reg->getMap() as $enum_type => $type){ - if(get_class($type) == 'Acelaya\Doctrine\Type\PhpEnumType') { + + foreach ($reg->getMap() as $enum_type => $type) { + if (get_class($type) == 'Acelaya\Doctrine\Type\PhpEnumType') { $values = $conn->fetchAll(" SELECT e.enumlabel AS value FROM pg_type t @@ -102,15 +108,17 @@ function __try($sql, $cb = null){ JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE t.typname = '{$enum_type}'"); - $actual_values = array_map(function($item) { return $item['value']; }, $values); - + $actual_values = array_map(function ($item) { + return $item['value']; + }, $values); + $reflection = new \ReflectionObject($type); $property = $reflection->getProperty('enumClass'); - $property->setAccessible (true); + $property->setAccessible(true); $class = $property->getValue($type); - - foreach($class::toArray() as $value){ - if(!in_array($value, $actual_values)) { + + foreach ($class::toArray() as $value) { + if (!in_array($value, $actual_values)) { echo "\n- ALTER TYPE {$enum_type} ADD VALUE '$value'\n"; __exec("ALTER TYPE {$enum_type} ADD VALUE '$value'"); } @@ -121,7 +129,7 @@ function __try($sql, $cb = null){ return false; }, - 'alter tablel term taxonomy type' => function() use ($conn) { + 'alter tablel term taxonomy type' => function () use ($conn) { $conn->executeQuery("ALTER TABLE term ALTER taxonomy TYPE VARCHAR(64);"); $conn->executeQuery("ALTER TABLE term ALTER taxonomy DROP DEFAULT;"); }, @@ -179,27 +187,27 @@ function __try($sql, $cb = null){ __exec("COMMENT ON COLUMN system_role.permissions IS '(DC2Type:json)';"); }, - "Cria colunas proponent_type e registration na tabela registration" => function() use ($conn){ - if(!__column_exists('registration', 'proponent_type')) { + "Cria colunas proponent_type e registration na tabela registration" => function () use ($conn) { + if (!__column_exists('registration', 'proponent_type')) { __exec("ALTER TABLE registration ADD COLUMN proponent_type VARCHAR(255) NULL"); } - if(!__column_exists('registration', 'range')) { + if (!__column_exists('registration', 'range')) { __exec("ALTER TABLE registration ADD COLUMN range VARCHAR(255) NULL"); } }, - 'migrate gender' => function() use ($conn) { + 'migrate gender' => function () use ($conn) { $conn->executeQuery("UPDATE agent_meta SET value='Homem' WHERE key='genero' AND value='Masculino'"); $conn->executeQuery("UPDATE agent_meta SET value='Mulher' WHERE key='genero' AND value='Feminino'"); }, - 'remove orphan events again' => function() use($conn){ + 'remove orphan events again' => function () use ($conn) { $conn->executeQuery("DELETE FROM event_meta WHERE object_id IN (SELECT id FROM event WHERE agent_id IS NULL)"); $conn->executeQuery("DELETE FROM event WHERE agent_id IS NULL"); }, - 'remove circular references again... ;)' => function() use ($conn) { + 'remove circular references again... ;)' => function () use ($conn) { $conn->executeQuery("UPDATE agent SET parent_id = null WHERE id = parent_id"); $conn->executeQuery("UPDATE agent SET parent_id = null WHERE id IN (SELECT profile_id FROM usr)"); @@ -207,8 +215,8 @@ function __try($sql, $cb = null){ return false; // executa todas as vezes só para garantir... }, - 'create table user apps' => function() use ($conn) { - if(__table_exists('user_app')){ + 'create table user apps' => function () use ($conn) { + if (__table_exists('user_app')) { echo "TABLE user_app ALREADY EXISTS"; return true; } @@ -225,13 +233,12 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE ONLY user_app ADD CONSTRAINT user_app_pk PRIMARY KEY (public_key);"); $conn->executeQuery("ALTER TABLE ONLY user_app ADD CONSTRAINT usr_user_app_fk FOREIGN KEY (user_id) REFERENCES usr(id);"); - }, - 'create table user_meta' => function() use ($conn) { + 'create table user_meta' => function () use ($conn) { - if(__table_exists('user_meta')){ + if (__table_exists('user_meta')) { echo "TABLE user_meta ALREADY EXISTS"; return true; } @@ -257,9 +264,9 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE ONLY user_meta ADD CONSTRAINT usr_user_meta_fk FOREIGN KEY (object_id) REFERENCES usr(id);"); }, - 'create seal and seal relation tables' => function() use ($conn) { + 'create seal and seal relation tables' => function () use ($conn) { - if(__table_exists('seal')){ + if (__table_exists('seal')) { echo "TABLE seal ALREADY EXISTS"; return true; } @@ -273,10 +280,9 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE seal ADD CONSTRAINT seal_fk FOREIGN KEY (agent_id) REFERENCES agent (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("ALTER TABLE seal_meta ADD CONSTRAINT seal_meta_fk FOREIGN KEY (object_id) REFERENCES seal (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("ALTER TABLE ONLY seal_relation ADD CONSTRAINT seal_relation_fk FOREIGN KEY (seal_id) REFERENCES seal(id);"); - }, - 'resize entity meta key columns' => function() use($conn) { + 'resize entity meta key columns' => function () use ($conn) { $conn->executeQuery('ALTER TABLE space_meta ALTER COLUMN key TYPE varchar(128)'); $conn->executeQuery('ALTER TABLE agent_meta ALTER COLUMN key TYPE varchar(128)'); $conn->executeQuery('ALTER TABLE event_meta ALTER COLUMN key TYPE varchar(128)'); @@ -285,8 +291,8 @@ function __try($sql, $cb = null){ }, - 'create registration field configuration table' => function () use($conn){ - if(__table_exists('registration_field_configuration')){ + 'create registration field configuration table' => function () use ($conn) { + if (__table_exists('registration_field_configuration')) { echo "TABLE registration_field_configuration ALREADY EXISTS"; return true; } @@ -297,8 +303,8 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE registration_field_configuration ADD CONSTRAINT FK_60C85CB1166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); }, - 'alter table registration_file_configuration add categories' => function () use($conn){ - if(__column_exists('registration_file_configuration', 'categories')){ + 'alter table registration_file_configuration add categories' => function () use ($conn) { + if (__column_exists('registration_file_configuration', 'categories')) { echo "ALREADY APPLIED"; return true; } @@ -312,8 +318,8 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE registration_file_configuration ADD CONSTRAINT FK_209C792E166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); }, - 'create saas tables' => function () use($conn) { - if(__table_exists('saas')){ + 'create saas tables' => function () use ($conn) { + if (__table_exists('saas')) { return true; } $conn->executeQuery("CREATE TABLE saas (id INT NOT NULL, name VARCHAR(255) NOT NULL, create_timestamp TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, status SMALLINT NOT NULL, agent_id INTEGER NOT NULL, PRIMARY KEY(id), url VARCHAR(255) NOT NULL, url_parent VARCHAR(255), slug VARCHAR(50) NOT NULL, namespace VARCHAR(50) NOT NULL);"); @@ -323,8 +329,8 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE ONLY saas_meta ADD CONSTRAINT saas_saas_meta_fk FOREIGN KEY (object_id) REFERENCES saas(id);"); }, - 'rename saas tables to subsite' => function () use($conn) { - if(__table_exists('subsite')){ + 'rename saas tables to subsite' => function () use ($conn) { + if (__table_exists('subsite')) { return true; } $conn->executeQuery("ALTER TABLE saas RENAME TO subsite"); @@ -333,8 +339,8 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER SEQUENCE saas_meta_id_seq RENAME TO subsite_meta_id_seq"); }, - 'remove parent_url and add alias_url' => function () use($conn) { - if(__column_exists('subsite', 'alias_url')){ + 'remove parent_url and add alias_url' => function () use ($conn) { + if (__column_exists('subsite', 'alias_url')) { return true; } $conn->executeQuery("ALTER TABLE subsite DROP COLUMN url_parent"); @@ -342,12 +348,11 @@ function __try($sql, $cb = null){ $conn->executeQuery("CREATE INDEX url_index ON subsite (url);"); $conn->executeQuery("CREATE INDEX alias_url_index ON subsite (alias_url);"); - }, - 'verified seal migration' => function () use($conn){ - if($id = $conn->fetchScalar("SELECT id FROM seal WHERE id = 1")){ + 'verified seal migration' => function () use ($conn) { + if ($id = $conn->fetchScalar("SELECT id FROM seal WHERE id = 1")) { return true; } $agent_id = $conn->fetchScalar("select profile_id @@ -357,7 +362,7 @@ function __try($sql, $cb = null){ from role where name = 'superAdmin' )"); - $conn->executeQuery( + $conn->executeQuery( "INSERT INTO seal VALUES( 1, $agent_id, @@ -365,50 +370,49 @@ function __try($sql, $cb = null){ 'Descrição curta Selo Mapas','Descrição longa Selo Mapas',0,CURRENT_TIMESTAMP,1 );" ); - $conn->executeQuery("INSERT INTO seal_relation + $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Agent', $agent_id FROM agent WHERE is_verified = 't';"); - $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Space', $agent_id FROM space WHERE is_verified = 't';"); - $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Project', $agent_id FROM project WHERE is_verified = 't';"); - $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Event', $agent_id FROM event WHERE is_verified = 't';"); + $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Space', $agent_id FROM space WHERE is_verified = 't';"); + $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Project', $agent_id FROM project WHERE is_verified = 't';"); + $conn->executeQuery("INSERT INTO seal_relation SELECT nextval('seal_relation_id_seq'), 1, id, CURRENT_TIMESTAMP, 1, 'MapasCulturais\Entities\Event', $agent_id FROM event WHERE is_verified = 't';"); }, - 'create update timestamp entities' => function () use($conn) { - if(__column_exists('agent', 'update_timestamp')){ + 'create update timestamp entities' => function () use ($conn) { + if (__column_exists('agent', 'update_timestamp')) { echo " ALREADY APPLIED update_timestamp FIELD CREATION ON agent TABLE. "; } else { - $conn->executeQuery("ALTER TABLE agent ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); + $conn->executeQuery("ALTER TABLE agent ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); } - if(__column_exists('space', 'update_timestamp')){ + if (__column_exists('space', 'update_timestamp')) { echo "ALREADY APPLIED update_timestamp FIELD CREATION ON space TABLE. "; } else { - $conn->executeQuery("ALTER TABLE space ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); + $conn->executeQuery("ALTER TABLE space ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); } - if(__column_exists('project', 'update_timestamp')){ + if (__column_exists('project', 'update_timestamp')) { echo "ALREADY APPLIED update_timestamp FIELD CREATION ON project TABLE. "; } else { - $conn->executeQuery("ALTER TABLE project ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); + $conn->executeQuery("ALTER TABLE project ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); } - if(__column_exists('event', 'update_timestamp')){ + if (__column_exists('event', 'update_timestamp')) { echo "ALREADY APPLIED update_timestamp FIELD CREATION ON event TABLE. "; } else { - $conn->executeQuery("ALTER TABLE event ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); + $conn->executeQuery("ALTER TABLE event ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); } - if(__column_exists('seal', 'update_timestamp')){ + if (__column_exists('seal', 'update_timestamp')) { echo "ALREADY APPLIED update_timestamp FIELD CREATION ON seal TABLE. "; } else { - $conn->executeQuery("ALTER TABLE seal ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); + $conn->executeQuery("ALTER TABLE seal ADD COLUMN update_timestamp TIMESTAMP(0) WITHOUT TIME ZONE;"); } - }, - 'alter table role add column subsite_id' => function () use($conn) { - if(__column_exists('role', 'subsite_id')){ + 'alter table role add column subsite_id' => function () use ($conn) { + if (__column_exists('role', 'subsite_id')) { return true; } - - $conn->executeQuery("ALTER TABLE role DROP CONSTRAINT IF EXISTS role_user_fk;"); - $conn->executeQuery("ALTER TABLE role DROP CONSTRAINT IF EXISTS role_unique;"); + + $conn->executeQuery("ALTER TABLE role DROP CONSTRAINT IF EXISTS role_user_fk;"); + $conn->executeQuery("ALTER TABLE role DROP CONSTRAINT IF EXISTS role_unique;"); $conn->executeQuery("ALTER TABLE role ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE role ALTER id DROP DEFAULT;"); $conn->executeQuery("ALTER TABLE role ALTER usr_id DROP NOT NULL;"); @@ -417,72 +421,72 @@ function __try($sql, $cb = null){ $conn->executeQuery("CREATE INDEX IDX_57698A6AC79C849A ON role (subsite_id);"); }, - 'Fix field options field type from registration field configuration' => function () use($conn) { + 'Fix field options field type from registration field configuration' => function () use ($conn) { $conn->executeQuery("ALTER TABLE registration_field_configuration ALTER COLUMN field_options TYPE text;"); }, - 'ADD columns subsite_id' => function () use($conn) { - if(!__column_exists('space', 'subsite_id')){ + 'ADD columns subsite_id' => function () use ($conn) { + if (!__column_exists('space', 'subsite_id')) { $conn->executeQuery("ALTER TABLE space ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE space ADD CONSTRAINT FK_2972C13AC79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_2972C13AC79C849A ON space (subsite_id);"); } - if(!__column_exists('agent', 'subsite_id')){ + if (!__column_exists('agent', 'subsite_id')) { $conn->executeQuery("ALTER TABLE agent ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE agent ADD CONSTRAINT FK_268B9C9DC79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_268B9C9DC79C849A ON agent (subsite_id);"); } - if(!__column_exists('event', 'subsite_id')){ + if (!__column_exists('event', 'subsite_id')) { $conn->executeQuery("ALTER TABLE event ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA7C79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_3BAE0AA7C79C849A ON event (subsite_id);"); } - if(!__column_exists('project', 'subsite_id')){ + if (!__column_exists('project', 'subsite_id')) { $conn->executeQuery("ALTER TABLE project ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEC79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_2FB3D0EEC79C849A ON project (subsite_id);"); } - if(!__column_exists('seal', 'subsite_id')){ + if (!__column_exists('seal', 'subsite_id')) { $conn->executeQuery("ALTER TABLE seal ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE seal ADD CONSTRAINT FK_2E30AE30C79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_2E30AE30C79C849A ON seal (subsite_id);"); } - if(!__column_exists('registration', 'subsite_id')){ + if (!__column_exists('registration', 'subsite_id')) { $conn->executeQuery("ALTER TABLE registration ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE registration ADD CONSTRAINT FK_62A8A7A7C79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_62A8A7A7C79C849A ON registration (subsite_id);"); } - if(!__column_exists('user_app', 'subsite_id')){ + if (!__column_exists('user_app', 'subsite_id')) { $conn->executeQuery("ALTER TABLE user_app ADD subsite_id INT DEFAULT NULL;"); $conn->executeQuery("ALTER TABLE user_app ADD CONSTRAINT FK_22781144C79C849A FOREIGN KEY (subsite_id) REFERENCES subsite (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("CREATE INDEX IDX_22781144C79C849A ON user_app (subsite_id);"); } }, - 'remove subsite slug column' => function () use($conn) { - if(!__column_exists('subsite', 'slug')){ + 'remove subsite slug column' => function () use ($conn) { + if (!__column_exists('subsite', 'slug')) { return true; } - + $conn->executeQuery("ALTER TABLE subsite DROP COLUMN slug;"); }, - 'add subsite verified_seals column' => function () use($conn) { - if(__column_exists('subsite', 'verified_seals')){ + 'add subsite verified_seals column' => function () use ($conn) { + if (__column_exists('subsite', 'verified_seals')) { return true; } $conn->executeQuery("ALTER TABLE subsite ADD verified_seals VARCHAR(512) DEFAULT '[]';"); }, - 'update entities last_update_timestamp with user last log timestamp' => function () use($conn,$app) { + 'update entities last_update_timestamp with user last log timestamp' => function () use ($conn, $app) { $agents = $conn->fetchAll("SELECT a.id, u.last_login_timestamp FROM agent a, usr u WHERE u.id = a.user_id"); - foreach($agents as $agent){ + foreach ($agents as $agent) { $agent = (object) $agent; $conn->executeQuery("UPDATE space SET update_timestamp = '{$agent->last_login_timestamp}' WHERE agent_id = {$agent->id} AND update_timestamp IS NULL"); $conn->executeQuery("UPDATE event SET update_timestamp = '{$agent->last_login_timestamp}' WHERE agent_id = {$agent->id} AND update_timestamp IS NULL"); @@ -493,12 +497,12 @@ function __try($sql, $cb = null){ $conn->executeQuery("UPDATE agent SET update_timestamp = u.last_login_timestamp FROM (SELECT id, last_login_timestamp FROM usr) AS u WHERE user_id = u.id AND update_timestamp IS NULL"); }, - 'Fix field options field type from registration field configuration' => function () use($conn) { + 'Fix field options field type from registration field configuration' => function () use ($conn) { $conn->executeQuery("ALTER TABLE registration_field_configuration ALTER COLUMN field_options TYPE text;"); }, - 'Created owner seal relation field' => function () use($conn) { - if(__column_exists('seal_relation', 'owner_id')){ + 'Created owner seal relation field' => function () use ($conn) { + if (__column_exists('seal_relation', 'owner_id')) { echo "ALREADY APPLIED"; return true; } @@ -514,11 +518,10 @@ function __try($sql, $cb = null){ $conn->executeQuery("UPDATE seal_relation SET owner_id = '$agent_id' WHERE owner_id IS NULL;"); }, - 'create table pcache' => function () use($conn) { - if(__table_exists('pcache')){ + 'create table pcache' => function () use ($conn) { + if (__table_exists('pcache')) { echo 'tabela pcache já foi criada'; return true; - } $conn->executeQuery("CREATE TABLE pcache (id INT NOT NULL, user_id INT NOT NULL, action VARCHAR(255) NOT NULL, create_timestamp TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, object_type VARCHAR(255) NOT NULL, object_id INT DEFAULT NULL, PRIMARY KEY(id));"); $conn->executeQuery("CREATE INDEX IDX_3D853098A76ED395 ON pcache (user_id);"); @@ -527,11 +530,10 @@ function __try($sql, $cb = null){ $conn->executeQuery("CREATE INDEX pcache_permission_idx ON pcache (object_type, object_id, action);"); $conn->executeQuery("CREATE INDEX pcache_permission_user_idx ON pcache (object_type, object_id, action, user_id);"); $conn->executeQuery("ALTER TABLE pcache ADD CONSTRAINT FK_3D853098A76ED395 FOREIGN KEY (user_id) REFERENCES usr (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); - }, 'function create pcache id sequence 2' => function () use ($conn) { - if(__sequence_exists('pcache_id_seq')){ + if (__sequence_exists('pcache_id_seq')) { echo 'sequencia pcache_id_seq já existe'; return true; } @@ -543,18 +545,17 @@ function __try($sql, $cb = null){ CACHE 1;"); $conn->executeQuery("ALTER TABLE ONLY pcache ALTER COLUMN id SET DEFAULT nextval('pcache_id_seq'::regclass);"); - }, - 'Add field for maximum size from registration field configuration' => function () use($conn) { - if(__column_exists('registration_field_configuration', 'max_size')){ + 'Add field for maximum size from registration field configuration' => function () use ($conn) { + if (__column_exists('registration_field_configuration', 'max_size')) { return true; } $conn->executeQuery("ALTER TABLE registration_field_configuration ADD COLUMN max_size text;"); }, - 'Add notification type for compliant and suggestion messages' => function () use($conn) { - if(__table_exists('notification_meta')) { + 'Add notification type for compliant and suggestion messages' => function () use ($conn) { + if (__table_exists('notification_meta')) { echo "ALREADY APPLIED"; return true; } @@ -563,8 +564,8 @@ function __try($sql, $cb = null){ $conn->executeQuery("ALTER TABLE notification_meta ADD CONSTRAINT notification_meta_fk FOREIGN KEY (object_id) REFERENCES notification (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); }, - 'create entity revision tables' => function() use($conn) { - if(__table_exists('entity_revision')) { + 'create entity revision tables' => function () use ($conn) { + if (__table_exists('entity_revision')) { echo "ALREADY APPLIED"; return true; } @@ -580,17 +581,16 @@ function __try($sql, $cb = null){ }, 'ALTER TABLE file ADD COLUMN path' => function () use ($conn) { - if(__column_exists('file', 'path')){ + if (__column_exists('file', 'path')) { return true; } $conn->executeQuery("CREATE INDEX file_owner_index ON file (object_type, object_id);"); $conn->executeQuery("CREATE INDEX file_group_index ON file (grp);"); $conn->executeQuery("ALTER TABLE file ADD path VARCHAR(1024) DEFAULT NULL;"); - }, - 'create avatar thumbs' => function() use($conn){ + 'create avatar thumbs' => function () use ($conn) { $conn->executeQuery("DELETE FROM file WHERE object_type = 'MapasCulturais\Entities\Agent' AND object_id NOT IN (SELECT id FROM agent)"); $conn->executeQuery("DELETE FROM file WHERE object_type = 'MapasCulturais\Entities\Space' AND object_id NOT IN (SELECT id FROM space)"); $conn->executeQuery("DELETE FROM file WHERE object_type = 'MapasCulturais\Entities\Project' AND object_id NOT IN (SELECT id FROM project)"); @@ -599,7 +599,7 @@ function __try($sql, $cb = null){ $files = $this->repo('SealFile')->findBy(['group' => 'avatar']); echo count($files) . " ARQUIVOS\n"; - foreach($files as $f){ + foreach ($files as $f) { $f->transform('avatarSmall'); $f->transform('avatarMedium'); $f->transform('avatarBig'); @@ -608,9 +608,9 @@ function __try($sql, $cb = null){ $this->disableAccessControl(); }, - '*_meta drop all indexes again' => function () use($conn) { + '*_meta drop all indexes again' => function () use ($conn) { - foreach(['subsite', 'agent', 'user', 'event', 'space', 'project', 'seal', 'registration', 'notification'] as $prefix){ + foreach (['subsite', 'agent', 'user', 'event', 'space', 'project', 'seal', 'registration', 'notification'] as $prefix) { $table = "{$prefix}_meta"; // seleciona todos os indeces exceto PK @@ -626,14 +626,14 @@ function __try($sql, $cb = null){ idx.indrelid::regclass::varchar = '{$table}' AND i.relname NOT IN (SELECT constraint_name FROM information_schema.table_constraints);"); - foreach($indexes as $index){ + foreach ($indexes as $index) { echo "DROP INDEX {$index['indname']}\n"; $conn->executeQuery("DROP INDEX {$index['indname']}"); } } $conn->executeQuery("ALTER TABLE seal_relation ADD COLUMN validate_date DATE;"); }, - 'recreate *_meta indexes' => function() use($conn) { + 'recreate *_meta indexes' => function () use ($conn) { __try("DELETE FROM subsite_meta WHERE object_id NOT IN (SELECT id FROM subsite)"); __try("DELETE FROM agent_meta WHERE object_id NOT IN (SELECT id FROM agent)"); @@ -715,7 +715,6 @@ function __try($sql, $cb = null){ __try("ALTER TABLE notification_meta ADD CONSTRAINT FK_6FCE5F0F232D562B FOREIGN KEY (object_id) REFERENCES notification (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;"); __try("CREATE INDEX notification_meta_owner_key_idx ON notification_meta (object_id, key);"); __try("CREATE INDEX notification_meta_owner_idx ON notification_meta (object_id);"); - }, /** @@ -724,9 +723,9 @@ function __try($sql, $cb = null){ * - files do grupo rules */ - 'create permission cache pending table2' => function() use ($conn) { + 'create permission cache pending table2' => function () use ($conn) { - if(__table_exists('permission_cache_pending')){ + if (__table_exists('permission_cache_pending')) { echo "TABLE permission_cache_pending ALREADY EXISTS"; return true; } @@ -739,14 +738,14 @@ function __try($sql, $cb = null){ PRIMARY KEY(id) );"); }, - - "corrigindo status da fila de criação de cache de permissão" => function() { + + "corrigindo status da fila de criação de cache de permissão" => function () { __exec("UPDATE permission_cache_pending SET status = 0;"); return false; }, 'create opportunity tables' => function () { - if(!__table_exists('opportunity')){ + if (!__table_exists('opportunity')) { __exec("DELETE FROM registration_meta WHERE object_id IN (SELECT id FROM registration WHERE project_id NOT IN (SELECT id FROM project))"); __exec("DELETE FROM registration WHERE project_id NOT IN (SELECT id FROM project)"); @@ -797,7 +796,7 @@ function __try($sql, $cb = null){ __exec("DELETE FROM registration WHERE agent_id NOT IN (SELECT id FROM agent)"); __exec("ALTER TABLE registration DROP CONSTRAINT fk_62a8a7a7c79c849a;"); - + __exec("ALTER TABLE registration RENAME COLUMN project_id TO opportunity_id;"); __exec("ALTER TABLE registration ALTER id SET DEFAULT pseudo_random_id_generator();"); __exec("ALTER TABLE registration ALTER status TYPE SMALLINT;"); @@ -818,30 +817,29 @@ function __try($sql, $cb = null){ __exec("ALTER TABLE registration_field_configuration RENAME COLUMN project_id TO opportunity_id;"); __exec("ALTER TABLE registration_field_configuration ADD CONSTRAINT FK_60C85CB19A34590F FOREIGN KEY (opportunity_id) REFERENCES opportunity (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); __exec("CREATE INDEX IDX_60C85CB19A34590F ON registration_field_configuration (opportunity_id);"); - } }, - - 'DROP CONSTRAINT registration_project_fk");' => function() { + + 'DROP CONSTRAINT registration_project_fk");' => function () { __exec("ALTER TABLE registration DROP CONSTRAINT IF EXISTS registration_project_fk ;"); }, - 'fix opportunity parent FK' => function() { + 'fix opportunity parent FK' => function () { __exec("ALTER TABLE opportunity DROP CONSTRAINT IF EXISTS FK_8389C3D7727ACA70;"); __exec("UPDATE opportunity SET parent_id = null WHERE parent_id NOT IN (SELECT id FROM opportunity)"); __try("ALTER TABLE opportunity DROP CONSTRAINT IF EXISTS opportunity_parent_fk;"); __exec("ALTER TABLE opportunity ADD CONSTRAINT opportunity_parent_fk FOREIGN KEY (parent_id) REFERENCES opportunity (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); }, - 'fix opportunity type 35' => function(){ + 'fix opportunity type 35' => function () { __exec("UPDATE opportunity SET type = 45 WHERE type = 35"); }, - + 'create opportunity sequence' => function () use ($conn) { - if(__sequence_exists('opportunity_id_seq')){ + if (__sequence_exists('opportunity_id_seq')) { return true; } - $last_id = $conn->fetchColumn ('SELECT max(id) FROM opportunity;'); + $last_id = $conn->fetchColumn('SELECT max(id) FROM opportunity;'); $last_id++; $conn->executeQuery("CREATE SEQUENCE opportunity_id_seq START WITH $last_id @@ -851,39 +849,38 @@ function __try($sql, $cb = null){ CACHE 1;"); $conn->executeQuery("ALTER TABLE ONLY opportunity ALTER COLUMN id SET DEFAULT nextval('opportunity_id_seq'::regclass);"); - }, - - 'update opportunity_meta_id sequence' => function() use ($conn){ - $last_id = $conn->fetchColumn ('SELECT max(id) FROM opportunity_meta;'); + + 'update opportunity_meta_id sequence' => function () use ($conn) { + $last_id = intval($conn->fetchColumn('SELECT max(id) FROM opportunity_meta;')); $last_id++; - + $conn->executeQuery("ALTER SEQUENCE opportunity_meta_id_seq START {$last_id} RESTART"); - + $conn->executeQuery("ALTER TABLE ONLY opportunity_meta ALTER COLUMN id SET DEFAULT nextval('opportunity_meta_id_seq'::regclass);"); }, - 'rename opportunity_meta key isProjectPhase to isOpportunityPhase' => function() { + 'rename opportunity_meta key isProjectPhase to isOpportunityPhase' => function () { __exec("UPDATE opportunity_meta SET key = 'isOpportunityPhase' WHERE key = 'isProjectPhase'"); }, - - 'migrate introInscricoes value to shortDescription' => function() use($conn) { + + 'migrate introInscricoes value to shortDescription' => function () use ($conn) { $values = $conn->fetchAll("SELECT * from opportunity_meta WHERE key = 'introInscricoes'"); - foreach($values as $value){ + foreach ($values as $value) { $conn->executeQuery("UPDATE opportunity SET short_description = :desc WHERE id = :id", ['id' => $value['object_id'], 'desc' => $value['value']]); } }, - - - + + + 'ALTER TABLE registration ADD consolidated_result' => function () { - if(!__column_exists('registration', 'consolidated_result')){ + if (!__column_exists('registration', 'consolidated_result')) { __exec("ALTER TABLE registration ADD consolidated_result VARCHAR(255) DEFAULT NULL;"); } }, - 'create evaluation methods tables' => function (){ - if(__table_exists('evaluation_method_configuration')){ + 'create evaluation methods tables' => function () { + if (__table_exists('evaluation_method_configuration')) { echo "evaluation_method_configuration table already exists"; return true; } @@ -902,13 +899,13 @@ function __try($sql, $cb = null){ $opportunities = $this->repo('Opportunity')->findAll(); - foreach($opportunities as $opportunity){ + foreach ($opportunities as $opportunity) { __exec("INSERT INTO evaluation_method_configuration ( opportunity_id, type) VALUES ($opportunity->id, 'simple');"); } }, - 'create registration_evaluation table' => function(){ - if(__table_exists('registration_evaluation')){ + 'create registration_evaluation table' => function () { + if (__table_exists('registration_evaluation')) { echo "ALREADY APPLIED"; return true; } @@ -927,41 +924,41 @@ function __try($sql, $cb = null){ __exec("ALTER TABLE registration_evaluation ADD CONSTRAINT FK_2E186C5C833D8F43 FOREIGN KEY (registration_id) REFERENCES registration (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;"); __exec("ALTER TABLE registration_evaluation ADD CONSTRAINT FK_2E186C5CA76ED395 FOREIGN KEY (user_id) REFERENCES usr (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;"); }, - - 'ALTER TABLE opportunity ALTER type DROP NOT NULL;' => function() use($conn){ + + 'ALTER TABLE opportunity ALTER type DROP NOT NULL;' => function () use ($conn) { $conn->executeUpdate('ALTER TABLE opportunity ALTER type DROP NOT NULL;'); }, - + 'ALTER TABLE registration ADD consolidated_result' => function () { - if(!__column_exists('registration', 'consolidated_result')){ + if (!__column_exists('registration', 'consolidated_result')) { __exec("ALTER TABLE registration ADD consolidated_result VARCHAR(255) DEFAULT NULL;"); } }, - 'create seal relation renovation flag field' => function() use($conn) { - if(__column_exists('seal_relation', 'renovation_request')){ + 'create seal relation renovation flag field' => function () use ($conn) { + if (__column_exists('seal_relation', 'renovation_request')) { echo "ALREADY APPLIED"; return true; } $conn->executeQuery("ALTER TABLE seal_relation ADD COLUMN renovation_request BOOLEAN;"); }, - 'create seal relation validate date' => function() use($conn) { - if(__column_exists('seal_relation', 'validate_date')){ + 'create seal relation validate date' => function () use ($conn) { + if (__column_exists('seal_relation', 'validate_date')) { echo "ALREADY APPLIED"; return true; } $conn->executeQuery("ALTER TABLE seal_relation ADD COLUMN validate_date DATE;"); }, - - 'update seal_relation set validate_date' => function() use ($conn) { - + + 'update seal_relation set validate_date' => function () use ($conn) { + $conn->executeQuery("UPDATE seal_relation SET validate_date = seal_relation.create_timestamp + cast(cast(s.valid_period as text) || 'month' as interval) FROM (SELECT id, valid_period FROM seal) AS s WHERE s.id = seal_id AND validate_date IS NULL;"); }, - - 'refactor of entity meta keky value indexes' => function() use ($conn){ - $__try = function($sql) use ($conn){ - try{ + + 'refactor of entity meta keky value indexes' => function () use ($conn) { + $__try = function ($sql) use ($conn) { + try { $conn->executeQuery($sql); } catch (\Exception $ex) { } @@ -986,17 +983,17 @@ function __try($sql, $cb = null){ $__try("CREATE INDEX notification_meta_key_idx ON notification_meta(key);"); }, - 'DROP index registration_meta_value_idx' => function () use ($conn){ + 'DROP index registration_meta_value_idx' => function () use ($conn) { __try("DROP INDEX registration_meta_value_idx;"); }, //Space_Relation - 'CREATE SEQUENCE REGISTRATION SPACE RELATION registration_space_relation_id_seq' => function() use($conn){ + 'CREATE SEQUENCE REGISTRATION SPACE RELATION registration_space_relation_id_seq' => function () use ($conn) { $conn->executeQuery("CREATE SEQUENCE space_relation_id_seq INCREMENT BY 1 MINVALUE 1 START 1;"); }, - 'CREATE TABLE spacerelation' => function() use($conn){ + 'CREATE TABLE spacerelation' => function () use ($conn) { $conn->executeQuery("CREATE TABLE space_relation (id INT NOT NULL, space_id INT DEFAULT NULL, object_id INT NOT NULL, create_timestamp TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, status SMALLINT DEFAULT NULL, object_type VARCHAR(255) NOT NULL, PRIMARY KEY(id));"); @@ -1008,37 +1005,36 @@ function __try($sql, $cb = null){ }, //Adiciona coluna space_data com metadados do espaço vinculado à inscrição - 'ALTER TABLE registration' => function() use($conn){ + 'ALTER TABLE registration' => function () use ($conn) { $conn->executeQuery("ALTER TABLE registration ADD space_data text DEFAULT NULL;"); }, - - - 'altertable registration_file_and_files_add_order' => function () use($conn){ - if(__column_exists('registration_file_configuration', 'order')){ + + + 'altertable registration_file_and_files_add_order' => function () use ($conn) { + if (__column_exists('registration_file_configuration', 'order')) { echo "ALREADY APPLIED"; } else { $conn->executeQuery("ALTER TABLE registration_file_configuration ADD COLUMN display_order SMALLINT DEFAULT 255;"); } - - if(__column_exists('registration_field_configuration', 'order')){ + + if (__column_exists('registration_field_configuration', 'order')) { echo "ALREADY APPLIED"; } else { $conn->executeQuery("ALTER TABLE registration_field_configuration ADD COLUMN display_order SMALLINT DEFAULT 255;"); } - }, - 'replace subsite entidades_habilitadas values' => function () use($conn) { + 'replace subsite entidades_habilitadas values' => function () use ($conn) { $rs = $conn->fetchAll("SELECT * FROM subsite_meta WHERE key = 'entidades_habilitadas'"); - - foreach($rs as $r){ + + foreach ($rs as $r) { $r = (object) $r; $value = preg_replace(['#Espa[^;]+os#i', '#Eventos#i', '#Agentes#i', '#Projetos#i', '#Oportunidades"i'], ['Spaces', 'Events', 'Agents', 'Projects', 'Opportunities'], $r->value); $conn->exec("UPDATE subsite_meta SET value = '{$value}' WHERE id = {$r->id}"); } }, - 'replace subsite cor entidades values' => function () use($conn) { + 'replace subsite cor entidades values' => function () use ($conn) { $conn->executeQuery("UPDATE subsite_meta SET key = 'spaces_color' where key = 'cor_espacos';"); $conn->executeQuery("UPDATE subsite_meta SET key = 'events_color' where key = 'cor_eventos';"); $conn->executeQuery("UPDATE subsite_meta SET key = 'projects_color' where key = 'cor_projetos';"); @@ -1047,64 +1043,57 @@ function __try($sql, $cb = null){ }, 'ALTER TABLE file ADD private and update' => function () use ($conn) { - if(__column_exists('file', 'private')){ + if (__column_exists('file', 'private')) { return true; } $conn->executeQuery("ALTER TABLE file ADD private BOOLEAN NOT NULL DEFAULT FALSE;"); - + $conn->executeQuery("UPDATE file SET private = true WHERE grp LIKE 'rfc_%' OR grp = 'zipArchive'"); - }, - 'fix subsite verifiedSeals array' => function() use($app){ + 'fix subsite verifiedSeals array' => function () use ($app) { $subsites = $app->repo('Subsite')->findAll(); - foreach($subsites as $subsite){ + foreach ($subsites as $subsite) { $subsite->setVerifiedSeals($subsite->verifiedSeals); $subsite->save(true); } }, - + 'move private files' => function () use ($conn) { - - + + $files = App::i()->repo('File')->findBy(['private' => true]); - + $StorageConfig = App::i()->storage->config; - - foreach($files as $file) { - - + + foreach ($files as $file) { + + // vou pegar a info de path direto do banco, sem usar o metodo do storage // para evitar erro com inconsistencias no banco $relative_path = $file->getRelativePath(false); - + if (!$relative_path) { echo "ATENCAO: Seu banco possui arquivos que não tem a informação de path' \n"; continue; } - + $targetPath = str_replace('\\', '-', $StorageConfig['private_dir'] . $relative_path); - + $oldPath = str_replace('\\', '-', $StorageConfig['dir'] . $relative_path); - + if (file_exists($oldPath)) { - - if(!is_dir(dirname($targetPath))) - mkdir (dirname($targetPath), 0755, true); - + + if (!is_dir(dirname($targetPath))) + mkdir(dirname($targetPath), 0755, true); + rename($oldPath, $targetPath); - } - - } - - - }, - 'create permission cache sequence' => function() use ($conn) { + 'create permission cache sequence' => function () use ($conn) { $conn->executeQuery("CREATE SEQUENCE permission_cache_pending_seq START WITH 1 @@ -1113,54 +1102,54 @@ function __try($sql, $cb = null){ NO MAXVALUE CACHE 1;"); }, - - 'create evaluation methods sequence' => function (){ - if(__sequence_exists('evaluation_method_configuration_id_seq')){ + + 'create evaluation methods sequence' => function () { + if (__sequence_exists('evaluation_method_configuration_id_seq')) { echo "evaluation_method_configuration_id_seq sequence already exists"; return true; } __exec("CREATE SEQUENCE evaluation_method_configuration_id_seq INCREMENT BY 1 MINVALUE 1 START 1;"); __exec("ALTER SEQUENCE evaluation_method_configuration_id_seq OWNED BY evaluation_method_configuration.id;"); __exec("ALTER TABLE ONLY evaluation_method_configuration ALTER COLUMN id SET DEFAULT nextval('evaluation_method_configuration_id_seq'::regclass);"); - - __exec("SELECT setval('evaluation_method_configuration_id_seq', (select max(id) from evaluation_method_configuration), true);"); + + __exec("SELECT setval('evaluation_method_configuration_id_seq', (select max(id) from evaluation_method_configuration), true);"); }, - 'change opportunity field agent_id not null' => function() use ($conn) { + 'change opportunity field agent_id not null' => function () use ($conn) { $conn->executeQuery(" ALTER TABLE opportunity ALTER COLUMN agent_id SET NOT NULL "); }, - 'alter table registration add column number' => function() use($conn) { - if(!__column_exists('registration', 'number')){ + 'alter table registration add column number' => function () use ($conn) { + if (!__column_exists('registration', 'number')) { $conn->executeQuery("ALTER TABLE registration ADD COLUMN number VARCHAR(24)"); } }, - 'update registrations set number fixed'=> function () use($conn){ + 'update registrations set number fixed' => function () use ($conn) { echo "\nsalvando número da inscrição para oportunidades de uma só fase ou para a primeira fase das inscrições\n"; $conn->executeQuery("UPDATE registration SET number = CONCAT('on-', id) WHERE opportunity_id IN (SELECT id FROM opportunity WHERE parent_id IS NULL)"); $regs = $conn->fetchAll(" SELECT r.id, m.value AS previous FROM registration r LEFT JOIN registration_meta m ON m.object_id = r.id AND m.key = 'previousPhaseRegistrationId'"); - + echo "\nsalvando número da inscrição para demais fases das oportunidades\n"; $registrations = []; - foreach($regs as $reg){ + foreach ($regs as $reg) { $reg = (object) $reg; $registrations[$reg->id] = $reg; } - foreach($registrations as $reg){ - if(!$reg->previous){ + foreach ($registrations as $reg) { + if (!$reg->previous) { continue; } $current = $reg; - - while($current->previous){ + + while ($current->previous) { print_r($current); $current = $registrations[$current->previous]; } @@ -1170,14 +1159,14 @@ function __try($sql, $cb = null){ } }, - 'alter table registration add column valuers_exceptions_list' => function() use($conn){ - if(!__column_exists('registration', 'valuers_exceptions_list')){ + 'alter table registration add column valuers_exceptions_list' => function () use ($conn) { + if (!__column_exists('registration', 'valuers_exceptions_list')) { $conn->executeQuery("ALTER TABLE registration ADD valuers_exceptions_list TEXT NOT NULL DEFAULT '{\"include\": [], \"exclude\": []}';"); } }, - 'create event attendance table' => function() use($conn) { - if(!__table_exists('event_attendance')){ + 'create event attendance table' => function () use ($conn) { + if (!__table_exists('event_attendance')) { $conn->executeQuery(" CREATE TABLE event_attendance ( id INT NOT NULL, @@ -1205,8 +1194,8 @@ function __try($sql, $cb = null){ } }, - 'create procuration table' => function() use($conn) { - if(!__table_exists('procuration')){ + 'create procuration table' => function () use ($conn) { + if (!__table_exists('procuration')) { $conn->executeQuery(" CREATE TABLE procuration ( token VARCHAR(32) NOT NULL, @@ -1216,17 +1205,16 @@ function __try($sql, $cb = null){ create_timestamp TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, valid_until_timestamp TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(token));"); - + $conn->executeQuery("CREATE INDEX procuration_usr_idx ON procuration (usr_id);"); $conn->executeQuery("CREATE INDEX procuration_attorney_idx ON procuration (attorney_user_id);"); $conn->executeQuery("ALTER TABLE procuration ADD CONSTRAINT FK_D7BAE7FC69D3FB FOREIGN KEY (usr_id) REFERENCES usr (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); $conn->executeQuery("ALTER TABLE procuration ADD CONSTRAINT FK_D7BAE7F3AEB2ED7 FOREIGN KEY (attorney_user_id) REFERENCES usr (id) NOT DEFERRABLE INITIALLY IMMEDIATE;"); - } }, - 'alter table registration_field_configuration add column config' => function() use($conn){ - if(!__column_exists('registration_field_configuration', 'config')){ + 'alter table registration_field_configuration add column config' => function () use ($conn) { + if (!__column_exists('registration_field_configuration', 'config')) { __exec(" ALTER TABLE registration_field_configuration ADD config TEXT; @@ -1234,7 +1222,7 @@ function __try($sql, $cb = null){ } }, - 'recreate ALL FKs' => function () use($conn) { + 'recreate ALL FKs' => function () use ($conn) { $sql = " DO $$ @@ -1315,26 +1303,25 @@ function __try($sql, $cb = null){ __exec("ALTER TABLE notification_meta ADD CONSTRAINT FK_6FCE5F0F232D562B FOREIGN KEY (object_id) REFERENCES notification (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;"); __exec("ALTER TABLE registration_evaluation ADD CONSTRAINT FK_2E186C5C833D8F43 FOREIGN KEY (registration_id) REFERENCES registration (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;"); __exec("ALTER TABLE registration_evaluation ADD CONSTRAINT FK_2E186C5CA76ED395 FOREIGN KEY (user_id) REFERENCES usr (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE; "); - }, 'create object_type enum type' => function () { - $object_types = implode(',', array_map(function($el) { + $object_types = implode(',', array_map(function ($el) { return "'$el'"; }, DoctrineEnumTypes\ObjectType::values())); __exec("CREATE TYPE object_type AS ENUM($object_types)"); - }, + }, 'create permission_action enum type' => function () { - $permission_actions = implode(',', array_map(function($el) { + $permission_actions = implode(',', array_map(function ($el) { return "'$el'"; }, DoctrineEnumTypes\PermissionAction::values())); __exec("CREATE TYPE permission_action AS ENUM($permission_actions)"); - }, + }, - 'alter tables to use enum types' => function() { + 'alter tables to use enum types' => function () { __exec("ALTER TABLE pcache ALTER COLUMN object_type TYPE object_type USING object_type::object_type"); __exec("ALTER TABLE pcache ALTER COLUMN action TYPE permission_action USING action::permission_action"); @@ -1343,16 +1330,15 @@ function __try($sql, $cb = null){ __exec("ALTER TABLE term_relation ALTER COLUMN object_type TYPE object_type USING object_type::object_type"); __exec("ALTER TABLE entity_revision ALTER COLUMN object_type TYPE object_type USING object_type::object_type"); __exec("ALTER TABLE metadata ALTER COLUMN object_type TYPE object_type USING object_type::object_type"); - }, - 'alter table permission_cache_pending add column status' => function() use($conn) { + 'alter table permission_cache_pending add column status' => function () use ($conn) { if (!__column_exists('permission_cache_pending', 'status')) { $conn->executeQuery("ALTER TABLE permission_cache_pending ADD status smallint DEFAULT 0"); } }, - 'RECREATE VIEW evaluations AGAIN!!!!!' => function() use($conn) { + 'RECREATE VIEW evaluations AGAIN!!!!!' => function () use ($conn) { __try("DROP VIEW evaluations"); $conn->executeQuery(" @@ -1427,9 +1413,9 @@ function __try($sql, $cb = null){ "); }, - 'adiciona oportunidades na fila de reprocessamento de cache' => function () use($conn) { + 'adiciona oportunidades na fila de reprocessamento de cache' => function () use ($conn) { $sql = "SELECT id from opportunity where parent_id is null and status > 0"; - foreach($conn->fetchAll($sql) as $em) { + foreach ($conn->fetchAll($sql) as $em) { __exec(" INSERT INTO permission_cache_pending ( id, @@ -1445,7 +1431,7 @@ function __try($sql, $cb = null){ } }, - 'adiciona novos indices a tabela agent_relation' => function () { + 'adiciona novos indices a tabela agent_relation' => function () { __try("DROP INDEX agent_relation_all;"); __try("CREATE INDEX agent_relation_owner_type ON agent_relation (object_type);"); __try("CREATE INDEX agent_relation_owner_id ON agent_relation (object_id);"); @@ -1456,7 +1442,7 @@ function __try($sql, $cb = null){ __try("ALTER INDEX idx_54585edd3414710b RENAME TO agent_relation_agent;"); }, - 'valuer disabling refactor' => function() use($conn) { + 'valuer disabling refactor' => function () use ($conn) { $conn->executeQuery(" UPDATE agent_relation @@ -1472,16 +1458,18 @@ function __try($sql, $cb = null){ __exec("ALTER TABLE metalist ALTER value TYPE TEXT;"); }, - 'Add metadata to Agent Relation' => function () use($conn) { - if(__column_exists('agent_relation', 'metadata')){ + 'Add metadata to Agent Relation' => function () use ($conn) { + if (__column_exists('agent_relation', 'metadata')) { return true; } $conn->executeQuery("ALTER TABLE agent_relation ADD COLUMN metadata json;"); }, 'add timestamp columns to registration_evaluation' => function () { - if (__column_exists('registration_evaluation', 'create_timestamp') && - __column_exists('registration_evaluation', 'update_timestamp')) { + if ( + __column_exists('registration_evaluation', 'create_timestamp') && + __column_exists('registration_evaluation', 'update_timestamp') + ) { echo "ALREADY APPLIED"; return true; } @@ -1539,8 +1527,10 @@ function __try($sql, $cb = null){ }, 'add timestamp columns to registration_evaluation' => function () { - if (__column_exists('registration_evaluation', 'create_timestamp') && - __column_exists('registration_evaluation', 'update_timestamp')) { + if ( + __column_exists('registration_evaluation', 'create_timestamp') && + __column_exists('registration_evaluation', 'update_timestamp') + ) { echo "ALREADY APPLIED"; return true; } @@ -1597,7 +1587,7 @@ function __try($sql, $cb = null){ } }, - 'create table job' => function () use($conn) { + 'create table job' => function () use ($conn) { __exec("CREATE TABLE job ( id VARCHAR(255) NOT NULL, name VARCHAR(32) NOT NULL, @@ -1759,16 +1749,16 @@ function __try($sql, $cb = null){ FOR EACH ROW EXECUTE PROCEDURE fn_clean_orphans('MapasCulturais\Entities\Subsite')"); }, - "Remove lixo angular registration_meta" => function() use ($conn){ + "Remove lixo angular registration_meta" => function () use ($conn) { - $clean_meta = function($meta, $clean_meta){ - if(is_array($meta)){ - foreach($meta as $key => $value){ + $clean_meta = function ($meta, $clean_meta) { + if (is_array($meta)) { + foreach ($meta as $key => $value) { $meta[$key] = $clean_meta($value, $clean_meta); } - }else if(is_object($meta)){ - foreach($meta as $key => $value){ - if($key == '$$hashKey'){ + } else if (is_object($meta)) { + foreach ($meta as $key => $value) { + if ($key == '$$hashKey') { unset($meta->$key); } } @@ -1777,48 +1767,48 @@ function __try($sql, $cb = null){ }; $metas = $conn->fetchAll("SELECT * FROM registration_meta WHERE value LIKE '%\$\$hashKey%'"); - foreach($metas as $i => $meta){ - $raw_value = json_decode($meta['value']); + foreach ($metas as $i => $meta) { + $raw_value = json_decode($meta['value']); $value = json_encode($clean_meta($raw_value, $clean_meta)); $meta['value'] = ($value == "[{}]") ? "[]" : $value; $conn->update("registration_meta", $meta, ['id' => $meta['id']]); - + echo "\nRemovido hashKey registration_meta id {$meta['id']}"; } }, - "Adiciona coluna avaliableEvaluationFields na tabela opportunity" => function() use ($conn){ - if(!__column_exists('opportunity', 'avaliable_evaluation_fields')) { + "Adiciona coluna avaliableEvaluationFields na tabela opportunity" => function () use ($conn) { + if (!__column_exists('opportunity', 'avaliable_evaluation_fields')) { __exec("ALTER TABLE opportunity ADD avaliable_evaluation_fields JSON DEFAULT NULL;"); } }, - "Adiciona coluna publish_timestamp na tabela opportunity" => function() use ($conn){ - if(!__column_exists('opportunity', 'publish_timestamp')) { + "Adiciona coluna publish_timestamp na tabela opportunity" => function () use ($conn) { + if (!__column_exists('opportunity', 'publish_timestamp')) { __exec("ALTER TABLE opportunity ADD publish_timestamp timestamp DEFAULT NULL;"); } }, "Adiciona coluna auto_publish na tabela opportunity" => function () { - if(!__column_exists('opportunity', 'auto_publish')) { + if (!__column_exists('opportunity', 'auto_publish')) { __exec("ALTER TABLE opportunity ADD auto_publish BOOLEAN DEFAULT 'false' NOT NULL;"); } }, - "Adiciona coluna evaluation_from e evaluation_to na tabela evaluation_method_configuration" => function() use ($conn){ - if(!__column_exists('evaluation_method_configuration', 'evaluation_from')) { + "Adiciona coluna evaluation_from e evaluation_to na tabela evaluation_method_configuration" => function () use ($conn) { + if (!__column_exists('evaluation_method_configuration', 'evaluation_from')) { __exec("ALTER TABLE evaluation_method_configuration ADD evaluation_from timestamp DEFAULT NULL;"); } - if(!__column_exists('evaluation_method_configuration', 'evaluation_to')) { + if (!__column_exists('evaluation_method_configuration', 'evaluation_to')) { __exec("ALTER TABLE evaluation_method_configuration ADD evaluation_to timestamp DEFAULT NULL;"); } }, - - "adiciona coluna name na tabela evaluation_method_configuration" => function () use($conn) { + + "adiciona coluna name na tabela evaluation_method_configuration" => function () use ($conn) { if (!__column_exists('evaluation_method_configuration', 'name')) { __exec("ALTER TABLE evaluation_method_configuration ADD name VARCHAR(255) DEFAULT NULL;"); } }, - "popula as colunas name, evaluation_from e evaluation_to da tabela evaluation_method_configuration" => function () use ($conn, $app){ + "popula as colunas name, evaluation_from e evaluation_to da tabela evaluation_method_configuration" => function () use ($conn, $app) { if (empty($app->getRegisteredEvaluationMethods())) { return false; } @@ -1827,7 +1817,7 @@ function __try($sql, $cb = null){ SELECT e.id, e.type, op.name, op.registration_from, op.registration_to FROM evaluation_method_configuration e LEFT JOIN opportunity op ON op.id = e.opportunity_id "); - + $num = count($rs); foreach ($rs as $i => $r) { $data = ['name' => $r['name']]; @@ -1849,27 +1839,27 @@ function __try($sql, $cb = null){ } }, - 'cria funções para o cast automático de ponto para varchar' => function () { + 'cria funções para o cast automático de ponto para varchar' => function () { __exec("CREATE OR REPLACE FUNCTION pg_catalog.text(point) RETURNS text STRICT IMMUTABLE LANGUAGE SQL AS 'SELECT $1::VARCHAR;';"); __try("CREATE CAST (point AS text) WITH FUNCTION pg_catalog.text(point) AS IMPLICIT;"); __exec("COMMENT ON FUNCTION pg_catalog.text(point) IS 'convert point to text';"); }, - "Renomeia colunas registrationFrom e registrationTo da tabela de projetod" => function() use ($conn){ - if (__column_exists('project', 'registration_from') && !__column_exists('project', 'starts_on')){ + "Renomeia colunas registrationFrom e registrationTo da tabela de projetod" => function () use ($conn) { + if (__column_exists('project', 'registration_from') && !__column_exists('project', 'starts_on')) { __exec("ALTER TABLE project RENAME registration_from TO starts_on;"); } - if (__column_exists('project', 'registration_to') && !__column_exists('project', 'ends_on')){ + if (__column_exists('project', 'registration_to') && !__column_exists('project', 'ends_on')) { __exec("ALTER TABLE project RENAME registration_to TO ends_on;"); } }, - "Adiciona novas coluna na tabela registration_field_configuration" => function() use ($conn){ + "Adiciona novas coluna na tabela registration_field_configuration" => function () use ($conn) { __exec("ALTER TABLE registration_field_configuration ADD conditional BOOLEAN;"); __exec("ALTER TABLE registration_field_configuration ADD conditional_field VARCHAR(255);"); __exec("ALTER TABLE registration_field_configuration ADD conditional_value VARCHAR(255);"); }, - "Adiciona novas coluna na tabela registration_file_configuration" => function() use ($conn){ + "Adiciona novas coluna na tabela registration_file_configuration" => function () use ($conn) { __exec("ALTER TABLE registration_file_configuration ADD conditional BOOLEAN;"); __exec("ALTER TABLE registration_file_configuration ADD conditional_field VARCHAR(255);"); __exec("ALTER TABLE registration_file_configuration ADD conditional_value VARCHAR(255);"); @@ -1877,27 +1867,27 @@ function __try($sql, $cb = null){ 'alter seal add column locked_fields' => function () { - if(!__column_exists('seal', 'locked_fields')) { + if (!__column_exists('seal', 'locked_fields')) { __exec("ALTER TABLE seal ADD locked_fields JSON DEFAULT '[]'"); } }, - "Consede permissão em todos os campo para todos os avaliadores da oportunidade" => function() use ($conn, $app){ + "Consede permissão em todos os campo para todos os avaliadores da oportunidade" => function () use ($conn, $app) { $opportunity_ids = $conn->fetchAll("SELECT id FROM opportunity WHERE status <> 0 AND status >= -1"); $fields = []; - foreach($opportunity_ids as $key => $id){ - - $cont = $key+1; + foreach ($opportunity_ids as $key => $id) { + + $cont = $key + 1; $opp = $app->repo("Opportunity")->findOneBy(['id' => $id['id']]); - if($opp->avaliableEvaluationFields){ + if ($opp->avaliableEvaluationFields) { $app->log->debug("{$cont} - Oportunidade {$opp->id} já tem configuração definida para os avaliadores"); continue; } - if($opp){ + if ($opp) { $prop = [ 'category' => "true", 'projectName' => "true", @@ -1908,30 +1898,28 @@ function __try($sql, $cb = null){ $fields_conf = $opp->getRegistrationFieldConfigurations(); $files_conf = $opp->getRegistrationFileConfigurations(); - foreach($fields_conf as $field){ - $fields["field_".$field->id] = "true"; + foreach ($fields_conf as $field) { + $fields["field_" . $field->id] = "true"; } - foreach($files_conf as $field){ - $fields["rfc_".$field->id] = "true"; + foreach ($files_conf as $field) { + $fields["rfc_" . $field->id] = "true"; } - $fields+= $prop; + $fields += $prop; $opp->avaliableEvaluationFields = $fields; $opp->save(true); $app->em->clear(); $app->log->debug("{$cont} - Configuração de permissão dos avaliadores fetuada na oportunidade {$opp->id}"); } - } - }, 'corrige metadados criados por erro em inscricoes de fases' => function () use ($conn, $app) { $opp_ids = $conn->fetchAll("SELECT id FROM opportunity WHERE parent_id IS NOT NULL"); foreach ($opp_ids as $opportunity) { $opportunity_id = $opportunity['id']; - + $conn->exec(" UPDATE registration_meta SET key = CONCAT('__BKP__', key) @@ -1950,46 +1938,46 @@ function __try($sql, $cb = null){ } }, - 'Adiciona a coluna description para a descrição da ocorrência' => function() { - if(!__column_exists('event_occurrence', 'description')) { + 'Adiciona a coluna description para a descrição da ocorrência' => function () { + if (!__column_exists('event_occurrence', 'description')) { __exec("ALTER TABLE event_occurrence ADD description TEXT DEFAULT NULL;"); } }, - 'Adiciona a coluna price para a o valor de entrada da ocorrência' => function() { - if(!__column_exists('event_occurrence', 'price')) { + 'Adiciona a coluna price para a o valor de entrada da ocorrência' => function () { + if (!__column_exists('event_occurrence', 'price')) { __exec("ALTER TABLE event_occurrence ADD price TEXT DEFAULT NULL;"); } }, - 'Adiciona a coluna priceInfo para a informações sobre o valor de entrada da ocorrência' => function() { - if(!__column_exists('event_occurrence', 'priceInfo')) { + 'Adiciona a coluna priceInfo para a informações sobre o valor de entrada da ocorrência' => function () { + if (!__column_exists('event_occurrence', 'priceInfo')) { __exec("ALTER TABLE event_occurrence ADD priceInfo TEXT DEFAULT NULL;"); } }, - - 'Apaga registro do db-update de "Definição dos cammpos cpf e cnpj com base no documento" para que rode novamente' => function() use ($conn, $app){ - if($conn->fetchAll("SELECT * FROM db_update WHERE name = 'Definição dos cammpos cpf e cnpj com base no documento'")){ + + 'Apaga registro do db-update de "Definição dos cammpos cpf e cnpj com base no documento" para que rode novamente' => function () use ($conn, $app) { + if ($conn->fetchAll("SELECT * FROM db_update WHERE name = 'Definição dos cammpos cpf e cnpj com base no documento'")) { $conn->executeQuery("DELETE FROM db_update WHERE name = 'Definição dos cammpos cpf e cnpj com base no documento'"); } }, - 'Corrige config dos campos na entidade registration_fields_configurarion' => function() use ($conn, $app){ + 'Corrige config dos campos na entidade registration_fields_configurarion' => function () use ($conn, $app) { $registration_fields_Types = $app->getRegisteredRegistrationFieldTypes(); $field_types = []; - foreach($registration_fields_Types as $type => $values){ - if(preg_match('/^@[a-zA-Z0-9\- ]{1,90}/', $values->name)){ - $field_types[] = "'".trim($values->slug)."'"; + foreach ($registration_fields_Types as $type => $values) { + if (preg_match('/^@[a-zA-Z0-9\- ]{1,90}/', $values->name)) { + $field_types[] = "'" . trim($values->slug) . "'"; } } $_field_types = implode(",", $field_types); - + $fields = $conn->fetchAll("SELECT * FROM registration_field_configuration WHERE field_type NOT IN ({$_field_types}) AND config LIKE '%entityField%'"); - + $txt = ""; - foreach($fields as $field){ + foreach ($fields as $field) { $_field = $app->repo("RegistrationFieldConfiguration")->find($field['id']); $config = $_field->config; - $txt.='['.$_field->id.' => '.serialize($_field->config).']\n'; + $txt .= '[' . $_field->id . ' => ' . serialize($_field->config) . ']\n'; unset($config['entityField']); array_filter($config); $_field->config = $config; @@ -2009,13 +1997,13 @@ function __try($sql, $cb = null){ fwrite($fp, $txt); fclose($fp); }, - "seta como vazio campo escolaridade do agent caso esteja com valor não informado" => function() use ($conn, $app){ + "seta como vazio campo escolaridade do agent caso esteja com valor não informado" => function () use ($conn, $app) { /** @var App $app */ - $app= App::i(); + $app = App::i(); $conn = $app->em->getConnection(); - if($agent_ids = $conn->fetchAll("SELECT am.object_id as id FROM agent_meta am WHERE am.key = 'escolaridade' AND am.value = 'Não Informar'")){ + if ($agent_ids = $conn->fetchAll("SELECT am.object_id as id FROM agent_meta am WHERE am.key = 'escolaridade' AND am.value = 'Não Informar'")) { $app->disableAccessControl(); - foreach($agent_ids as $value){ + foreach ($agent_ids as $value) { $agent = $app->repo("Agent")->find($value['id']); $agent->escolaridade = null; $agent->save(true); @@ -2023,17 +2011,17 @@ function __try($sql, $cb = null){ $app->enableAccessControl(); } }, - 'altera tipo da coluna description na tabela file' => function() use ($conn, $app){ + 'altera tipo da coluna description na tabela file' => function () use ($conn, $app) { $conn->executeQuery("ALTER TABLE file ALTER COLUMN description TYPE text;"); }, - "faz com que o updateTimestamp seja igual ao createTimestamp na criacão da entidade" => function() use ($conn){ + "faz com que o updateTimestamp seja igual ao createTimestamp na criacão da entidade" => function () use ($conn) { __exec("UPDATE agent SET update_timestamp = create_timestamp WHERE update_timestamp IS NULL"); __exec("UPDATE space SET update_timestamp = create_timestamp WHERE update_timestamp IS NULL"); __exec("UPDATE project SET update_timestamp = create_timestamp WHERE update_timestamp IS null"); __exec("UPDATE opportunity SET update_timestamp = create_timestamp WHERE update_timestamp IS NULL"); __exec("UPDATE EVENT SET update_timestamp = create_timestamp WHERE update_timestamp IS NULL"); }, - "migra valores das colunas do tipo array para do tipo json" => function() use ($conn) { + "migra valores das colunas do tipo array para do tipo json" => function () use ($conn) { $fields = $conn->fetchAll("SELECT id, config, field_options, categories from registration_field_configuration"); $count = count($fields); @@ -2041,16 +2029,16 @@ function __try($sql, $cb = null){ json_decode($string); return json_last_error() === JSON_ERROR_NONE; }; - - $check_serialize = function($value) use ($json_validate) { - if((is_string($value) && $json_validate($value)) || !$value) { + + $check_serialize = function ($value) use ($json_validate) { + if ((is_string($value) && $json_validate($value)) || !$value) { return $value; } return json_encode(unserialize($value)); }; - foreach($fields as $i => $field) { + foreach ($fields as $i => $field) { echo "migrando registration_field_configuration ({$i} / $count)\n"; $field['config'] = $check_serialize($field['config']); $field['field_options'] = $check_serialize($field['field_options']); @@ -2067,7 +2055,7 @@ function __try($sql, $cb = null){ $files = $conn->fetchAll("SELECT id, categories from registration_file_configuration"); $count = count($files); - foreach($files as $i => $file) { + foreach ($files as $i => $file) { echo "migrando registration_file_configuration ({$i} / $count)\n"; $file['categories'] = $check_serialize($file['categories']); @@ -2079,7 +2067,7 @@ function __try($sql, $cb = null){ $requests = $conn->fetchAll("SELECT id, metadata from request"); $count = count($requests); - foreach($requests as $i => $request) { + foreach ($requests as $i => $request) { echo "migrando request ({$i} / $count)\n"; $id = $request['id']; $metadata = $check_serialize($request['metadata']); @@ -2087,11 +2075,11 @@ function __try($sql, $cb = null){ $conn->executeQuery(" UPDATE request SET metadata = ':metadata' - WHERE id = $id", ['metadata'=>$metadata]); + WHERE id = $id", ['metadata' => $metadata]); } }, - 'corrige permissão de avaliadores que tem avaliação mas não possui permissão de avaliar pela regra configurada' => function() use($conn) { + 'corrige permissão de avaliadores que tem avaliação mas não possui permissão de avaliar pela regra configurada' => function () use ($conn) { $regs = $conn->fetchFirstColumn(" SELECT r.id @@ -2102,9 +2090,9 @@ function __try($sql, $cb = null){ p1.action IS NOT NULL AND p2.action IS NULL"); $app = App::i(); - + $count = count($regs); - foreach($regs as $i => $reg) { + foreach ($regs as $i => $reg) { $registration = $app->repo('Registration')->find($reg); echo "\n$i / $count ---- $registration"; $app->enqueueEntityToPCacheRecreation($registration); @@ -2113,11 +2101,11 @@ function __try($sql, $cb = null){ $app->persistPCachePendingQueue(); }, - 'adiciona coluna user_id à tabela pending_permission_cache' => function() use($conn) { + 'adiciona coluna user_id à tabela pending_permission_cache' => function () use ($conn) { __exec('ALTER TABLE permission_cache_pending ADD usr_id INT DEFAULT NULL;'); }, - 'limpeza da tabela de pcache' => function() use($conn) { + 'limpeza da tabela de pcache' => function () use ($conn) { __exec(" DELETE FROM pcache p1 USING pcache p2 @@ -2128,37 +2116,37 @@ function __try($sql, $cb = null){ p1.object_id = p2.object_id AND p1.action = p2.action;"); }, - - "Cria colunas registration_proponent_types e registration_ranges na tabela opportunity" => function() use ($conn){ - if(!__column_exists('opportunity', 'registration_proponent_types')) { + + "Cria colunas registration_proponent_types e registration_ranges na tabela opportunity" => function () use ($conn) { + if (!__column_exists('opportunity', 'registration_proponent_types')) { __exec("ALTER TABLE opportunity ADD COLUMN registration_proponent_types JSON NULL"); } - if(!__column_exists('opportunity', 'registration_ranges')) { + if (!__column_exists('opportunity', 'registration_ranges')) { __exec("ALTER TABLE opportunity ADD COLUMN registration_ranges JSON NULL"); } }, - "Cria colunas registration_ranges e proponent_types na tabela registration_field_configuration" => function() use ($conn){ - if(!__column_exists('registration_field_configuration', 'registration_ranges')) { + "Cria colunas registration_ranges e proponent_types na tabela registration_field_configuration" => function () use ($conn) { + if (!__column_exists('registration_field_configuration', 'registration_ranges')) { __exec("ALTER TABLE registration_field_configuration ADD COLUMN registration_ranges JSON NULL"); } - if(!__column_exists('registration_field_configuration', 'proponent_types')) { + if (!__column_exists('registration_field_configuration', 'proponent_types')) { __exec("ALTER TABLE registration_field_configuration ADD COLUMN proponent_types JSON NULL"); } }, - "Cria colunas registration_ranges e proponent_types na tabela registration_file_configuration" => function() use ($conn){ - if(!__column_exists('registration_file_configuration', 'registration_ranges')) { + "Cria colunas registration_ranges e proponent_types na tabela registration_file_configuration" => function () use ($conn) { + if (!__column_exists('registration_file_configuration', 'registration_ranges')) { __exec("ALTER TABLE registration_file_configuration ADD COLUMN registration_ranges JSON NULL"); } - if(!__column_exists('registration_file_configuration', 'proponent_types')) { + if (!__column_exists('registration_file_configuration', 'proponent_types')) { __exec("ALTER TABLE registration_file_configuration ADD COLUMN proponent_types JSON NULL"); } }, - + 'trigger to update children and parent opportunities' => function () { __exec("CREATE OR REPLACE FUNCTION fn_propagate_opportunity_update() RETURNS TRIGGER @@ -2185,7 +2173,7 @@ function __try($sql, $cb = null){ FOR EACH ROW EXECUTE FUNCTION fn_propagate_opportunity_update()"); }, - 'renomeia metadados da funcionalidade AffirmativePollices' => function() use ($conn, $app) { + 'renomeia metadados da funcionalidade AffirmativePollices' => function () use ($conn, $app) { $entity_metadada = [ [ 'entity' => 'evaluationMethodConfiguration_meta', @@ -2210,54 +2198,53 @@ function __try($sql, $cb = null){ ]; foreach ($entity_metadada as $metadata) { - + $entity = trim($metadata['entity']); $old = trim($metadata['old']); $new = trim($metadata['new']); - if($values = $conn->fetchAll("SELECT id FROM {$entity} WHERE key = '{$old}'")) { + if ($values = $conn->fetchAll("SELECT id FROM {$entity} WHERE key = '{$old}'")) { $total = count($values); foreach ($values as $key => $value) { $_key = $key + 1; $id = $value['id']; __exec("UPDATE {$entity} SET key = '{$new}' WHERE id = {$id}"); - + $app->log->debug("{$_key} de {$total} - Metadado {$old} alterado para {$new} na entidade {$entity}"); } } else { - $app->log->debug("Metadado {$old} não encontrado"); + $app->log->debug("Metadado {$old} não encontrado"); } } }, - "Cria colunas score e eligible na entidade Registration - correcao" => function() use ($conn){ - if(!__column_exists('registration', 'score')) { + "Cria colunas score e eligible na entidade Registration - correcao" => function () use ($conn) { + if (!__column_exists('registration', 'score')) { __exec("ALTER TABLE registration ADD COLUMN score FLOAT NULL"); - } - if(!__column_exists('registration', 'eligible')) { + } + if (!__column_exists('registration', 'eligible')) { __exec("ALTER TABLE registration ADD COLUMN eligible BOOLEAN NULL"); } }, - 'corrige os valores da distribuição de avaliação por categorias - correção' => function() use ($conn, $app) { - if($values = $conn->fetchAll("SELECT * FROM evaluationmethodconfiguration_meta WHERE key = 'fetchCategories'")) { - - foreach($values as $value) { - if($fetchCategories = json_decode($value['value'], true)) { + 'corrige os valores da distribuição de avaliação por categorias - correção' => function () use ($conn, $app) { + if ($values = $conn->fetchAll("SELECT * FROM evaluationmethodconfiguration_meta WHERE key = 'fetchCategories'")) { + + foreach ($values as $value) { + if ($fetchCategories = json_decode($value['value'], true)) { $data = []; $id = $value['id']; $val_id = $value['object_id']; $users = []; - foreach($fetchCategories as $user => $fetchCategorie ) { - if(!is_array($fetchCategorie)) { - $categories = explode(";",$fetchCategorie); - + foreach ($fetchCategories as $user => $fetchCategorie) { + if (!is_array($fetchCategorie)) { + $categories = explode(";", $fetchCategorie); + $data[$user] = $categories; - + $_data = json_encode($data); __exec("UPDATE evaluationmethodconfiguration_meta SET value = '{$_data}' WHERE id = {$id}"); $users[] = $app->repo("User")->find($user); $app->log->debug("Campo fetchCategories atualizado na avaliação {$val_id}"); } - } $em = $app->repo('EvaluationMethodConfiguration')->find($value['object_id']); @@ -2278,7 +2265,6 @@ function __try($sql, $cb = null){ __try('CREATE INDEX entity_revision_data_id ON entity_revision_data (id)'); __try('CREATE INDEX entity_revision_data_key ON entity_revision_data (key)'); - }, 'adiciona índice para a coluna action da tabela pcache' => function () { @@ -2299,7 +2285,7 @@ function __try($sql, $cb = null){ __try('CREATE INDEX file_parent_idx ON file (parent_id)'); __try('CREATE INDEX file_parent_object_type_idx ON file (parent_id, object_type)'); }, - 'Corrige constraint enforce_geotype_geom da tabela geo_division' => function() use($conn) { + 'Corrige constraint enforce_geotype_geom da tabela geo_division' => function () use ($conn) { __try("ALTER TABLE geo_division DROP CONSTRAINT enforce_geotype_geom"); __exec( @@ -2310,7 +2296,8 @@ function __try($sql, $cb = null){ CHECK (geometrytype(geom) = 'MULTIPOLYGON'::text OR geometrytype(geom) = 'POLYGON'::text OR geom IS NULL) - "); + " + ); } -] + $updates ; +] + $updates; diff --git a/api/mapas/src/tools/apply-multicore-db-update.php b/api/mapas/src/tools/apply-multicore-db-update.php index 7e31a5695f..fd3414f729 100644 --- a/api/mapas/src/tools/apply-multicore-db-update.php +++ b/api/mapas/src/tools/apply-multicore-db-update.php @@ -1,11 +1,11 @@ view->path as $path){ $db_update_file = $path . 'mc-updates.php'; diff --git a/compose.yaml b/compose.yaml index 59536a4917..e6a2957e93 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,6 +1,6 @@ services: php: - image: ${DOCKER_IMAGE:-ghcr.io/redemapas/mapas:feat-new-theme} + image: ghcr.io/redemapas/mapas:feat-new-theme depends_on: - database restart: unless-stopped @@ -26,21 +26,29 @@ services: GOOGLE_RECAPTCHA_SITEKEY: ${GOOGLE_RECAPTCHA_SITEKEY} GOOGLE_RECAPTCHA_SECRET: ${GOOGLE_RECAPTCHA_SECRET} SESSIONS_SAVE_PATH: ${SESSIONS_SAVE_PATH} - build: - context: ./api - target: frankenphp_dev + # build: + # context: ./api + # target: frankenphp_dev volumes: - ./api:/app # - /app/var - - var-files:/app/var - - ./api/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro - - ./api/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro + - var-files:/app/var/private-files + # - ./api/frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro + # - ./api/frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro - caddy_data:/data - caddy_config:/config web: extends: service: php + command: + [ + "frankenphp", + "run", + "--config", + "/etc/caddy/Caddyfile", + "--watch" + ] ports: # HTTP - target: 80 @@ -66,7 +74,7 @@ services: - php volumes: # - ./api:/app - - var-files:/app/var + - var-files:/app/var/private-files execute-job: extends: @@ -76,17 +84,27 @@ services: - php volumes: # - ./api:/app - - var-files:/app/var + - var-files:/app/var/private-files # db-update: # extends: # service: php - # command: php /app/mapas/src/tools/apply-updates.php + # command: php mapas/src/tools/apply-updates.php # depends_on: # - database # volumes: # # - ./api:/app - # - var-files:/app/var + # - var-files:/app/var/private-files + + # mc-update: + # extends: + # service: php + # command: php mapas/src/tools/apply-multicore-db-update.php + # depends_on: + # - database + # volumes: + # # - ./api:/app + # - var-files:/app/var/private-files redis: image: redis:6 @@ -107,17 +125,17 @@ services: # ports: # - "8025:8025" - pwa: - image: redemapas/mapas-pwa - build: - context: ./pwa - target: dev - volumes: - - ./pwa:/srv/app - environment: - API_PLATFORM_CREATE_CLIENT_ENTRYPOINT: http://php - API_PLATFORM_CREATE_CLIENT_OUTPUT: . - NEXT_PUBLIC_ENTRYPOINT: http://php + # pwa: + # image: redemapas/mapas-pwa + # build: + # context: ./pwa + # target: dev + # volumes: + # - ./pwa:/srv/app + # environment: + # API_PLATFORM_CREATE_CLIENT_ENTRYPOINT: http://php + # API_PLATFORM_CREATE_CLIENT_OUTPUT: . + # NEXT_PUBLIC_ENTRYPOINT: http://php database: image: kartoza/postgis:14 @@ -128,7 +146,7 @@ services: DATADIR: ${DATADIR} volumes: - db_data:/opt/postgres/data - - ./api/mapas/dev/db:/docker-entrypoint-initdb.d + #- ./api/mapas/dev/db:/docker-entrypoint-initdb.d # you may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! # - ./api/docker/db/data:/var/lib/postgresql/data healthcheck: