Announcement

  •  » Engine
  •  » turn the "local" directory into a configuration setting

#1 2010-12-03 11:01:56

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

turn the "local" directory into a configuration setting

Hi Piwigo coding team,

The directory local makes a Piwigo installation unique. It contains:
* specific configuration settings
* database connection settings
* specific CSS rules
* some themes/plugins use it to store their configuration
* specific language values

The directory local is not the same as the directory _data which should be considered as a cache, that can be emptied at any time without breaking Piwigo. The other difference is that _data does not have to be visible on HTTP request while local must be.

In the future Piwigo 2.2, local will also contain the combined CSS and Javascript files, see [Forum, topic 16741] Browser side - javascript/css optimizations

Currently (Piwigo 2.1) the path of the directory _data is a configuration setting but local is hardcoded. In order to progress on the multiple sites features (1 Piwigo installation = several distinct galleries), we need to make the path of the directory local configurable as well.


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#2 2010-12-03 12:39:16

rvelices
Piwigo Team
2005-12-29
1960

Re: turn the "local" directory into a configuration setting

plg wrote:

The directory local is not the same as the directory _data which should be considered as a cache, that can be emptied at any time without breaking Piwigo. The other difference is that _data does not have to be visible on HTTP request while local must be.

In fact I store my plugin config files in _data ...

Ideally we should somehow be able to simplify for the users
1. - 'persistent' directory without required url access (_data/plugins, database config ...)
2. - 'persistent' directory with required url access (local/css)
3. - 'cache' directory without required url access (templates_c.)
4. - 'cache' directory with required url access (local/combined)

1. and 2. should be backed up by the user ...

Offline

 

#3 2011-01-13 23:49:47

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

I have a problem with this change.

I would like to have $conf[local_dir], set to './local' by default. Unfortunately, the standard way to customize parameter settings is to overwrite them in.... local/config/config.inc.php. You see the problem: we can't define the $conf[local_dir] in $conf[local_dir]/config/config.inc.php

Moreover, in include/common.inc.php, local/config/database.inc.php is included before configuration files.

Any idea?

(I've quickly read Drupal code which has the multisite feature and it loads the config file depending on the URL which of course is not a bad idea but I would like something simpler, considering that a single site can be mapped on several domains for example)


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#4 2011-01-14 08:35:48

LucMorizur
Member
Vienne (Isère) - France
2009-04-30
168

Re: turn the "local" directory into a configuration setting

plg wrote:

I have a problem with this change.

I would like to have $conf[local_dir], set to './local' by default. Unfortunately, the standard way to customize parameter settings is to overwrite them in.... local/config/config.inc.php. You see the problem: we can't define the $conf[local_dir] in $conf[local_dir]/config/config.inc.php

Moreover, in include/common.inc.php, local/config/database.inc.php is included before configuration files.

Any idea?

Define this setting at the installation time?


Our gallery : Le Site à Nous (a silly name in french, but here I don't care ;-) ! )
An event, a new gallery ? Plugin Event Cats
My test gallery : Tests Piwigo de Luc
Thanksalot for this beautiful project.

Offline

 

#5 2011-01-14 10:59:20

rvelices
Piwigo Team
2005-12-29
1960

Re: turn the "local" directory into a configuration setting

plg wrote:

I have a problem with this change.

I would like to have $conf[local_dir], set to './local' by default. Unfortunately, the standard way to customize parameter settings is to overwrite them in.... local/config/config.inc.php. You see the problem: we can't define the $conf[local_dir] in $conf[local_dir]/config/config.inc.php

Moreover, in include/common.inc.php, local/config/database.inc.php is included before configuration files.

Any idea?

(I've quickly read Drupal code which has the multisite feature and it loads the config file depending on the URL which of course is not a bad idea but I would like something simpler, considering that a single site can be mapped on several domains for example)

Maybe just do it simple, modify config_default on piwigo.com and include at the end config_default_piwigo.com.php ???

Offline

 

#6 2011-01-14 11:23:29

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

rvelices wrote:

Maybe just do it simple, modify config_default on piwigo.com and include at the end config_default_piwigo.com.php ???

Yes, if I want to solve the problem just for Piwigo.com, adding a $conf[local_dir] in include/config_default and changing it would be enough. On Piwigo.com, I use a $_SERVER[specific_var] that is set by the web server (setEnv with Apache, setenv.add-environment with Lighttpd) for each virtualhost.

A simple way to solve the problem would something like this in include/config_default :

Code:

$conf['local_dir'] = './local';
if (isset($_SERVER['PWG_LOCAL_DIR']))
{
    $conf['local_dir'] = $_SERVER['PWG_LOCAL_DIR'];
}

With a page in the Piwigo documentation that explains how to set the $_SERVER['PWG_LOCAL_DIR'] from Apache or Lighttpd.

But the danger is that it would be possible to overwrite $conf[local_dir] in $conf[local_dir]/config/config.inc.php. The only way I have in mind to prevent overwriting would be to use a constant instead of $conf[local_dir] in include/config_default (and not in include/constants because $conf must be already defined) :

Code:

if (isset($_SERVER['PWG_LOCAL_DIR']))
{
    define(PWG_LOCAL_DIR, $_SERVER['PWG_LOCAL_DIR']);
}
else
{
    define(PWG_LOCAL_DIR, './local');
}

With this solution + documentation page on "how to set $_SERVER['PWG_LOCAL_DIR'] from your web server", this makes an easy multisite solution for Piwigo, which does not depend on the URL.


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#7 2011-01-14 11:36:24

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

plg wrote:

With this solution + documentation page on "how to set $_SERVER['PWG_LOCAL_DIR'] from your web server", this makes an easy multisite solution for Piwigo, which does not depend on the URL.

This is the solution used in Magento, as far as I understand their documentation.


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#8 2011-01-14 11:39:52

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

On Nginx, the equivalent of Apache setEnv is fastcgi_param


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#9 2011-01-14 14:03:49

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

local/config/database.inc.php defines $prefixeTable and $prefixeTable is used in include/config_default.inc.php => we can't define the local_dir in include/config_default.inc.php


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#10 2011-01-14 14:50:47

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

As I can't define PWG_LOCAL_DIR in include/config_default, I've moved this code into include/common:

Code:

define(
  'PWG_LOCAL_DIR',
  isset($_SERVER['PWG_LOCAL_DIR'])
    ? $_SERVER['PWG_LOCAL_DIR']
    : PHPWG_ROOT_PATH.'local/'
);

@include(PWG_LOCAL_DIR .'config/database.inc.php');
[...]
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PWG_LOCAL_DIR. 'config/config.inc.php');

The problem is that I must duplicate this code everywhere include/common is not loaded : install.php, upgrade.php, upgrade_feed.php (well OK, that's only 3 files, it's not that a big deal)


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#11 2011-01-14 14:52:10

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

and I also admit I feel more comfortable to define this constant outside include/config_default which is designed to fill $conf hashmap, not define constants.


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#12 2011-01-14 16:10:46

rvelices
Piwigo Team
2005-12-29
1960

Re: turn the "local" directory into a configuration setting

plg wrote:

Code:

define(
  'PWG_LOCAL_DIR',
...
    : PHPWG_ROOT_PATH.'local/'
);

Please no PHPWG_ROOT_PATH. It should be relative to the root ! Let the code use PHPWG_ROOT_PATH or get_root_url depending on the page ...

Offline

 

#13 2011-01-14 16:22:07

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

rvelices wrote:

Please no PHPWG_ROOT_PATH. It should be relative to the root ! Let the code use PHPWG_ROOT_PATH or get_root_url depending on the page ...

would that be better? (so that we can use get_root_url().PWG_LOCAL_DIR somewhere else ?)

Code:

define(
  'PWG_LOCAL_DIR',
  isset($_SERVER['PWG_LOCAL_DIR'])
    ? $_SERVER['PWG_LOCAL_DIR']
    : 'local/'
);

@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'config/database.inc.php');
[...]
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');

Latest blog post (May 3rd 2018) New subscription form

Offline

 

#14 2011-01-14 18:03:10

rvelices
Piwigo Team
2005-12-29
1960

Re: turn the "local" directory into a configuration setting

plg wrote:

would that be better? (so that we can use get_root_url().PWG_LOCAL_DIR somewhere else ?)

Yes :). It must be used when sending to the browser combined_css and combined_url in template.php . It is required to be different if we have question_mark_in_url = false

Offline

 

#15 2011-01-17 14:50:12

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13171

Re: turn the "local" directory into a configuration setting

grum proposed me an interesting solution by private email and here is a summary:

Code:

if (is_file(local/config/multi.inc.php))
{
  include(local/config/multi.inc.php);
  // sets $conf['local_dir_site']
  define('PWG_LOCAL_DIR', $conf['local_dir_site']);
}
else
{
  define('PWG_LOCAL_DIR', 'local/');
}

@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'config/database.inc.php');

[...]

include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH.'local/config/config.inc.php');
if (isset($conf['local_dir_site']))
{
  @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
}

I really like this solution because the "local" directory is considered as the "common" local directory, at least for the config.inc.php file. This way you can have a common configuration for all your sites and a specific configuration for a given site. The local/config/multisite.inc.php is designed to fill the $conf['local_dir_site'] parameter. We will provide examples to fill it depending on the URL or on a web server parameter: this can be very flexible.


Latest blog post (May 3rd 2018) New subscription form

Offline

 
  •  » Engine
  •  » turn the "local" directory into a configuration setting

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2018 · Contact