Commit 3e15d5d2 authored by Visay Keo's avatar Visay Keo
Browse files

[FEATURE] Allow setting to search replace db content

parent 4ecc1221
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
CHANGELOG
CHANGELOG
=========
=========


3.0-dev
3.0.7
-------
-----


  - [FEATURE] Allow setting to search replace db content
  - [IMP] Set data directory list to sync in variable
  - [IMP] Set data directory list to sync in variable


3.0.6
3.0.6
+21 −0
Original line number Original line Diff line number Diff line
@@ -161,6 +161,27 @@ To execute this task only, run this command:
bin-dir/syncontent --ansible-tags=db
bin-dir/syncontent --ansible-tags=db
```
```


For TYPO3, most of the time after restoring data, the domain records need to be adjusted to match your local setup.
In this case, you can provide a list of pair value so that this tool can search and replace it before restoring to your
local system.

To do that, create a file called `main.yml` in `ansible/roles/database/defaults/` directory and add the following content:

```
---
# Content replacement in database
replacement:
  1:
    search: live-domain.com
    replace: local-site:8080
  2:
    search: live-domain2.net
    replace: domain2.local-site:8080
```

`replacement`, `search` and `replace` are keyword but for `1` and `2` you can use any strings to define your content type.
Just add more array list with `search` and `replace` pair if needed.

### 3. cleanup
### 3. cleanup


The last step is to run some necessary commands needed by the framework for the application to work.
The last step is to run some necessary commands needed by the framework for the application to work.
+1 −0
Original line number Original line Diff line number Diff line
/*
+0 −2
Original line number Original line Diff line number Diff line
---
# defaults file for database
+5 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,11 @@
    synchronize: mode=pull src="{{ remote_dump }}" dest="/tmp/{{ ssh_user }}/db_dump.sql"
    synchronize: mode=pull src="{{ remote_dump }}" dest="/tmp/{{ ssh_user }}/db_dump.sql"
    when: not from_cache|bool
    when: not from_cache|bool


  - name: Search and replace content in database dump
    local_action: replace dest="/tmp/{{ ssh_user }}/db_dump.sql" regexp="{{ item.value.search }}" replace="{{ item.value.replace }}"
    with_dict: replacement | default({})
    when: not from_cache|bool

  - name: Drop local database
  - name: Drop local database
    local_action: shell {{ bin_path }}/dockertypo3 run db mysqladmin -h db -u root -proot drop dockertypo3 -f
    local_action: shell {{ bin_path }}/dockertypo3 run db mysqladmin -h db -u root -proot drop dockertypo3 -f
                  chdir="{{ local_path }}"
                  chdir="{{ local_path }}"