Skip to content

Commit

Permalink
Make farm settings more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
it-spiderman authored and osnard committed Nov 8, 2024
1 parent 0b85e7a commit b0df9ab
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ main (`w`) wiki database, as that DB holds information on all instances.

Commands are the same as for single wiki, but additional parameters in `profile.json` are required
- Set all parameters as if backing up/restoring the main farm wiki (`w`, management instance)
- Add section `farm-options` that has following items
- Add section `bluespice-farm-options` that has following items

```
{
"farm-options": {
"bluespice-farm-options": {
"instances-dir": "/var/www/w/_sf_instance",
"instance-name": "wiki-name"
}
Expand All @@ -130,7 +130,7 @@ with `profile.json`:
"dbname": "w"
}
},
"farm-options": {
"bluespice-farm-options": {
"instance-name": "*"
}
}
Expand All @@ -146,7 +146,7 @@ Since instance settings are stored in DB, when backing up, extra file `filesyste
which is then used on restore.

When restoring a farm instance, profile file __must__ be used, with `db-options.connection` set
to the main wiki database. Optionally, set `farm-options.instances-dir` to the root directory that holds instances.
to the main wiki database. Optionally, set `bluespice-farm-options.instances-dir` to the root directory that holds instances.

```json
{
Expand All @@ -158,7 +158,7 @@ to the main wiki database. Optionally, set `farm-options.instances-dir` to the r
"dbname": "w"
}
},
"farm-options": {
"bluespice-farm-options": {
"instances-dir": "/path/to/instances"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace MWStake\MediaWiki\CliAdm;

use PDO;
use RecursiveIteratorIterator;
use MWStake\MediaWiki\CliAdm\SettingsFileIterator;

class FarmInstanceSettingsManager {
class BlueSpiceFarmInstanceSettingsManager {

/**
* @var PDO
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/WikiBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DateTime;
use Exception;
use MWStake\MediaWiki\CliAdm\FarmInstanceSettingsManager;
use MWStake\MediaWiki\CliAdm\BlueSpiceFarmInstanceSettingsManager;
use MWStake\MediaWiki\CliAdm\IBackupProfile;
use MWStake\MediaWiki\CliAdm\JSONBackupProfile;
use MWStake\MediaWiki\CliAdm\DefaultBackupProfile;
Expand Down Expand Up @@ -82,7 +82,7 @@ class WikiBackup extends Command {
/** @var array */
private $skipDbPrefixes = [];

/** @var FarmInstanceSettingsManager|null */
/** @var BlueSpiceFarmInstanceSettingsManager|null */
private $farmSettingsReader = null;

/**
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function readInSettingsFile() {
}
$this->{$requiredField} = $settings[$requiredField];
}
$farmOptions = $this->profile->getFarmOptions();
$farmOptions = $this->profile->getBlueSpiceFarmOptions();
if ( $farmOptions && $farmOptions['instance-name'] ) {
$this->setupFarmEnvironment( $farmOptions );
}
Expand All @@ -232,7 +232,7 @@ private function setupFarmEnvironment( array $options ) {
throw new Exception( "Could not connect to management database: " . $ex->getMessage() );
}

$this->farmSettingsReader = new FarmInstanceSettingsManager( $mainPdo, $settingsTable );
$this->farmSettingsReader = new BlueSpiceFarmInstanceSettingsManager( $mainPdo, $settingsTable );
if ( $this->instanceName === '*' ) {
$this->output->writeln( "Backing up all instances ..." );
// Backup all instances
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/WikiRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MWStake\MediaWiki\CliAdm\Commands;

use DateTime;
use MWStake\MediaWiki\CliAdm\FarmInstanceSettingsManager;
use MWStake\MediaWiki\CliAdm\BlueSpiceFarmInstanceSettingsManager;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -88,7 +88,7 @@ class WikiRestore extends Command {

/**
*
* @var FarmInstanceSettingsManager
* @var BlueSpiceFarmInstanceSettingsManager
*/
private $farmSettingsManager = null;

Expand Down Expand Up @@ -302,12 +302,12 @@ private function setupFarmEnvironment() {
$mainDbConnectionOptions['dbpassword']
);
$settingsTable = ( $mainDbConnectionOptions['dbprefix' ] ?? '' ) . 'simple_farmer_instances';
$this->farmSettingsManager = new FarmInstanceSettingsManager( $mainPdo, $settingsTable );
$this->farmSettingsManager = new BlueSpiceFarmInstanceSettingsManager( $mainPdo, $settingsTable );
$settings = $this->farmSettingsManager->getSettingsFromFile( $instanceSettingsFile );
if ( !$settings ) {
throw new Exception( "Failed to read settings.json for farm instance" );
}
$farmOptions = $this->profile->getOptions()['farm-options'] ?? null;
$farmOptions = $this->profile->getOptions()['bluespice-farm-options'] ?? null;
$instancesDir = $farmOptions['instances-dir'] ?? $this->mediawikiRoot . '/_sf_instances';
$this->instanceName = $settings['path'];
$this->settings['dbname'] = $settings['dbname'];
Expand Down
4 changes: 2 additions & 2 deletions src/DefaultBackupProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function getDBBackupOptions() {
/**
* @inheritDoc
*/
public function getFarmOptions(): ?array {
return $this->getOption( 'farm-options' );
public function getBlueSpiceFarmOptions(): ?array {
return $this->getOption( 'bluespice-farm-options' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/IBackupProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getDBBackupOptions();
/**
* @return array|null
*/
public function getFarmOptions(): ?array;
public function getBlueSpiceFarmOptions(): ?array;

/**
* Key "db-options" should contain DB backup options.
Expand Down

0 comments on commit b0df9ab

Please sign in to comment.