Skip to content

Commit

Permalink
General fixes for multi sites, issue #89
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Josson committed Mar 5, 2015
1 parent 7164002 commit dc59a6f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 20 deletions.
2 changes: 1 addition & 1 deletion arlima.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://github.com/victorjonsson/Arlima
Description: Manage the order of posts on your front page, or any page you want. This is a plugin suitable for online newspapers that's in need of a fully customizable front page.
Author: VK (<a href="http://twitter.com/chredd">@chredd</a>, <a href="http://twitter.com/znoid">@znoid</a>, <a href="http://twitter.com/victor_jonsson">@victor_jonsson</a>, <a href="http://twitter.com/lefalque">@lefalque</a>)
Version: 3.1.beta.42
Version: 3.1.beta.43
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Expand Down
6 changes: 6 additions & 0 deletions classes/CMSInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ function getDBPrefix();
*/
function runSQLQuery($sql);

/**
* @param string $tbl
* @return bool
*/
function dbTableExists($tbl);



/* * * * POSTS / PAGES * * */
Expand Down
11 changes: 11 additions & 0 deletions classes/WP/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ public function runSQLQuery($sql)
}
}

/**
* @param string $tbl
* @return bool
*/
public function dbTableExists($tbl)
{
$this->wpdb->query('SHOW TABLES LIKE \''.$tbl.'\'');
return $this->wpdb->num_rows == 1;
}

/**
* Flush all caches affecting arlima
* @return void
Expand All @@ -338,6 +348,7 @@ public function flushCaches()

/* * * Relation between lists and posts * * * * */


const META_KEY_LIST = '_arlima_list';
const META_KEY_ATTR = '_arlima_list_data';

Expand Down
67 changes: 51 additions & 16 deletions classes/WP/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function init()
if( is_admin() ) {

// Register install/uninstall procedures
add_action('activate_arlima/arlima.php', 'Arlima_WP_Plugin::install');
add_action('deactivate_arlima/arlima.php', 'Arlima_WP_Plugin::deactivate');
register_activation_hook('arlima/arlima.php', 'Arlima_WP_Plugin::install');
register_deactivation_hook('arlima/arlima.php', 'Arlima_WP_Plugin::deactivate');
register_uninstall_hook('arlima/arlima.php', 'Arlima_WP_Plugin::uninstall');

// Add actions and filters used in wp-admin
Expand Down Expand Up @@ -376,6 +376,20 @@ function addExportFeeds()
add_feed(self::EXPORT_FEED_NAME, array($this, 'loadExportFeed'));
}

/**
* @param Arlima_AbstractRepositoryDB[] $repos
* @return bool
*/
static function hasCreatedDBTables($repos)
{
$has_tables = false;
foreach($repos[0]->getDatabaseTables() as $table) {
$has_tables = Arlima_CMSFacade::load()->dbTableExists($table);
break;
}
return $has_tables;
}

/**
* Install procedure for this plugin
* - Adds database tables
Expand All @@ -386,23 +400,35 @@ function addExportFeeds()
*/
public static function install()
{
// Add db tables
foreach(self::loadRepos() as $repo) {
$repo->createDatabaseTables();
if( is_network_admin() ) {
throw new Exception('You can not install Arlima for an entire multi-site network.');
}

// Add feed
global $wp_rewrite;
$plugin = new self();
$plugin->addExportFeeds();
$wp_rewrite->flush_rules();
$repos = self::loadRepos();

// Add settings
$plugin = new self();
$settings = $plugin->loadSettings();
$settings['install_version'] = ARLIMA_PLUGIN_VERSION;
$settings['image_quality'] = 100;
$plugin->saveSettings($settings);
if( self::hasCreatedDBTables($repos) ) {
self::update();
}
else {

// Add db tables
foreach($repos as $repo) {
$repo->createDatabaseTables();
}

// Add feed
global $wp_rewrite;
$plugin = new self();
$plugin->addExportFeeds();
$wp_rewrite->flush_rules();

// Add settings
$plugin = new self();
$settings = $plugin->loadSettings();
$settings['install_version'] = ARLIMA_PLUGIN_VERSION;
$settings['image_quality'] = 100;
$plugin->saveSettings($settings);
}
}

/**
Expand Down Expand Up @@ -446,6 +472,11 @@ public static function update()
$plugin = new self();
$current_version = $plugin->getSetting('install_version', 0);

if( is_multisite() && !self::hasCreatedDBTables(self::loadRepos()) ) {
self::install();
return;
}

// Time for an update
if ( $current_version !== ARLIMA_PLUGIN_VERSION ) {

Expand All @@ -459,6 +490,10 @@ public static function update()
$settings['editor_sections'] = '';
}

if( $current_version < 3.1 ) {
delete_option('arlima_db_version');
}

// Let the repos do their thang
foreach(self::loadRepos() as $repo) {
$repo->updateDatabaseTables($current_version_float);
Expand Down
3 changes: 3 additions & 0 deletions classes/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>abstract applyFilters()</strong> : <em>mixed</em><br /><em>Filter data</em> |
| public | <strong>abstract currentVisitorCanEdit()</strong> : <em>bool</em><br /><em>Tells whether or not current website visitor can edit pages/posts</em> |
| public | <strong>abstract dbEscape(</strong><em>string</em> <strong>$input</strong>)</strong> : <em>string</em><br /><em>Make string safe for use in a database query</em> |
| public | <strong>abstract dbTableExists(</strong><em>string</em> <strong>$tbl</strong>)</strong> : <em>bool</em> |
| public | <strong>abstract doAction()</strong> : <em>void</em><br /><em>Invoke a system event</em> |
| public | <strong>abstract flushCaches()</strong> : <em>void</em><br /><em>Flush all caches affecting arlima</em> |
| public | <strong>abstract generateImageVersion(</strong><em>string</em> <strong>$file</strong>, <em>string</em> <strong>$attach_url</strong>, <em>int</em> <strong>$max_width</strong>, <em>int</em> <strong>$img_id</strong>)</strong> : <em>string</em><br /><em>Generate an image version of given file with given max width (resizing image). Returns the $attach_url if not possible to create image version</em> |
Expand Down Expand Up @@ -666,6 +667,7 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>applyFilters()</strong> : <em>mixed</em><br /><em>Filter data</em> |
| public | <strong>currentVisitorCanEdit()</strong> : <em>bool</em><br /><em>Tells whether or not current website visitor can edit pages/posts</em> |
| public | <strong>dbEscape(</strong><em>string</em> <strong>$input</strong>)</strong> : <em>string</em><br /><em>Make string safe for use in a database query</em> |
| public | <strong>dbTableExists(</strong><em>string</em> <strong>$tbl</strong>)</strong> : <em>bool</em> |
| public | <strong>doAction()</strong> : <em>mixed</em><br /><em>Invoke a system event</em> |
| public | <strong>flushCaches()</strong> : <em>void</em><br /><em>Flush all caches affecting arlima</em> |
| public | <strong>generateImageVersion(</strong><em>string</em> <strong>$file</strong>, <em>string</em> <strong>$attach_url</strong>, <em>int</em> <strong>$max_width</strong>, <em>int</em> <strong>$img_id</strong>)</strong> : <em>string</em><br /><em>Generate an image version of given file with given max width (resizing image). Returns the $attach_url if not possible to create image version</em> |
Expand Down Expand Up @@ -807,6 +809,7 @@ isInScheduledInterval('*:*'); // All days of the week and all hours of the day
| public | <strong>getSetting(</strong><em>string</em> <strong>$name</strong>, <em>bool</em> <strong>$default=false</strong>)</strong> : <em>mixed</em> |
| public static | <strong>getTemplateCSS()</strong> : <em>string</em><br /><em>Get the path to the CSS file that controls the presentation of articles in an arlima list</em> |
| public | <strong>getTemplateStylesheets()</strong> : <em>array</em> |
| public static | <strong>hasCreatedDBTables(</strong><em>[\Arlima_AbstractRepositoryDB](#class-arlima_abstractrepositorydb-abstract)[]</em> <strong>$repos</strong>)</strong> : <em>bool</em> |
| public | <strong>init()</strong> : <em>void</em> |
| public | <strong>initAdminActions()</strong> : <em>void</em><br /><em>Actions added in wp-admin</em> |
| public | <strong>initThemeActions()</strong> : <em>void</em><br /><em>Actions added in the theme</em> |
Expand Down
2 changes: 1 addition & 1 deletion constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
or define('ARLIMA_COMPILE_LESS_IN_BROWSER', ARLIMA_DEV_MODE);

// Plugin version (only edit this via grunt!)
define('ARLIMA_PLUGIN_VERSION', '3.1.beta.42');
define('ARLIMA_PLUGIN_VERSION', '3.1.beta.43');
define('ARLIMA_FILE_VERSION', ARLIMA_PLUGIN_VERSION .(ARLIMA_DEV_MODE ? '__'.time():''));

// Which type of tag to use for images in Arlima RSS feeds
Expand Down
2 changes: 1 addition & 1 deletion js/arlima/arlima.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: @chredd, @znoid, @victor_jonsson, @lefalque, @aaslun
Tags: CMS, e-paper, e-magazine, magazine, newspaper, front page, wysiwyg
Requires at least: 3.8
Tested up to: 3.9.1
Stable tag: 3.1.beta.42
Stable tag: 3.1.beta.43
License: GPL2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down

0 comments on commit dc59a6f

Please sign in to comment.