GithubHelp home page GithubHelp logo

wp-media / search-and-replace Goto Github PK

View Code? Open in Web Editor NEW
89.0 23.0 35.0 3.46 MB

A simple search for find strings in your WordPress database and replace the string.

Home Page: https://wordpress.org/plugins/search-and-replace/

License: GNU General Public License v2.0

PHP 95.76% CSS 1.65% JavaScript 2.59%
wordpress-database search replace database

search-and-replace's Introduction

Search & Replace

Latest Stable Version Latest Unstable Version License Build Status

UNMAINTAINED

Note: This version of the plugin is not maintained anymore.

Description:

With Search & Replace you can search for everything and replace this with everything but before you do this you can easily create a simple database backup and restore it.

We have implemented special features!

The first one is "Replace a Domain / URL" that is useful for a quick and simple transfer or a migration of a WordPress site. The second feature is full support for serialized data. There are a lot more features - check them out! :-)

Our goal with this plugin is to give you a good solution for manipulating your data for both Developers and Users of WordPress.

Note: This plugin requires PHP 5.6 or higher to be activated.

Features

  • Search & replace data in your WordPress database
  • Change domain/URL of your WordPress installation
  • Handle serialized data
  • Choose dry run or download SQL file
  • Change table prefix
  • Backup & restore your database
  • WordPress Multisite support
  • localized and ready for your own language

Translations

Get a translation, your language from the WordPress repository and/or contribute your own language

Requirements:

PHP 5.6 + WordPress 4.x (might work with 3.x, but not tested yet)

Installation

  1. Unpack the download package.
  2. Upload the files to the /wp-content/plugins/ directory.
  3. Activate the plugin in WordPress backend.

Usage

Go to Tools -> Search & Replace to view the plugin's user interface.

screenshot-6

Backup Database tab

Urgent: Backup your database!

Please always backup your database before performing search/replace operations.

For avoiding problem please keep in mind that this plugin search and replace strictly what is specified in "Replace With".

Common error example:

Search For: http://web.com/wordpress/

Replace With: http://neuweb.com/wordpress

The url become something like: http://neuweb.com/wordpresscontent/...

Correct "Replace with":

Search For: http://web.com/wordpress/

Replace With: http://neuweb.com/wordpress/

The url become something like: http://neuweb.com/wordpress/content/...

Multisite usage:

If you are running a WordPress multisite and want to export the tables of all sites, run the plugin on the main site. Using the plugin on a subsite will only backup the tables of that subsite.

screenshot-4

Replace Domain/URL Tab

If you want to migrate your site to another domain, please enter here your new domain URL, then download a sql file with the replaced URLs. Import this file into the database of your WordPress installation on your new domain.

Please enter the new domain name including "http://" or "https://", as shown in the 'search' field.

If you want to replace the database-prefix, check the checkbox "replace database prefix" and enter your new prefix in the filed below. Don't forget to set the new prefix in the wp-config.php of your new installation!

Press Replace Domain URL button to download your SQL file for migration.

Multisite usage: If you are running multisite and want to migrate the tables of all sites, run the plugin on the main site. Using the plugin on a subsite will only migrate the tables of that subsite. The plugin will also replace the domain names (without http(s)://) in the wp_blogs table.

screenshot-2

Search and Replace Tab

Please backup your database before any search/replace!

Enter your search/replace values and select the tables you want to search. Click on "Do search/replace" to start the operation. By default, the checkbox "Dry run" is checked. In "dry run"- mode, you get a detailed preview of the changes. No changes will be written to the database. Please check always with "dry run" first. If you want to apply the changes, uncheck the "dry run"-button, choose if you want to download a sql dump with the changes, or write them into the database. Then click "do search/replace" again.

Multisite usage:

If you are running multisite and want to search the tables of all sites, run the plugin on the main site. Using the plugin on a subsite will only show the tables for that subsite.

screenshot-1

Import SQL tab

Import a SQL file or a gzipped SQL file into your database here. This may delete or change existing tables in your database. Please backup your database before doing this!

screenshot-3

License

Good news, this plugin is free for everyone! Since it's released under the GNU General Public License v2+ (or later), you can use it free of charge on your personal or commercial blog.

search-and-replace's People

Contributors

abhishekdaffodil avatar bouchaala-sabri avatar bueltge avatar bvdv avatar chrico avatar cuongdcdev avatar derpixler avatar devbanana avatar devintact avatar galileopress avatar giede avatar mvarugh avatar narek13 avatar ryantang333 avatar s-hinse avatar sherylhohman avatar tditlu avatar widoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

search-and-replace's Issues

Prepared for localization (GlotPress)

We have to prepared the Plugin for localization. At the current version the text-domain is insr for a correct GlotPress support the text-domain must be the a slug of the pluginname. In our case is this search-and-replace.

How to internationalize plugins: Text-Domain

Add "Backup DB" tab

A "Backup DB" tab should be added. Only backup without changes is possible here.

Add a database-tools tab

sometimes its useful to get quick access to a DB-Admin Tool like adminer. Lets implement a new tab called adminer and here use the plugin adminer.

search for html code gives no results

Hi,

In my wp_posts there is a field called post_content. The HTML code of the page created in WP is stored here. I need to update multiple pages with a few changes to the HTML code, and have two options. Check every page in WP editor, one-by-one, and change the code. Or, use S&R. What I am trying now is to do a Dry Run and search for:

image_alt="Some Text Here" link_type="no_link"

and eventually change that to:

image_alt="Some Text Here" link_type="page" single_item="257" open_in="current_browser"

However, when I do a search for the first criteria mentioned above, no search pattern is found. The search entered is now displayed as:

image_alt=\

It looks like the " sign is causing the problem. How can I do a succesfull S&R ?

Wordpress 4.4.2
S&R Version 3.0.0

Fix Unittest

Currently have the test a bug, that they can run.

Fixed header at review modal

On a review of a search & replace process we get this in a modal and can scroll through the result
until the end. Here we can't close the modal because the close button is scrolled away.

Solve this with fixed table header.

Constructors

Constructors should have better injection. E.g the Admin-class creates new instances of DatabaseManager, DatabaseExporter and DatabaseImporter. This is not necessary and the same instance should be reused in all classes (e.G. the Replace-class).

Examples

DatabaseManager

// current
public function __construct() {
    global $wpdb;
    $this->wpdb = $wpdb;
}

// better
public function __construct( wpdb $wpdb ) {
    $this->wpdb = $wpdb;
}

Admin / SqlImportAdmin

// current
public function __construct() {
    $this->dbm     = new DatabaseManager();
    $this->replace = new Replace( $this->dbm );
    $this->dbe     = new DatabaseExporter( $this->replace, $this->dbm );
    $this->dbi     = new DatabaseImporter();
    $this->errors  = new \WP_Error();
}

// better
public function __construct( DatabaseManager $dbm, Replace $replace, DatabaseExporter $dbe, DatabaseImporter $dbi, \WP_Error $errors ) {
    $this->dbm     = $dbm;
    $this->replace = $replace;
    $this->dbe     = $dbe;
    $this->dbi     = $dbi;
    $this->errors  = $errors;
}

DatabaseExporter

// current
public function __construct( Replace $replace, DatabaseManager $dbm ) {
    $this->errors = new \WP_Error();
    // snip
}

//  better
public function __construct( Replace $replace, DatabaseManager $dbm, \WP_Error $errors ) {
    $this->errors = $errors;
    // snip
}

Replace

// current
public function __construct( $dbm ) {
    if ( ! $dbm instanceof DatabaseManager ) {
        throw new \InvalidArgumentException ( 'Class Replace needs Object of Type DatabaseManager as Parameter' );
    }
    $this->dbm = $dbm;
}

// better
public function __construct( DatabaseManager $dbm ) {
    $this->dbm = $dbm;
}

To use multiple instances in several classes and keep the count of params in your constructors as small as possible, you could create a Container-class which holds the instances of your classes (see also PSR: https://github.com/php-fig/fig-standards/blob/master/proposed/container.md ).

Example:

$container = new Container();
$container->set( 'Manager', new DatabaseManager( $wpdb ) );

$manager = $container->get( 'Manager' ); // Instance of DatabaseManager

add .gitattributes to Build packages

We have to add a .gitattributes file what contains export-ignoreto build more less packages.

# Export the same files as the wordpress.org plugin repository
# Based on https://plugins.trac.wordpress.org/browser/search-and-replace/trunk

.git            export-ignore
.gitignore      export-ignore
.gitattributes  export-ignore

Reports|Logging - standardisation

Currently the following classes:

  • Inpsyde\SearchReplace\Database\Exporter
  • Inpsyde\SearchReplace\Database\Importer
  • Inpsyde\SearchReplace\Database\Replace

returning "report"-arrays in their methods. The response has - most of the time - following fields:

  • errors - NULL|\WP_Error|array
  • changes - string|array|null
  • tables - string|int|null|array
  • table_name - string
  • changes_count - int
  • filename - string
  • timing

  1. We should standardize the logging (reports) within these classes (e.G. Monolog). Most of the information is not used anymore and only important when an error occures. On error --> generate log file which can be downloaded - printed out (maybe can be disabled/activated via setting).
  2. The methods should return a success/fail state (true/false) for better testing. The page-classes can print out the correct notices.
  3. The classes should implement methods to grant access to generated reports for error handling (see 1.).

Multiple Workflow, runs also without WordPress

Das Plugin muss mit und Ohne WordPress ausführbar sein.

Hintergrund: Möchte der Anwender die Domain von einem Projekt ändern, kann das nicht aus einer neuen Instanz geschehen. Ohne das die Datenbank vorbereitet wurde (Domain und URL ersetzen) ist WordPress nicht ausführbar.

Anwendung:
Mit Search&Replace kann eine Datenbankdump erstellt werden in dem z.B. die Domain geändert wurde. Dieser Dump kann heruntergeladen und im Standalone-Modus importiert werden. Die für den Import nötige Datenbankverbindung wird aus der wp-config.php ausgelesen. Wichtig ist das an dieser Stelle geprüft wird ob WordPress korrekt installiert ist. Im Standalone-Modus können Datenbankinhalte auch gesucht und ersetzt werden. Es muss im Standalone-Modus entsprechend zwei Anwendungsmöglichkeiten geben. 1. Restore 2. Search&Replace.

Die Restore-Funktionalität wird es nur im Standalone-betrieb geben.

Anmerkungen:

  • Wichtig ist hier eine Absicherung des Standalone Betriebes!
  • Unnötige Redundanzen müssen vermeiden werden.

Dry Run: Keep Search and Replace values

When dry run is selected, the values in the "search" and "replace" fields should be be prefilled in the form on the result page. Probably the user wants to do a "real" replace with thes values or edit them.

switch to deactivate MaxExecutionTime

We have reported security error on systems where set_time_limit()is deactivated at the 'php.ini`.
To nevertheless get the plugin working we have to implement a option to switch off MaxExecutionTime.

Has been disabled for security reasons in ....../wp-content/plugins/search-and-replace/inc/Service/MaxExecutionTime.php on line 27

Dealing with big Databases

If user has big Databases, the plugin cannot handle this. A solution can be that we call every table with a ajax. So we get a better performance and a working status.

Another issue is that I couldn't back up my database. It seems it was too big and I had timeouts and errors. What do you think about adding an option to backup just one table in the DB?
https://wordpress.org/support/topic/php-errors-69#post-8044179

easy / expert mode

Give the UI an easy Mode where only DB-EXports with replaced data are possible. The search&replace functionality could also be restricted to replacing the blog-URl as found in the DB with a new one.
In expert mode, all funtionality is provided. The app should warn that wrong actions here could destroy things...

SQL Error on import

In exported databases we create tables wit the following sql.

CREATE TABLE `i_5_postmeta` (
  `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `post_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  `meta_key` varchar(255) DEFAULT NULL,
  `meta_value` longtext,
  PRIMARY KEY (`meta_id`),
  KEY `post_id` (`post_id`),
  KEY `meta_key` (`meta_key`(191))
) TYPE=InnoDB AUTO_INCREMENT=309 ;

On import this throws a error

#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 
'TYPE=InnoDB AUTO_INCREMENT=19815' at line 13

Solution: Replace TYPE=InnoDB with Engine=InnoDB

Composer: Use PSR-Autoloading

The autoloading class Inpsyde\searchReplace\inc\Autoloader could be replaced by composer and PSR-Autoloading. Just include the /vendor/autoload.php after composer install.

Detecte Searchpattern

Wenn ein Endanwender Daten in der Datenbank suchen und ersetzten will gibt es bestimmte Fälle in den ein mehrfaches durchlaufen nötig wird. Es gilt diese zu erkennen und dies dem Anwender zu Kommunizieren.

Beispiel:
Es soll die Domain geändert werden, dabei werden mindestens 2 Durchläufe nötig.

    1. Suche nach http://www.domain.de
    1. Suche nach www.domain.de

Remove namespace from main Plugin file

We try to detect lower php version but we cant detect lower version if we had the namespace declaration in the main plugin file.

Parse error: syntax error, unexpected T_STRING in ~/wordpress/wp-content/plugins/search-and-replace/inspyde-search-replace.php on line 16

Set visibility for functions

Some functions have no visibility. To search for them you can use this regex
(?<![private|public|protected|static]\s)function\s.*?\(.*?\)\s

remove redundant code

The handling of admin pages are very prone for errors because the code repeats oneself.

Look at the tabs, we have the same markup on 5 different files:
https://github.com/inpsyde/search-and-replace/tree/3.0.1/src/inc/templates

    <h2 class="nav-tab-wrapper">
        <a class="nav-tab" href="<?php echo admin_url() ?>/tools.php?page=sqlesc_html_export"><?php esc_html_e( 'Backup Database', 'insr' ); ?></a>
        <a class="nav-tab" href="<?php echo admin_url() ?>/tools.php?page=replace_domain"><?php esc_html_e( 'Replace Domain/URL', 'insr' ); ?></a>
        <a class="nav-tab" href="<?php echo admin_url() ?>/tools.php?page=inpsyde_search_replace"><?php esc_html_e( 'Search and replace', 'insr' ); ?></a>
        <a class="nav-tab" href="<?php echo admin_url() ?>/tools.php?page=sql_import"><?php esc_html_e( 'Import SQL file', 'insr' ); ?></a>
        <a class="nav-tab nav-tab-active" href="<?php echo admin_url() ?>/tools.php?page=credits"><?php esc_html_e( 'Credits', 'insr' ); ?></a>
    </h2>

Go a head to src/inc/Init.php here we have identical functions.
https://github.com/inpsyde/search-and-replace/blob/3.0.1/src/inc/Init.php

    /**
     *callback function for db backup  page
     */
    public function show_db_backup_page() {

        $export_admin = new DbBackupAdmin();
        $export_admin->show_page();
    }

    /**
     *callback function for replace domain page
     */
    public function show_replace_domain_page() {

        $export_admin = new ReplaceDomainAdmin();
        $export_admin->show_page();
    }

    /**
     *callback function for import page
     */
    public function show_import_page() {

        $import_admin = new SqlImportAdmin();
        $import_admin->show_page();
    }

    /**
     *callback function for import page
     */
    public function show_credits_page() {

        $import_admin = new CreditsAdmin();
        $import_admin->show_page();
    }

TODO: Reduce code and implement better tab handling.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.