Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-wordpress-deploy",
"description": "Deploy Wordpress without pain using Grunt.",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "https://github.com/webrain/grunt-wordpress-deploy",
"author": {
"name": "Dario Ghilardi",
Expand Down
17 changes: 12 additions & 5 deletions tasks/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ exports.init = function (grunt) {
return exclusions;
};

exports.db_adapt = function(old_url, new_url, file) {
exports.db_adapt = function(old_url, new_url, file, fn_custom_filter) {
grunt.log.oklns("Adapt the database: set the correct urls for the destination in the database.");
var content = grunt.file.read(file);

var output = exports.replace_urls(old_url, new_url, content);


if (fn_custom_filter) {
grunt.log.oklns("Applying custom filter to database.");
output = fn_custom_filter(output);
}

grunt.file.write(file, output);
};

Expand All @@ -100,9 +105,10 @@ exports.init = function (grunt) {

exports.replace_urls_in_serialized = function(search, replace, string) {
var length_delta = search.length - replace.length;
var search_regexp = new RegExp(search, 'g');

// Replace for serialized data
var matches, length, delimiter, old_serialized_data, target_string, new_url;
var matches, length, delimiter, old_serialized_data, target_string, new_url, occurences;
var regexp = /s:(\d+):([\\]*['"])(.*?)\2;/g;

while (matches = regexp.exec(string)) {
Expand All @@ -111,12 +117,13 @@ exports.init = function (grunt) {

// If the string contains the url make the substitution
if (target_string.indexOf(search) !== -1) {
occurences = target_string.match(search_regexp).length;
length = matches[1];
delimiter = matches[2];

// Replace the url
new_url = target_string.replace(search, replace);
length -= length_delta;
new_url = target_string.replace(search_regexp, replace);
length -= length_delta * occurences;

// Compose the new serialized data
var new_serialized_data = 's:' + length + ':' + delimiter + new_url + delimiter + ';';
Expand Down
4 changes: 2 additions & 2 deletions tasks/wordpressdeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function(grunt) {
util.db_dump(local_options, local_backup_paths);

// Search and Replace database refs
util.db_adapt(local_options.url, target_options.url, local_backup_paths.file);
util.db_adapt(local_options.url, target_options.url, local_backup_paths.file, target_options.filter);

// Dump target DB
util.db_dump(target_options, target_backup_paths);
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = function(grunt) {
// Dump Target DB
util.db_dump(target_options, target_backup_paths );

util.db_adapt(target_options.url,local_options.url,target_backup_paths.file);
util.db_adapt(target_options.url,local_options.url,target_backup_paths.file, local_options.filter);

// Backup Local DB
util.db_dump(local_options, local_backup_paths);
Expand Down