Jump to content

Recommended Posts

Hi everybody!

I have been reading about Multisite, but it kinda bugs me that every topic talks about having both admin and database same for multiple sites.

I have a project where customer tests it by adding content to the site, while I still need to do some changes here and there in code, maybe some in database. If something crashes for a while, customer can't keep testing, which is a bit problematic.

Is there any way that I could have two separate versions of one site ("production" and development) that share the same database, but are otherwise independent? Just the thought of having to migrate database every time I want to show client something new gives me anxiety 😁

Share this post


Link to post
Share on other sites
3 hours ago, iipa said:

Is there any way that I could have two separate versions of one site ("production" and development) that share the same database, but are otherwise independent?

What do you mean by "otherwise independent"? It is easy to have two pw instances connecting to one DB (just put the same in config.php), but that makes no sense in a production/dev environment. Adding a field to one site means you'll also have it in your other site. If your code does not reflect that (in BOTH instances), you'll get into trouble (php errors). And you don't want to have those DB changes on the live system instantly of course! Imagine you want to try adding a new "lorem ipsum" news entry... you'll instantly have it on your live system!

You have two options:

1) Duplicate your live website to the dev environment, make changes, test everything, push the changes back to live
--> this works only if you don't have any changes to the DB on your live system while you are developing/testing on your dev system

2) Migrations
https://processwire.com/blog/posts/introduction-migrations-module/
https://weekly.pw/issue/261/#new-module-rockmigrations (thx @teppo for listing it)

  • Like 1

Share this post


Link to post
Share on other sites

Hmm, that's a good point. There certainly are some risks that come with having the same database that I haven't considered. Thanks for pointing them out!

First solution doesn't work in this case, because client wants to test how things work with adding real content, so they probably wouldn't like the idea of things being wiped with every update.

The second option with migrations sounds cool though - might be just what I need!

  • Like 1

Share this post


Link to post
Share on other sites

Another (rather lo-fi) setup could be:

Use dev template files, as alternative templates. For testing out new content, you can leave pages unpublished and still preview them when logged in.

If your client (role) has permissions to switch templates with Tracy Debugger, there the template switcher panel you could use.

https://processwire.com/blog/posts/introducing-tracy-debugger/#template-path-panel

https://processwire-recipes.com/recipes/use-different-sets-of-template-files/

  • Like 2

Share this post


Link to post
Share on other sites

Wow, that sounds nice as well! And fairly easy to implement too. You know what they say, work smart, not hard!

  • Like 1

Share this post


Link to post
Share on other sites

I had some issues with server provider and subdomain SSL certificate (I want all my sites use forced https), but after those were resolved, @dragan's solution works perfectly! So thanks again, now I'm able to use actual data also in testing phase, which helps in UI design.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Juergen
      Hello @ all,
      I am creating a new inputfield/fieldtype to store opening hours, but I am struggeling to save values from multiple dynamic created inputfields in 1 column of the database.
      Scenario:
      The user can enter one or more opening times per day in a UI.
      Fe:
      Monday open from 08:00 to 12:00 and from 14:00 to 17:00 Tuesday open from 08:00 to 12:00 and from 14:00 to 19:00 and so on
      Via a little JavaScript you can add as much opening times as you need per day - the additional inputfield will be created dynamically.
      After form submission all the values are in the POST array -> this works (see example below):
      ProcessWire\WireInputData Object ( [openinghours_mo-0-start] => 09:00 [openinghours_mo-0-finish] => 13:00 [openinghours_mo-1-start] => 14:00 [openinghours_mo-1-finish] => 18:00 [openinghours_mo-2-start] => 21:00 [openinghours_mo-2-finish] => 23:00 [openinghours_tu-0-start] => 09:00 [openinghours_tu-0-finish] => 13:00 [openinghours_tu-1-start] => 14:00 [openinghours_tu-1-finish] => 18:00 [openinghours_we-0-start] => 09:00 [openinghours_we-0-finish] => 13:00 [openinghours_we-1-start] => 14:00 [openinghours_we-1-finish] => 18:00 [openinghours_th-0-start] => 09:00 [openinghours_th-0-finish] => 13:00 [openinghours_th-1-start] => 14:00 [openinghours_th-1-finish] => 18:00 [openinghours_fr-0-start] => 09:00 [openinghours_fr-0-finish] => 13:00 [openinghours_fr-1-start] => 14:00 [openinghours_fr-1-finish] => 18:00 [openinghours_sa-0-start] => [openinghours_sa-0-finish] => [openinghours_so-0-start] => [openinghours_so-0-finish] => ) The property name is always the name attribute of the field 😉 . If the property is empty means closed on that day.
      Now I need to combine all those values into 1 array (or json array) and store it in the database in 1 column called 'hours' in my case (see screenshot below):

      In my ___processInput(WireInputData $input) method I have tried to make it work like this:
      public function ___processInput(WireInputData $input): self { $name = $this->attr('name'); $value = $this->attr('value'); //input object includes always every input on the page, so lets filter out only inputs from this field //we need to do this, because the number of values is variable - so extract only values that starts with $name.'_' $nameAttributes = []; foreach($input as $key=>$value){ if(substr($key, 0, strlen($name.'_')) === $name.'_'){ $nameAttributes[$key] = $value; } } // loop through all inputfields of this fieldtype $time_values = []; foreach($nameAttributes as $nameAttr => $value) { $time_values[$nameAttr] = $value; } } //save it in the database $input->set('hours', serialize($time_values)); return $this; } The only important part of this code is the last part with the serialize function.
      After saving it will create a record in the database, but the value is always NULL (default value) (see below).

      Checking $time_values returns all the values, but printing out "$this" shows me that the property "hours" inside the Openinghours object is empty (see below) - so the mistake must be there, but I dont know where?!?!?!?
      [title] => Home [openinghours] => ProcessWire\OpeningHours Object ( [data] => Array ( [hours] => ) ) If I check the sleepValue() method or the sanitizeValue() - they are also empty. So it seems that the values will not reach these methods. I havent found a clear documentation of whats going on behind the saving process of an inputfield.
      As far as I know the saving process starts with the form submission. The values are in the POST array and will be processed by the processInput() method. Before they will be saved in the database they will be sanitized by the sanitizeValue() mehtod and afterwards they will be prepared for storage in the sleepValue() method.  The last step is the storage itself.
      Has someone an idea what is missing by storing values from multiple fields into 1 database column or has someone a working example of such a scenario on github to help me out.
      A clear explanation of the storage process will be also helpful.
      Thanks and best regards
    • By Pip
      Hi Everyone 
      I've been working on Processwire for two months now. Structuring the website as needed. Unsure why but I'm getting this one now. Seems my fields has crashed. 
      I've tried googling some answers but can't seem to find a step by step guide on how to rectify this. Any advise? Practically new on this. 
      TIA. 

    • By Rodd
      Hi everyone!
      I have a website in a production environment and I want to duplicate it in a local environment. I exported the content of the website (with the 'Site Profile Exporter' module) but I cannot use it actually. I've got an issue with the database. I imported this one in MAMP then.

      I also exported the pages (with the 'ProcessPagesExportImport' module), but I cannot import it to my local website because the fields don't exist. So I created this fields, but I have this error :
      How can I use the elements that already exist and are presents in my database? How can I duplicate correctly the templates, fields and pages?
      Thanks by advance
      PS: Sorry if my english is bad
       
    • By Sébastien
      Hello everyone,
      I recently started using ProcessWire and already manage to accomplish several things on my own, but I keep asking myself a lot of questions, among which the following:
      After installing a multiple sites version (first method), everything works for now as desired, but I realize that all the files seem accessible by all the domains.
      Let's say that site1.com can access the asset files, template or other ressources of site2.com folders and vice versa by specifying only and for example:
      site1.com/path_to_a_site2_folder/one_file
      or
      site2.com/path_to_a_site1_folder/one_file
      Would you know if there is a simple way to prohibit this kind of behavior in order to clearly distinguish each site and thus ensure the confidentiality and separation of content?
      I prefer to avoid the entities to be considered as a single set by crawlers and prevent access the elements belonging to each domain from another domain.
      Thanks for your help. Sébastien.
    • By DooM
      Hello guys,
      I'm trying to figure out how to sync fields and templates between staging and production environments.
      I've found Migrations module by Lostkobrakai, but with use of it all the fields and templates must be created by API, which is kind of uncomfortable.
      I also tried ProcessDatabaseBackups module which can export only certain tables, but I don't think it's the best practice to do that.
      How do you guys solve this problem? It's very annoying to setup everything three times (dev, staging, production).
      Thanks a lot :)
×
×
  • Create New...