diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e09b844 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index 5df1b9b..e675067 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.sass-cache +/vendor/ +*.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8fa2459 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: php +php: + - '5.4' + - nightly +install: composer install +script: composer test diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d7f1051 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md new file mode 100755 index 0000000..c131f70 --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# WP Sync DB + +WP Sync DB eliminates the manual work of migrating a WP database. Copy your db from one WP install to another with a single-click in your dashboard. Especially handy for syncing a local development database with a live site. + +

+ +## Looking for a Maintainer + +I've moved away from PHP & WordPress work and don't have time to maintain this. If you're a talented PHP developer I'd be happy to give you this repo. Grab the latest code from [delicious-brains](https://github.com/wp-sync-db/wp-sync-db/tree/delicious-brains), remove the license checking, branding, & other cruft, and open up a PR to show me your work. + +## Description + +WP Sync DB exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer, or send it directly to another WordPress instance. It is perfect for developers who develop locally and need to move their WordPress site to a staging or production server. + +### Selective Sync + +WP Sync DB lets you choose which DB tables are migrated. Have a huge analytics table you'd rather not send? Simply deselect it and it won't be synced. + +### Bi-directional Sync + +#### Pull: Replace a Local DB with a Remote DB + +If you have a test site setup locally but you need the latest data from the production server, just install WP Sync DB on both sites and you can pull the live database down, replacing your local database in just a few clicks. + +#### Push: Replace a Remote DB with a Local DB + +If you're developing a new feature for a site that's already live, you likely need to tweak your settings locally before deploying. Once you've perfected your configuration on your development machine, it's easy to send the settings to your production server. Just push to the server, replacing your remote database with your local one. + +### Database Export & Backup + +Not only can WP Sync DB pull and push your DB: it can export your DB to an SQL file that you can save and backup wherever you want. No need to ssh into your machine or open up phpMyAdmin. + +### Encrypted Transfers + +All data is sent over SSL to prevent your database from being read during the transfer. WP Sync DB also uses HMAC encryption to sign and verify every request. This ensures that all requests are coming from an authorized server and haven't been tampered with en route. + +### Automatic Find & Replace + +When migrating a WordPress site, URLs in the content, widgets, menus, etc need to be updated to the new site's URL. Doing this manually is annoying, time consuming, and very error-prone. WP Sync DB does all of this for you. + +### Stress Tested on Massive Sites + +Huge database? No prob. WP Sync DB has been tested with tables several GBs in size. + +### Detect Limitations Automatically + +WP Sync DB checks both the remote and local servers to determine limitations and optimize for performance. For example, we detect the MySQL `max_allowed_packet_size` and adjust how much SQL we execute at a time. + +### Sync Media Libraries Between Installations + +Using the optional [WP Sync DB Media Files](https://github.com/wp-sync-db/wp-sync-db-media-files) addon, you can have media files synced between installs too. + +## Installation + +1. Install [github-updater](https://github.com/afragen/github-updater) by downloading the latest zip [here](https://github.com/afragen/github-updater/releases). We rely on this plugin for updating WP Sync DB directly from this git repo. +2. Install WP Sync DB by downloading the latest zip [here](https://github.com/wp-sync-db/wp-sync-db/releases). Both github-updater and WP Sync DB will now download their own updates automatically, so you will never need to go through that tedious zip downloading again. +3. Access the WP Sync DB menu option under Tools. +4. Install the optional [WP Sync DB Media Files](https://github.com/wp-sync-db/wp-sync-db-media-files) addon. + +## Help Videos + +### Feature Walkthrough + + + +A brief walkthrough of the WP Sync DB plugin showing all of the different options and explaining them. + +### Pulling Live Data Into Your Local Development Environment + + + +This screencast demonstrates how you can pull data from a remote, live WordPress install and update the data in your local development environment. + +### Pushing Local Development Data to a Staging Environment + + + +This screencast demonstrates how you can push a local WordPress database you've been using for development to a staging environment. + +### Media Files Addon Demo + + + +A short demo of how the [Media Files addon](https://github.com/wp-sync-db/wp-sync-db-media-files) allows you to sync up your WordPress Media Libraries. + +## Similar Tools + +- [Interconnect IT's Search & Replace](https://github.com/interconnectit/Search-Replace-DB) + +## Isn't this the same as WP Migrate DB Pro? + +No, of course not, don't be silly. I took out the license verification code, a really shady looking PressTrends reporter, and the tab for installing the Media Files addon before I published 1.4. Release 1.3 was the same as [WP Migrate DB Pro](https://deliciousbrains.com/wp-migrate-db-pro), but I've made several improvements since then. + +## Is this Illegal? + +**No.** Just because this is based on the paid-for WP Migrate DB Pro, it doesn't mean I can't release it. WP Migrate DB Pro is released under GPLv2, a copyleft license that guarantees my freedom (and the freedom of all users) to copy, distribute, and/or modify this software. + +I _was_ forced to rename it from "WP Migrate DB" to "WP Sync DB" after Delicious Brains decided to trademark the name "WP Migrate DB", [filed a DMCA takedown](http://wptavern.com/dmca-takedown-notice-issued-against-fork-of-wp-migrate-db-pro) against the repo, and threatened to take me to court. But they should be OK with it now. diff --git a/asset/config.rb b/asset/config.rb deleted file mode 100644 index f89f6ca..0000000 --- a/asset/config.rb +++ /dev/null @@ -1,24 +0,0 @@ -# Require any additional compass plugins here. - -# Set this to the root of your project when deployed: -http_path = "/" -css_dir = "css" -sass_dir = "sass" -images_dir = "img" -javascripts_dir = "js" - -# You can select your preferred output style here (can be overridden via the command line): -# output_style = :expanded or :nested or :compact or :compressed - -# To enable relative paths to assets via compass helper functions. Uncomment: -# relative_assets = true - -# To disable debugging comments that display the original location of your selectors. Uncomment: -# line_comments = false - - -# If you prefer the indented syntax, you might want to regenerate this -# project again passing --syntax sass, or you can uncomment this: -# preferred_syntax = :sass -# and then run: -# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass diff --git a/asset/css/styles.css b/asset/css/styles.css old mode 100644 new mode 100755 index 4fcc717..81dcc19 --- a/asset/css/styles.css +++ b/asset/css/styles.css @@ -1,184 +1,1272 @@ -/* line 1, ../sass/styles.scss */ -#migrate-form { - padding-top: 10px; +#wpsdb-main { + width: 742px; } -/* line 9, ../sass/styles.scss */ -.form-table .row-new-url th, .form-table .row-new-url td, -.form-table .row-new-path th, -.form-table .row-new-path td, -.form-table .row-revisions th, -.form-table .row-revisions td { - padding-bottom: 20px; +#overlay { + background-color: rgba(255, 255, 255, 0.9); +} + +.wpsdb { + /* ============================================================================= + Common & Global + ========================================================================== */ + /* ============================================================================= + Migrate Tab + ========================================================================== */ + /* Misc */ + /* Tabs */ + /* Saved migration profile selection */ + /* Output Selection */ + /* Find and Replace */ + /* Select Tables */ + /* Advanced Options */ + /* Save migration profile */ + /* Action buttons */ + /* ============================================================================= + Settings Tab + ========================================================================== */ + /* ============================================================================= + Help Tab + ========================================================================== */ + /* ============================================================================= + Addons Tab + ========================================================================== */ +} +.wpsdb .updated { + clear: both; +} +.wpsdb div.updated.warning { + max-width: 742px; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + margin: 10px 0; +} +.wpsdb div.updated.warning p { + font-size: 13px; + margin: 0.5em 0; +} +.wpsdb a { + text-decoration: none; +} +.wpsdb li { + margin-bottom: 5px; + position: relative; +} +.wpsdb ul { + margin: 0; +} +.wpsdb input[type=checkbox], +.wpsdb input[type=radio] { + margin-right: 5px; + vertical-align: baseline; + margin-top: 0; +} +.wpsdb input[type=text], +.wpsdb input[type=password] { + padding: 5px; +} +.wpsdb input[disabled=disabled] { + cursor: default; +} +.wpsdb label.disabled { + color: #888; + cursor: default; +} +.wpsdb .option-section { border-bottom: 1px solid #ccc; + padding-bottom: 20px; + margin-bottom: 20px; } -/* line 18, ../sass/styles.scss */ -.form-table .row-old-path th, .form-table .row-old-path td, -.form-table .row-save-file th, -.form-table .row-save-file td, -.form-table .row-guids th, -.form-table .row-guids td { - padding-top: 20px; +.wpsdb .option-section h3 { + font-size: 18px; + font-weight: normal; } - -/* line 24, ../sass/styles.scss */ -p.submit { +.wpsdb p.migrate-db { overflow: hidden; - padding-top: 20px; - border-top: 1px solid #ccc; - margin-top: 20px; } -/* line 30, ../sass/styles.scss */ -p.submit input { +.wpsdb p.migrate-db input { float: left; } -/* line 34, ../sass/styles.scss */ -p.submit img { +.wpsdb p.migrate-db img { float: left; margin: 3px 0 0 5px; } - -/* line 40, ../sass/styles.scss */ -#wpmdb-container { +.wpsdb p.migrate-db .save-settings-button { + margin-left: 10px; + display: none; +} +.wpsdb .indent-wrap { + margin-left: 24px; +} +.wpsdb .expandable-content { + display: none; + margin-top: 10px; +} +.wpsdb .expandable-content li:last-child { + margin-bottom: 0px; +} +.wpsdb .header-wrapper { + margin-bottom: 10px; +} +.wpsdb .header-expand-collapse { + cursor: pointer; + display: inline-block; +} +.wpsdb .option-description { + font-size: 12px; + color: #999; + margin-left: 8px; + font-weight: normal; +} +.wpsdb .option-group li:last-child { + margin-bottom: 0; +} +.wpsdb .connection-status { + display: none; + overflow: auto; +} +.wpsdb .connection-status.error { + color: #9D1818; +} +.wpsdb .ajax-spinner { + left: 6px; position: relative; + top: 3px; } - -/* line 44, ../sass/styles.scss */ -#wpmdb-main { - margin-right: 320px; - min-height: 1200px; +.wpsdb div.message { + margin: 15px 0 0; } - -/* line 49, ../sass/styles.scss */ -#wpmdb-sidebar { +.wpsdb .return-to-profile-selection { + margin-bottom: 15px; + display: inline-block; +} +.wpsdb .return-to-profile-selection.bottom { + margin-top: 10px; +} +.wpsdb h2.nav-tab-wrapper { + margin-top: 10px; + margin-bottom: 20px; + padding-left: 5px; +} +.wpsdb h2.nav-tab-wrapper a { + margin-right: 4px; +} +.wpsdb h2.nav-tab-wrapper a.nav-tab-active { + color: #464646; + cursor: default; +} +.wpsdb label { + display: inline-block; + clear: both; +} +.wpsdb .migration-profile-options li { + position: relative; + width: 520px; +} +.wpsdb .migration-profile-options li a { + padding: 5px 10px; + width: 500px; + border: 1px solid #ddd; + margin: 0px 0px 7px; + display: block; + font-size: 14px; + color: #333; +} +.wpsdb .migration-profile-options li a:hover { + border-color: #bbb; +} +.wpsdb .main-list-delete-profile-link { + color: #999999; + font-family: "Times New Roman", serif; + font-size: 26px; + font-weight: 200; position: absolute; - top: 0; - right: 0; - width: 250px; + right: 7px; + top: 6px; + cursor: pointer; +} +.wpsdb .main-list-delete-profile-link:hover { + color: #444; +} +.wpsdb .option-group li { + margin-bottom: 5px; +} +.wpsdb .option-group > li { + margin-bottom: 8px; +} +.wpsdb .option-group li > label { + font-size: 14px; + font-weight: bold; +} +.wpsdb .option-group ul { + display: none; + margin: 10px 0px 10px 25px; +} +.wpsdb .option-group ul label { + font-size: 12px; + font-weight: normal; +} +.wpsdb .option-heading, .wpsdb .checkbox-label { + font-size: 14px; + font-weight: bold; +} +.wpsdb .checkbox-label input[type=checkbox] { + margin-right: 7px; + position: relative; + top: -1px; +} +.wpsdb .expand-collapse-arrow { + margin-right: 9px; +} +.wpsdb .migrate-connection-info { + min-width: 675px; + margin: 0; +} +.wpsdb .migrate-tab .pull-push-connection-info { + width: 418px; + height: 65px; + color: #333; + font-family: Consolas, Monaco, monospace; + font-size: 15px; + line-height: 21px; + padding: 10px; +} +.wpsdb .basic-access-auth-wrapper { + display: none; + margin-bottom: 5px; +} +.wpsdb .auth-username, .wpsdb .auth-password { + width: 206px; + margin-top: 3px; +} +.wpsdb .auth-password { + width: 207px; +} +.wpsdb .connection-info-wrapper { + display: none; + width: 670px; +} +.wpsdb .connect-button { + margin-top: 2px; +} +.wpsdb .temp-disabled { + background-color: #EEEEEE; + color: #888888; + font-family: Consolas, Monaco, monospace; + text-shadow: 0 1px 0 #FFFFFF; +} +.wpsdb .push-list ul { + margin-bottom: 0px; +} +.wpsdb .find-heading, .wpsdb .replace-heading { + float: left; +} +.wpsdb .find-heading { + width: 400px; +} +.wpsdb .replace-fields { + border-collapse: collapse; + border-spacing: 0px; +} +.wpsdb .replace-fields input { + width: 295px; +} +.wpsdb .replace-fields tr td { + padding-bottom: 7px; +} +.wpsdb .replace-fields tr:last-child td { + padding-bottom: 0px; +} +.wpsdb .arrow-col { + width: 93px; + text-align: center; + vertical-align: middle; +} +.wpsdb .right-arrow { + font-size: 36px; + color: #aaa; + font-family: arial, sans-serif; +} +.wpsdb .replace-right-col span { + border-radius: 50%; border: 1px solid #ccc; - padding: 20px; + background-color: #eee; + width: 16px; + height: 16px; + display: inline-block; + position: relative; + top: 4px; + cursor: pointer; } -/* line 57, ../sass/styles.scss */ -#wpmdb-sidebar .author { - padding-bottom: 20px; - margin-bottom: 20px; - border-bottom: 1px solid #ccc; - overflow: hidden; +.wpsdb .replace-right-col span:hover { + border-color: #aaa; +} +.wpsdb .sort-handle-col { + width: 20px; + cursor: -webkit-grab; + cursor: -moz-grab; +} +.wpsdb .sort-handle:before { + content: "\f214"; + display: inline-block; + -webkit-font-smoothing: antialiased; + font: normal 16px/1 'dashicons'; + vertical-align: top; + color: #aaa; + background-color: transparent !important; +} +.wpsdb .original-repeatable-field { + display: none; +} +.wpsdb .no-replaces-message { + display: none; + margin-bottom: 0px; } -/* line 63, ../sass/styles.scss */ -#wpmdb-sidebar .author img { +.wpsdb .inline-message.missing-replace { + margin-top: 15px; + display: none; +} +.wpsdb #new-path-missing-warning { + margin-top: 5px; +} +.wpsdb .tables-header { + display: inline-block; +} +.wpsdb .expand-collapse-arrow { + display: inline-block; + position: relative; + top: -2px; + font-size: 11px; +} +.wpsdb .collapsed { + -moz-transform: scale(1) rotate(-90deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg); + -webkit-transform: scale(1) rotate(-90deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg); + -o-transform: scale(1) rotate(-90deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg); + -ms-transform: scale(1) rotate(-90deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg); + transform: scale(1) rotate(-90deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg); +} +.wpsdb .select-deselect-divider { + margin: 0 6px; +} +.wpsdb .select-wrap { + display: none; + margin-top: 12px; +} +.wpsdb .select-post-types-wrap { + display: block; +} +.wpsdb .multiselect { + min-width: 420px; + min-height: 180px; + margin-bottom: 10px; +} +.wpsdb .table-migrate-options li label { + font-size: 12px; + font-weight: normal; +} +.wpsdb .table-migrate-options li { + margin-bottom: 5px; +} +.wpsdb .general-helper { + border-radius: 50%; + border: 1px solid #ccc; + background-color: #eee; + width: 15px; + height: 15px; + display: inline-block; + position: relative; + top: 4px; + margin-top: -4px; + cursor: pointer; + margin-left: 2px; +} +.wpsdb .general-helper:hover { + border-color: #aaa; +} +.wpsdb .general-helper:after { + content: "?"; + color: #999999; + font-size: 10px; + font-weight: bold; + left: 4px; + position: absolute; + top: -1px; +} +.wpsdb .helper-message { + padding: 10px; + border: 1px solid #ccc; + border-radius: 3px; + background-color: #fff; + position: absolute; + width: 500px; + z-index: 9999; + display: none; + box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2); +} +.wpsdb .inline-message { + padding: 10px; + border-radius: 3px; + margin-top: 5px; +} +.wpsdb .inline-message.error { + border: 1px solid #CC0000; + background-color: #FFEBE8; +} +.wpsdb .inline-message.warning { + background-color: #FFFFE0; + border: 1px solid #E6DB55; +} +.wpsdb .helper-message:before { + content: ''; + border-bottom: 8px solid transparent; + border-right: 8px solid #aaa; + border-top: 8px solid transparent; + display: block; + height: 0; + left: -8px; + position: absolute; + top: 11px; + width: 0; +} +.wpsdb .helper-message:after { + content: ''; + border-bottom: 8px solid transparent; + border-right: 8px solid #fff; + border-top: 8px solid transparent; + display: block; + height: 0; + left: -7px; + position: absolute; + top: 11px; + width: 0; +} +.wpsdb .helper-message.bottom:before { + content: ''; + border-left: 8px solid transparent; + border-right: 8px solid transparent; + border-bottom: 8px solid #aaa; + border-top: 0; + display: block; + height: 0; + left: 50%; + margin-left: -8px; + position: absolute; + top: -9px; + width: 0; +} +.wpsdb .helper-message.bottom:after { + content: ''; + border-left: 8px solid transparent; + border-right: 8px solid transparent; + border-bottom: 8px solid #fff; + border-top: 0; + display: block; + height: 0; + left: 50%; + margin-left: -8px; + position: absolute; + top: -8px; + width: 0; +} +.wpsdb .label-disabled { + color: #888; +} +.wpsdb .prefix-notice, .wpsdb .ssl-notice, .wpsdb .different-plugin-version-notice, .wpsdb .directory-permission-notice { + background-color: #FFFFE0; + border: 1px solid #E6DB55; + padding: 15px; + border-radius: 3px; + margin-bottom: 15px; + display: none; +} +.wpsdb .prefix-notice p, .wpsdb .ssl-notice p, .wpsdb .different-plugin-version-notice p, .wpsdb .directory-permission-notice p { + margin-top: 0px; +} +.wpsdb .prefix-notice p:last-child, .wpsdb .ssl-notice p:last-child, .wpsdb .different-plugin-version-notice p:last-child, .wpsdb .directory-permission-notice p:last-child { + margin: 0px; +} +.wpsdb .different-plugin-version-notice, .wpsdb .directory-permission-notice { + background-color: #FFEBE8; + border-color: #CC0000; +} +.wpsdb .different-plugin-version-notice a, .wpsdb .directory-permission-notice a { + color: #CC0000; + text-decoration: underline; +} +.wpsdb .save-migration-profile-wrap li label { + font-size: 12px; + font-weight: normal; +} +.wpsdb .save-migration-profile-wrap li { + margin-bottom: 5px; + padding-left: 25px; +} +.wpsdb .save-migration-profile-wrap .indent-wrap { + margin-left: 0px; +} +.wpsdb .create-new-label { + margin-right: 8px; +} +.wpsdb .create-new-profile { + position: absolute; + top: -5px; +} +.wpsdb .replace-remove-row, +.wpsdb .delete-profile { + background-color: #eee; + border: 1px solid #ccc; + border-radius: 50% 50% 50% 50%; + cursor: pointer; + height: 11px; + left: 5px; + margin-left: 2px; + position: absolute; + margin-top: -6px; + top: 50%; + width: 11px; + display: none; + background-position: 50% 50%; + background-size: 6px 6px; + background-repeat: no-repeat; +} +.wpsdb .replace-remove-row:after, +.wpsdb .delete-profile:after { + content: "\00d7"; + left: 2px; + position: absolute; + top: -3px; + color: #aaa; + font-size: 12px; +} +.wpsdb .replace-remove-row:after { + position: relative; +} +.wpsdb .replace-remove-row:hover, +.wpsdb .delete-profile:hover { + border-color: #aaa; +} +.wpsdb .migrate-db .ajax-success-msg { + font-weight: bold; + margin: 3px 0 0 9px; + display: inline-block; +} +.wpsdb p img.save-profile-ajax-spinner { + margin-left: 10px; +} +.wpsdb .backup-description { + left: 20px; + position: relative; +} +.wpsdb .backup-option-disabled { + margin-bottom: 0px !important; +} +.wpsdb .settings-tab { + display: none; +} +.wpsdb .settings-tab .slider { + max-width: 416px; +} +.wpsdb .settings-tab .slider-label { + display: block; + margin-bottom: 10px; float: left; - margin-right: 20px; + width: 50%; } -/* line 68, ../sass/styles.scss */ -#wpmdb-sidebar .author .desc { +.wpsdb .settings-tab .slider-label-wrapper { + max-width: 416px; + width: 100%; + position: relative; +} +.wpsdb .settings-tab .amount { + width: 50%; + text-align: right; + display: block; + text-align: right; float: left; } -/* line 72, ../sass/styles.scss */ -#wpmdb-sidebar .author h3 { +.wpsdb .settings-tab .slider-spinner { + position: absolute; + right: -35px; + bottom: -13px; +} +.wpsdb .settings-tab .slider-success-msg { + display: none; + right: -53px; + bottom: -13px; + position: absolute; + font-weight: bold; +} +.wpsdb .settings-tab .ui-slider { + border: 1px solid #dfdfdf; + height: 10px; + border-radius: 2px; + position: relative; +} +.wpsdb .settings-tab .ui-slider-handle { + width: 7px; + height: 20px; + background-color: #aaa; + display: block; + position: absolute; + top: -5px; + outline: none; +} +.wpsdb .settings-tab .ui-slider-handle:active { + background-color: #999; +} +.wpsdb .settings-tab .ui-slider-range { + background-color: #eee; + height: 100%; +} +.wpsdb .settings-tab .option-section li label { font-size: 12px; - margin: 0; + font-weight: normal; + position: relative; +} +.wpsdb .settings-tab .option-section li { + margin-bottom: 5px; +} +.wpsdb .settings-tab .option-section li:last-child { + margin-bottom: 0px; +} +.wpsdb .settings-tab .option-section .ajax-spinner { + right: -23px; + left: inherit; + top: 0px; + position: absolute; } -/* line 77, ../sass/styles.scss */ -#wpmdb-sidebar .author h2 { +.wpsdb .settings-tab .option-section .ajax-success-msg { + right: -42px; + left: inherit; + top: 0px; + position: absolute; + font-weight: bold; +} +.wpsdb .settings-tab .option-section .bubble .ajax-spinner { + right: -45px; +} +.wpsdb .settings-tab .option-section .bubble .ajax-success-msg { + right: -65px; +} +.wpsdb .allow-remote-reqeusts { + font-size: 14px; + font-weight: bold; +} +.wpsdb .connection-info-label { + margin-top: 15px; + margin-bottom: 5px; + display: block; +} +.wpsdb .connection-info { + clear: both; + font-size: 15px; + line-height: 21px; + font-family: Consolas, Monaco, monospace; + padding: 10px 10px; + height: 67px; + text-shadow: 0px 1px 0px #fff; + display: block; + margin-bottom: 7px; + width: 418px; +} +.wpsdb .reset-button-wrap { + width: 418px; +} +.wpsdb .reset-api-key { + float: left; +} +.wpsdb .reset-api-key-ajax-spinner { + float: left; + margin: 4px 7px; +} +.wpsdb .plugin-compatibility-wrap { + padding: 18px 18px 18px 24px; + background-color: #e6e6e6; + margin-left: 0; +} +.wpsdb .plugin-compatibility-wrap p:last-of-type { + margin-bottom: 0; +} +.wpsdb ul.plugin-compatibility-options { + display: block; + margin: 10px 0 10px 0px; +} +.wpsdb .plugin-compatibility-spinner { + position: relative; + top: 3px; + left: 10px; +} +.wpsdb .plugin-compatibility-success-msg { + position: relative; + left: 10px; + font-weight: bold; + display: none; +} +.wpsdb .help-tab { + display: none; +} +.wpsdb .help-tab h3 { font-size: 18px; - margin: 0; - padding: 0; + font-weight: normal; } -/* line 82, ../sass/styles.scss */ -#wpmdb-sidebar .author h2 a { - color: #464646; - text-decoration: none; +.wpsdb .help-tab .support { + border-bottom: 1px solid #ccc; + margin-bottom: 25px; + padding-bottom: 18px; } -/* line 86, ../sass/styles.scss */ -#wpmdb-sidebar .author h2 a:hover { - color: #000; +.wpsdb .help-tab .support p { + width: 640px; } -/* line 92, ../sass/styles.scss */ -#wpmdb-sidebar .author p { - margin: 0; +.wpsdb .help-tab .support .email a { + font-size: 12px; } -/* line 97, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe { - padding-bottom: 20px; - margin-bottom: 20px; +.wpsdb .help-tab .support .ajax-spinner { + top: 2px; +} +.wpsdb .help-tab .video-viewer { + margin-bottom: 30px; +} +.wpsdb .help-tab .videos { + width: 640px; +} +.wpsdb .help-tab .videos ul > li { + margin-bottom: 30px; + overflow: hidden; + position: relative; +} +.wpsdb .help-tab .videos ul > li a { + overflow: hidden; + display: block; + width: 320px; + height: 180px; + float: left; + margin-right: 15px; + position: relative; + z-index: 1; +} +.wpsdb .help-tab .videos ul > li a:before, .wpsdb .help-tab .videos ul > li a:after { + position: absolute; + content: " "; + margin: auto; + left: 0; + right: 0; + top: 0; + bottom: 0; +} +.wpsdb .help-tab .videos ul > li a:before { + width: 64px; + height: 64px; + -webkit-border-radius: 64px; + -moz-border-radius: 64px; + -ms-border-radius: 64px; + -o-border-radius: 64px; + border-radius: 64px; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); + opacity: 0.8; + border: 1px solid #ddd; + background-color: #fff; + z-index: 2; +} +.wpsdb .help-tab .videos ul > li a:after { + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); + opacity: 0.8; + border: 21.33333px solid transparent; + border-top-width: 12.8px; + border-bottom-width: 12.8px; + border-left-color: #333; + background: transparent; + display: block; + left: 25px; + width: 0px; + height: 0px; + z-index: 3; +} +.wpsdb .help-tab .videos .video:last-child { + margin-bottom: 0px; +} +.wpsdb .help-tab .videos img { + width: 320px; + height: 240px; + position: relative; + top: 50%; + margin-top: -120px; +} +.wpsdb .help-tab .debug { + width: 640px; + border-bottom: 1px solid #CCCCCC; + margin-bottom: 25px; + padding-bottom: 28px; +} +.wpsdb .help-tab .debug textarea { + width: 100%; + min-height: 200px; + font-family: Consolas, Monaco, monospace; + margin-bottom: 5px; +} +.wpsdb .help-tab h4 { + margin: 0 0 0.2em 0; +} +.wpsdb .help-tab p { + margin: 0 0 0.5em 0; +} +.wpsdb .help-tab iframe { + display: none; +} + +/* Progress Information */ +/* Contain floats: h5bp.com/q */ +.clearfix:before, .clearfix:after { + content: ""; + display: table; +} + +.clearfix:after { + clear: both; +} + +.clearfix { + zoom: 1; +} + +.general-spinner { + width: 16px; + height: 16px; +} + +.migration-error { + color: #A21B1B; + display: block; + font-weight: bold; + max-height: 400px; + max-width: 100%; + overflow: scroll; + word-wrap: break-word; +} + +.progress-content { + display: none; + position: relative; + margin: 0 auto; + background-color: #fff; + padding: 50px; + box-shadow: 0 0 10px #ccc; + cursor: default; + width: 80%; + z-index: 99999; + position: fixed; + left: 50%; + margin-left: -40%; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} +.progress-content .progress-bar { + height: 10px; + background-color: #8cc1e9; + margin-bottom: 5px; + background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #72a7cf), color-stop(100%, #8cc1e9)); + background-image: -webkit-linear-gradient(bottom, #72a7cf, #8cc1e9); + background-image: -moz-linear-gradient(bottom, #72a7cf, #8cc1e9); + background-image: -o-linear-gradient(bottom, #72a7cf, #8cc1e9); + background-image: linear-gradient(bottom, #72a7cf, #8cc1e9); +} +.progress-content .progress-title { + font-size: 18px; + font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif; + font-weight: normal; + float: left; +} +.progress-content .progress-bar { + width: 0%; +} +.progress-content .progress-info-wrapper { + margin-bottom: 10px; +} +.progress-content .progress-text { + clear: left; + float: left; + width: 100%; +} +.progress-content .timer { + float: right; +} +.progress-content .progress-tables { + overflow: hidden; + margin-bottom: 2px; + padding: 0 0 20px 0; +} +.progress-content .progress-bar-wrapper { + position: relative; +} +.progress-content .progress-bar-wrapper:before { + content: ''; + display: block; + height: 5px; + width: 1px; + background-color: #ccc; + position: absolute; + top: 15px; + left: 0px; +} +.progress-content .progress-tables-hover-boxes { + position: absolute; + top: 0px; + left: 0px; + display: block; + width: 100%; +} +.progress-content .progress-chunk-hover { + display: block; + float: left; + height: 35px; + position: relative; + top: -5px; + z-index: 1; +} +.progress-content .progress-chunk { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; + float: left; + display: block; + height: 6px; + border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; + color: #999; + position: relative; + text-align: center; } -/* line 102, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe h2 { - padding: 0; - margin: 0; - margin-bottom: 0.5em; - color: #666; - font-size: 20px; +.progress-content .progress-chunk > span { + padding: 0px 3px; + white-space: nowrap; + text-overflow: ellipsis; + margin-top: 10px; + display: inline-block; } -/* line 110, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe ul { - list-style-type: disc; +.progress-content .progress-label { + padding: 5px 10px; + border: 1px solid #ccc; + border-radius: 3px; + background-color: #fff; + font-family: Consolas, Monaco, monospace; + font-size: 12px; + display: inline-block; + top: -35px; + position: absolute; + opacity: 0; + -webkit-transition: opacity 200ms ease-in-out; + -moz-transition: opacity 200ms ease-in-out; + -ms-transition: opacity 200ms ease-in-out; + -o-transition: opacity 200ms ease-in-out; + transition: opacity 200ms ease-in-out; +} +.progress-content .label-visible { + opacity: 1; } -/* line 114, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe li { - margin-left: 1.5em; +.progress-content .progress-label:before { + content: ""; + width: 0; + height: 0; + border-left: 4px solid transparent; + border-right: 4px solid transparent; + border-top: 4px solid #ccc; + display: block; + position: absolute; + bottom: -5px; + left: 50%; + margin-left: -2px; +} +.progress-content .progress-label:after { + content: ""; + width: 0; + height: 0; + border-left: 4px solid transparent; + border-right: 4px solid transparent; + border-top: 4px solid #fff; + display: block; + position: absolute; + bottom: -4px; + left: 50%; + margin-left: -2px; +} +.progress-content .migration-progress-ajax-spinner { + left: 7px; + position: relative; + top: 15px; +} +.progress-content .close-progress-content { + color: #999999; + cursor: pointer; + font-family: "Times New Roman",serif; + font-size: 26px; + font-weight: 200; + position: absolute; + right: 20px; + top: 20px; + padding: 5px; + display: none; +} +.progress-content .close-progress-content:hover { color: #666; + border-color: #aaa; } -/* line 119, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe p { - margin: 0; +.progress-content .migration-controls { + display: block; + margin-top: 45px; +} +.progress-content .migration-controls span { + float: left; + text-align: center; + display: block; } -/* line 123, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe p.interesting { - margin-bottom: 1em; +.progress-content .migration-controls span:first-child { + margin-right: 10px; + width: 71px; } -/* line 127, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .error { - color: red; - font-weight: bold; - margin-bottom: 1em; + +body.mp6 input[type=checkbox]:disabled { + opacity: 1; + border-color: #ccc; } -/* line 133, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .thanks { - color: #333; - font-weight: bold; +body.mp6 #wpsdb-main { + margin-top: 15px; font-size: 14px; } -/* line 139, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field { - margin-bottom: 1em; +body.mp6 p { + font-size: 14px; +} +body.mp6 .wrap h2 { + float: left; +} +body.mp6 .wpsdb input[type=checkbox], +body.mp6 .wpsdb input[type=radio] { + vertical-align: middle; + margin-top: -4px; +} +body.mp6 .wpsdb input[type=text], +body.mp6 .wpsdb input[type=password] { + padding: 3px 5px; +} +body.mp6 .wpsdb input.code { + padding-top: 6px; +} +body.mp6 .wpsdb label { + font-size: 14px; +} +body.mp6 .wpsdb h2.nav-tab-wrapper { + float: none; + margin-bottom: 0; + width: 722px; +} +body.mp6 .wpsdb .help-tab h3 { + margin-top: 0; +} +body.mp6 .wpsdb .temp-disabled { + background-color: #f9f9f9; } -/* line 142, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field p { - margin-bottom: 0.3em; +body.mp6 .wpsdb .migration-profile-options li a { + border-color: #ccc; + color: #555; + background-color: #e4e4e4; } -/* line 146, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field .willing-copy { +body.mp6 .wpsdb .migration-profile-options li a:hover { + background-color: #fff; + color: #464646; +} +body.mp6 .wpsdb .settings-tab .slider-label span { + vertical-align: middle; +} +body.mp6 .wpsdb .settings-tab .slider-label-wrapper { + font-size: 14px; +} +body.mp6 .wpsdb .settings-tab .ui-slider { + border-color: #ccc; + background-color: #fff; +} +body.mp6 .wpsdb .settings-tab .ui-slider-range { + background-color: #d8fcd1; +} +body.mp6 .wpsdb .settings-tab .option-section li label { + font-size: 14px; +} +body.mp6 .wpsdb .connection-info, +body.mp6 .wpsdb .migrate-tab .pull-push-connection-info { font-weight: bold; font-size: 14px; +} +body.mp6 .wpsdb .general-helper { + border: 0; + width: auto; + height: auto; + top: auto; + margin: 0; +} +body.mp6 .wpsdb .general-helper:after { + content: "\f223"; + display: inline-block; + -webkit-font-smoothing: antialiased; + font: normal 22px/1 'dashicons'; + vertical-align: top; + top: auto; + left: auto; + position: relative; +} +body.mp6 .wpsdb .helper-message { + font-size: 14px; line-height: 1.4em; - margin-bottom: 1em; } -/* line 154, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.how-much input { - width: 50px; +body.mp6 .wpsdb .right-arrow { + display: none; } -/* line 160, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.notify-me input { - position: absolute; +body.mp6 .wpsdb .arrow-col { + width: 75px; } -/* line 164, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.notify-me label { - display: block; - padding-left: 20px; +body.mp6 .wpsdb .arrow-col:after { + content: "\f344"; + display: inline-block; + -webkit-font-smoothing: antialiased; + font: normal 22px/1 'dashicons'; + vertical-align: top; + color: #999; +} +body.mp6 .wpsdb .find-heading { + width: 409px; +} +body.mp6 .wpsdb .replace-fields input { + width: 304px; +} +body.mp6 .wpsdb .replace-right-col span { + border-color: #999; +} +body.mp6 .wpsdb .replace-right-col span:hover { + border-color: #666; +} +body.mp6 .wpsdb .replace-add-row:after, body.mp6 .wpsdb .replace-add-row:before { + background-color: #999; +} +body.mp6 .wpsdb .replace-add-row:hover:after, body.mp6 .wpsdb .replace-add-row:hover:before { + background-color: #666; +} +body.mp6 .wpsdb .option-group.migrate-selection > li > label { + font-size: 16px; +} +body.mp6 .wpsdb .saved-migration-profile-label { + font-size: 16px; +} +body.mp6 .wpsdb .option-heading, body.mp6 .wpsdb .checkbox-label { + font-size: 16px; +} +body.mp6 .wpsdb .checkbox-label input[type=checkbox] { + top: auto; +} +body.mp6 .wpsdb .return-to-profile-selection { + font-size: 14px; +} +body.mp6 .wpsdb .option-description { + font-size: 13px; +} +body.mp6 .wpsdb .save-migration-profile-wrap li { + position: relative; +} +body.mp6 .wpsdb .replace-remove-row, +body.mp6 .wpsdb .delete-profile { + border: 0; + border-radius: 0; + height: auto; + width: auto; + left: 0; + top: 50%; + margin-left: 0; +} +body.mp6 .wpsdb .replace-remove-row:after, +body.mp6 .wpsdb .delete-profile:after { + content: "\f153"; + display: inline-block; + -webkit-font-smoothing: antialiased; + font: normal 18px/1 'dashicons'; + vertical-align: middle; + color: #999; +} +body.mp6 .wpsdb .replace-remove-row:hover:after, +body.mp6 .wpsdb .delete-profile:hover:after { + color: #666; } -/* line 172, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.comments textarea { - width: 230px; - height: 3em; +body.mp6 .wpsdb .help-tab .support p, body.mp6 .wpsdb .help-tab .support .email a { + font-size: 14px; +} +body.mp6 .wpsdb .help-tab div.warning p { + font-size: 13px; +} +body.mp6 .wpsdb .help-tab .videos h4, body.mp6 .wpsdb .help-tab .videos p { + font-size: 14px; +} +body.mp6 .wpsdb .inline-message, body.mp6 .wpsdb .notification-message { + border-radius: 0; + border: 0; + box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); + padding: 10px 14px; + font-size: 13px; +} +body.mp6 .wpsdb .notification-message { + margin-bottom: 20px; + background-color: #fff; +} +body.mp6 .wpsdb .notification-message p { + font-size: 13px; + margin-top: 0; +} +body.mp6 .wpsdb .notification-message p:last-child { + margin: 0; +} +body.mp6 .wpsdb .notification-message h4 { + margin-top: 0; +} +body.mp6 .wpsdb .notification-message a { + color: #0074a2; + text-decoration: none; +} +body.mp6 .wpsdb .notification-message a:hover { + color: #2ea2cc; +} +body.mp6 .wpsdb .inline-message.error, body.mp6 .wpsdb .notification-message.error-notice { + border-left: 4px solid #dd3d36; + background-color: #fff; } -/* line 177, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.comments textarea.has-content, #wpmdb-sidebar .subscribe .field.comments textarea:focus { - height: 5em; +body.mp6 .wpsdb .inline-message.warning, body.mp6 .wpsdb .notification-message.warning-notice { + background-color: #fff; + border-left: 4px solid #ffba00; } -/* line 183, ../sass/styles.scss */ -#wpmdb-sidebar .subscribe .field.submit-button { +body.mp6 .wpsdb .inline-message.success, body.mp6 .wpsdb .notification-message.success-notice { + border-left: 4px solid #7ad03a; +} +body.mp6 .wpsdb .ssl-notice { margin-bottom: 0; } +body.mp6 .wpsdb .different-plugin-version-notice, body.mp6 .wpsdb .directory-permission-notice { + margin-bottom: 10px; +} +body.mp6 .progress-content { + font-size: 14px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); + background-color: #eee; +} +body.mp6 .progress-content .progress-title { + font-family: 'Open Sans', sans-serif; + font-weight: normal; + font-size: 22px; +} +body.mp6 .progress-content .dashicons-yes { + font-size: 42px; + line-height: 0.5em; +} +body.mp6 .progress-content .progress-bar { + background-image: none; + background-color: #0074a2; +} +body.mp6 #overlay { + background-color: rgba(0, 0, 0, 0.5); +} +body.mp6 .migration-progress-ajax-spinner { + top: 20px; +} diff --git a/asset/img/wpappstore-logo.png b/asset/img/wpappstore-logo.png deleted file mode 100644 index df44985..0000000 Binary files a/asset/img/wpappstore-logo.png and /dev/null differ diff --git a/asset/js/common.js b/asset/js/common.js new file mode 100644 index 0000000..f81cdeb --- /dev/null +++ b/asset/js/common.js @@ -0,0 +1,29 @@ +// global vars +var hooks = []; +var call_stack = []; +var non_fatal_errors = ''; +var migration_error = false; +var connection_data; +var next_step_in_migration; + +function wpsdb_call_next_hook() { + if (!call_stack.length) { + call_stack = hooks; + } + + var func = call_stack[0]; + call_stack.shift(); + window[func](); // Uses the string from the array to call the function of the same name +} + +function wpsdb_add_commas(number_string) { + number_string += ''; + x = number_string.split('.'); + x1 = x[0]; + x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + ',' + '$2'); + } + return x1 + x2; +} diff --git a/asset/js/hook.js b/asset/js/hook.js new file mode 100644 index 0000000..f5983e5 --- /dev/null +++ b/asset/js/hook.js @@ -0,0 +1,68 @@ +(function($) { + $.wpsdb = { + /** + * Implement a WordPress-link Hook System for Javascript + * TODO: Change 'tag' to 'args', allow number (priority), string (tag), + object (priority+tag) + */ + hooks: { + action: {}, + filter: {} + }, + add_action: function(action, callable, tag) { + jQuery.wpsdb.add_hook('action', action, callable, tag); + }, + add_filter: function(action, callable, tag) { + jQuery.wpsdb.add_hook('filter', action, callable, tag); + }, + do_action: function(action, args) { + jQuery.wpsdb.do_hook('action', action, null, args); + }, + apply_filters: function(action, value, args) { + return jQuery.wpsdb.do_hook('filter', action, value, args); + }, + remove_action: function(action, tag) { + jQuery.wpsdb.remove_hook('action', action, tag); + }, + remove_filter: function(action, tag) { + jQuery.wpsdb.remove_hook('filter', action, tag); + }, + add_hook: function(hook_type, action, callable, tag) { + if (undefined == jQuery.wpsdb.hooks[hook_type][action]) { + jQuery.wpsdb.hooks[hook_type][action] = []; + } + var hooks = jQuery.wpsdb.hooks[hook_type][action]; + if (undefined == tag) { + tag = action + '_' + hooks.length; + } + jQuery.wpsdb.hooks[hook_type][action].push({ + tag: tag, + callable: callable + }); + }, + do_hook: function(hook_type, action, value, args) { + if (undefined != jQuery.wpsdb.hooks[hook_type][action]) { + var hooks = jQuery.wpsdb.hooks[hook_type][action]; + for (var i = 0; i < hooks.length; i++) { + if ('action' == hook_type) { + hooks[i].callable(args); + } else { + value = hooks[i].callable(value, args); + } + } + } + if ('filter' == hook_type) { + return value; + } + }, + remove_hook: function(hook_type, action, tag) { + if (undefined != jQuery.wpsdb.hooks[hook_type][action]) { + var hooks = jQuery.wpsdb.hooks[hook_type][action]; + for (var i = hooks.length - 1; i >= 0; i--) { + if (undefined == tag || tag == hooks[i].tag) + hooks.splice(i, 1); + } + } + } + }; +})(jQuery); diff --git a/asset/js/script.js b/asset/js/script.js old mode 100644 new mode 100755 index 47c6b64..e6e8691 --- a/asset/js/script.js +++ b/asset/js/script.js @@ -1,62 +1,2316 @@ +// global functions +var migration_complete; +var migration_complete_events; +var migrate_table_recursive; +var execute_next_step; + (function($) { - $(document).ready(function() { - $('#replace-guids-info-link').click(function() { - var $div = $('#replace-guids-info'); - if ( 'none' == $div.css('display') ) { - $div.show(); - $(this).html('show less'); - return false; - } - else { - $div.hide(); - $(this).html('show more'); - return false; - } - }); - - $('#wpmdb-sidebar').each(function() { - var $sidebar = $(this); - - $('form', $sidebar).submit(function() { - var $form = $(this), - data = $(this).serializeArray(); - - $('.button', $form).attr('disabled', 'true'); - - data.push({name: 'action', value: 'subscribe_submission'}); - - $.post( ajaxurl, data, function(result) { - if (result) { - $('.error', $sidebar).remove(); - $('.field.submit-button', $sidebar).before(''); - $('.error', $sidebar).fadeIn(); - } - else { - $form.html('

Thanks for subscribing. We promise to protect your email from weasels.

').fadeIn(); - document.location.hash = '#top'; - } - }); - return false; + var connection_established = false; + var last_replace_switch = ''; + var doing_ajax = false; + var doing_reset_api_key_ajax = false; + var doing_save_profile = false; + var doing_plugin_compatibility_ajax = false; + var profile_name_edited = false; + var show_prefix_notice = false; + var show_ssl_notice = false; + var show_version_notice = false; + var migration_completed = false; + var currently_migrating = false; + var dump_filename = ''; + var dump_url = ''; + var migration_intent; + var remote_site; + var secret_key; + var form_data; + var stage; + var elapsed_interval; + var completed_msg; + var tables_to_migrate = ''; + var migration_paused = false; + var previous_progress_title; + var previous_progress_text; + var timer_count; + var overall_percent; + var migration_cancelled = false; + + var admin_url = ajaxurl.replace('/admin-ajax.php', ''), + spinner_url = admin_url + '/images/wpspin_light'; + + if (window.devicePixelRatio >= 2) { + spinner_url += '-2x'; + } + + spinner_url += '.gif'; + + window.onbeforeunload = function(e) { + if (currently_migrating) { + e = e || window.event; + + // For IE and Firefox prior to version 4 + if (e) { + e.returnValue = 'Sure?'; + } + + // For Safari + return 'Sure?'; + } + }; + + function pad(n, width, z) { + z = z || '0'; + n = n + ''; + return n.length >= width ? n : new Array(width - n.length + 1).join(z) + + n; + } + + function is_int(n) { + n = parseInt(n); + return typeof n === 'number' && n % 1 == 0; + } + + function setup_counter() { + timer_count = 0, + counter_display = $('.timer'), + label = wpsdb_i10n.time_elapsed + ' '; + + elapsed_interval = setInterval(count, 1000); + } + + function display_count() { + hours = Math.floor(timer_count / 3600) % 24; + minutes = Math.floor(timer_count / 60) % 60; + seconds = timer_count % 60; + var display = label + pad(hours, 2, 0) + ':' + pad(minutes, 2, 0) + ':' + + pad(seconds, 2, 0); + counter_display.html(display); + } + + function count() { + timer_count = timer_count + 1; + display_count(); + } + + function get_intersect(arr1, arr2) { + var r = [], + o = {}, l = arr2.length, + i, v; + for (i = 0; i < l; i++) { + o[arr2[i]] = true; + } + l = arr1.length; + for (i = 0; i < l; i++) { + v = arr1[i]; + if (v in o) { + r.push(v); + } + } + return r; + } + + function get_query_var(name) { + name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, + " ")); + } + + function maybe_show_ssl_warning(url, key, remote_scheme) { + var scheme = url.substr(0, url.indexOf(':')); + if (remote_scheme != scheme && url.indexOf('https') != -1) { + $('.ssl-notice').show(); + show_ssl_notice = true; + url = url.replace('https', 'http'); + $('.pull-push-connection-info').val(url + "\n" + key); + return; + } + show_ssl_notice = false; + return; + } + + function maybe_show_version_warning(plugin_version, url) { + if (typeof plugin_version != 'undefined' && plugin_version != + wpsdb_plugin_version) { + $('.different-plugin-version-notice').show(); + $('.remote-version').html(plugin_version); + $('.remote-location').html(url); + $('.step-two').hide(); + show_version_notice = true; + } + } + + function maybe_show_prefix_notice(prefix) { + if (prefix != wpsdb_this_prefix) { + $('.remote-prefix').html(prefix); + show_prefix_notice = true; + if ($('#pull').is(':checked')) { + $('.prefix-notice.pull').show(); + } else { + $('.prefix-notice.push').show(); + } + } + } + + function get_domain_name(url) { + var temp_url = url; + var domain = temp_url.replace(/\/\/(.*)@/, '//').replace('http://', '').replace( + 'https://', '').replace('www.', ''); + return domain; + } + + function get_default_profile_name(url, intent, ing_suffix) { + var domain = get_domain_name(url); + var action = intent; + action = action.charAt(0).toUpperCase() + action.slice(1); + if (ing_suffix) { + action += 'ing'; + } + var preposition = 'to'; + if (intent == 'pull') { + preposition = 'from'; + } + + return profile_name = action + ' ' + preposition + ' ' + domain; + } + + function remove_protocol(url) { + return url.replace(/^https?:/i, ""); + } + + $(document).ready(function() { + $('#plugin-compatibility').change(function(e) { + var install = '1'; + if ($(this).is(':checked')) { + // replace with l10n string when available + var answer = confirm( + 'If confirmed we will install an additional WordPress "Must Use" plugin. This plugin will allow us to control which plugins are loaded during WP Sync DB specific operations. Do you wish to continue?' + ); + + if (!answer) { + $(this).prop('checked', false); + return; + } + } else { + install = '0'; + } + + $('.plugin-compatibility-wrap').toggle(); + + $(this).parent().append(''); + $('#plugin-compatibility').attr('disabled', 'disabled'); + $('.plugin-compatibility').addClass('disabled'); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_plugin_compatibility', + install: install, + }, + error: function(jqXHR, textStatus, errorThrown) { + // replace with l10n string when available + alert( + 'A problem occurred when trying to change the plugin compatibility setting.\r\n\r\nStatus: ' + + jqXHR.status + ' ' + jqXHR.statusText + + '\r\n\r\nResponse:\r\n' + jqXHR.responseText); + $('.ajax-spinner').remove(); + $('#plugin-compatibility').removeAttr('disabled'); + $('.plugin-compatibility').removeClass('disabled'); + }, + success: function(data) { + if ('' != $.trim(data)) { + alert(data); + } else { + $('.plugin-compatibility').append( + 'Saved'); + $('.ajax-success-msg').fadeOut(2000, function() { + $(this).remove(); + }); + } + $('.ajax-spinner').remove(); + $('#plugin-compatibility').removeAttr('disabled'); + $('.plugin-compatibility').removeClass('disabled'); + } + }); + + }); + + if ($('#plugin-compatibility').is(':checked')) { + $('.plugin-compatibility-wrap').show(); + } + + if (navigator.userAgent.indexOf('MSIE') > 0 || navigator.userAgent.indexOf( + 'Trident') > 0) { + $('.ie-warning').show(); + } + + $('.slider').slider({ + range: 'min', + value: wpsdb_max_request / 1024, + min: 512, + max: wpsdb_bottleneck / 1024, + step: 512, + slide: function(event, ui) { + $('.amount').html(wpsdb_add_commas(ui.value) + ' kB'); + }, + change: function(event, ui) { + $('.amount').after(''); + $('.slider').slider('disable'); + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'json', + cache: false, + data: { + action: 'wpsdb_update_max_request_size', + max_request_size: parseInt(ui.value), + nonce: wpsdb_nonces.update_max_request_size, + }, + error: function(jqXHR, textStatus, errorThrown) { + $('.slider').slider('enable'); + $('.slider-spinner').remove(); + alert(wpsdb_i10n.max_request_size_problem); + }, + success: function(data) { + $('.slider').slider('enable'); + $('.slider-spinner').remove(); + $('.slider-success-msg').show(); + $('.slider-success-msg').fadeOut(2000, function() { + $(this).hide(); }); + } + }); + } + }); + $('.amount').html(wpsdb_add_commas($('.slider').slider('value')) + + ' kB'); + + var progress_content_original = $('.progress-content').clone(); + $('.progress-content').remove(); + + var push_select = $('#select-tables').clone(); + var pull_select = $('#select-tables').clone(); + var push_post_type_select = $('#select-post-types').clone(); + var pull_post_type_select = $('#select-post-types').clone(); + var push_select_backup = $('#select-backup').clone(); + var pull_select_backup = $('#select-backup').clone(); + + $('.help-tab .video').each(function() { + var $container = $(this), + $viewer = $('.video-viewer'); + + $('a', this).click(function(e) { + e.preventDefault(); + + $viewer.attr('src', '//www.youtube.com/embed/' + $container.data( + 'video-id') + '?autoplay=1'); + $viewer.show(); + var offset = $viewer.offset(); + $(window).scrollTop(offset.top - 50); + }); + }); + + $('.backup-options').show(); + $('.keep-active-plugins').show(); + if ($('#savefile').is(':checked')) { + $('.backup-options').hide(); + $('.keep-active-plugins').hide(); + } + + function disable_export_type_controls() { + $('.option-group').each(function(index) { + $('input', this).attr('disabled', 'disabled'); + $('label', this).css('cursor', 'default'); + }); + } + + function enable_export_type_controls() { + $('.option-group').each(function(index) { + $('input', this).removeAttr('disabled'); + $('label', this).css('cursor', 'pointer'); + }); + } + + // automatically validate connnection info if we're loading a saved profile + establish_remote_connection_from_saved_profile(); + + function establish_remote_connection_from_saved_profile() { + var action = $('input[name=action]:checked').val(); + var connection_info = $.trim($('.pull-push-connection-info').val()).split( + "\n"); + if (typeof wpsdb_default_profile == 'undefined' || + wpsdb_default_profile == true || action == 'savefile' || doing_ajax + ) { + return; + } + + last_replace_switch = action; + + doing_ajax = true; + disable_export_type_controls(); + + $('.connection-status').html(wpsdb_i10n.establishing_remote_connection); + $('.connection-status').removeClass( + 'notification-message error-notice migration-error'); + $('.connection-status').append(''); + + var intent = $('input[name=action]:checked').val(); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'json', + cache: false, + data: { + action: 'wpsdb_verify_connection_to_remote_site', + url: connection_info[0], + key: connection_info[1], + intent: intent, + nonce: wpsdb_nonces.verify_connection_to_remote_site, + convert_post_type_selection: wpsdb_convert_post_type_selection, + profile: wpsdb_profile + }, + error: function(jqXHR, textStatus, errorThrown) { + $('.connection-status').html(wpsdb_i10n.connection_local_server_problem + + ' (#102)'); + $('.connection-status').append('

Status: ' + jqXHR.status + + ' ' + jqXHR.statusText + '

Response:
' + + jqXHR.responseText); + $('.connection-status').addClass( + 'notification-message error-notice migration-error'); + $('.ajax-spinner').remove(); + doing_ajax = false; + enable_export_type_controls(); + }, + success: function(data) { + $('.ajax-spinner').remove(); + doing_ajax = false; + enable_export_type_controls(); + + if (typeof data.wpsdb_error != 'undefined' && data.wpsdb_error == + 1) { + $('.connection-status').html(data.body); + $('.connection-status').addClass( + 'notification-message error-notice migration-error'); + + if (data.body.indexOf('401 Unauthorized') > -1) { + $('.basic-access-auth-wrapper').show(); + } + return; + } + + maybe_show_ssl_warning(connection_info[0], connection_info[1], + data.scheme); + maybe_show_version_warning(data.plugin_version, connection_info[ + 0]); + maybe_show_prefix_notice(data.prefix); + + $('.pull-push-connection-info').addClass('temp-disabled'); + $('.pull-push-connection-info').attr('readonly', 'readonly'); + $('.connect-button').hide(); + + $('.connection-status').hide(); + $('.step-two').show(); + connection_established = true; + connection_data = data; + move_connection_info_box(); + + var loaded_tables = ''; + if (wpsdb_default_profile == false && typeof wpsdb_loaded_tables != + 'undefined') { + loaded_tables = wpsdb_loaded_tables; + } + + var table_select = document.createElement('select'); + $(table_select).attr({ + multiple: 'multiple', + name: 'select_tables[]', + id: 'select-tables', + class: 'multiselect' + }); + + $.each(connection_data.tables, function(index, value) { + var selected = $.inArray(value, loaded_tables); + if (selected != -1) { + selected = ' selected="selected" '; + } else { + selected = ' '; + } + $(table_select).append('' + value + ' (' + connection_data.table_sizes_hr[ + value] + ')'); + }); + + pull_select = table_select; + + var loaded_post_types = ''; + if (wpsdb_default_profile == false && typeof wpsdb_loaded_post_types != + 'undefined') { + if (typeof data.select_post_types != 'undefined') { + $('#exclude-post-types').attr('checked', 'checked'); + $('.post-type-select-wrap').show(); + loaded_post_types = data.select_post_types; + } else { + loaded_post_types = wpsdb_loaded_post_types; + } + } + + var post_type_select = document.createElement('select'); + $(post_type_select).attr({ + multiple: 'multiple', + name: 'select_post_types[]', + id: 'select-post-types', + class: 'multiselect' + }); + + $.each(connection_data.post_types, function(index, value) { + var selected = $.inArray(value, loaded_post_types); + if (selected != -1 || (wpsdb_convert_exclude_revisions == + true && value != 'revision')) { + selected = ' selected="selected" '; + } else { + selected = ' '; + } + $(post_type_select).append('' + value + ''); + }); + + pull_post_type_select = post_type_select; + + var loaded_tables_backup = ''; + if (wpsdb_default_profile == false && typeof wpsdb_loaded_tables_backup != + 'undefined') { + loaded_tables_backup = wpsdb_loaded_tables_backup; + } + + var table_select_backup = document.createElement('select'); + $(table_select_backup).attr({ + multiple: 'multiple', + name: 'select_backup[]', + id: 'select-backup', + class: 'multiselect' + }); + + $.each(connection_data.tables, function(index, value) { + var selected = $.inArray(value, loaded_tables_backup); + if (selected != -1) { + selected = ' selected="selected" '; + } else { + selected = ' '; + } + $(table_select_backup).append('' + value + ' (' + connection_data + .table_sizes_hr[value] + ')'); + }); + + push_select_backup = table_select_backup; + + if ($('#pull').is(':checked')) { + $('#select-tables').remove(); + $('.select-tables-wrap').prepend(pull_select); + $('#select-post-types').remove(); + $('.select-post-types-wrap').prepend(pull_post_type_select); + $('#select-backup').remove(); + $('.backup-tables-wrap').prepend(pull_select_backup); + $('.table-prefix').html(data.prefix); + $('.uploads-dir').html(wpsdb_this_uploads_dir); + } else { + $('#select-backup').remove(); + $('.backup-tables-wrap').prepend(push_select_backup); + } + + $.wpsdb.do_action('verify_connection_to_remote_site', + connection_data); + + } + + }); + + } + + // add to tags which act as JS event buttons, will not jump page to top + // and will deselect the button + $('.js-action-link').click(function(e) { + e.preventDefault(); + $(this).blur(); + }); + + // clears the debug log + $('.clear-log').click(function() { + $('.debug-log-textarea').val(''); + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_clear_log', + nonce: wpsdb_nonces.clear_log, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.clear_log_problem); + }, + success: function(data) {} + }); + }); + + // updates the debug log when the user switches to the help tab + function refresh_debug_log() { + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_get_log', + nonce: wpsdb_nonces.get_log, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.update_log_problem); + }, + success: function(data) { + $('.debug-log-textarea').val(data); + } + }); + } + + // select all tables + $('.multiselect-select-all').click(function() { + var multiselect = $(this).parents('.select-wrap').children( + '.multiselect'); + $(multiselect).focus(); + $('option', multiselect).attr('selected', 1); + }); + + // deselect all tables + $('.multiselect-deselect-all').click(function() { + var multiselect = $(this).parents('.select-wrap').children( + '.multiselect'); + $(multiselect).focus(); + $('option', multiselect).removeAttr('selected'); + }); + + // invert table selection + $('.multiselect-invert-selection').click(function() { + var multiselect = $(this).parents('.select-wrap').children( + '.multiselect'); + $(multiselect).focus(); + $('option', multiselect).each(function() { + $(this).attr('selected', !$(this).attr('selected')); + }); + }); + + // on option select hide all "advanced" option divs and show the correct div + // for the option selected + $('.option-group input[type=radio]').change(function() { + group = $(this).closest('.option-group'); + $('ul', group).hide(); + parent = $(this).closest('li'); + $('ul', parent).show(); + }); + + // on page load, expand hidden divs for selected options (browser form + // cache) + $('.option-group').each(function() { + $('.option-group input[type=radio]').each(function() { + if ($(this).is(':checked')) { + parent = $(this).closest('li'); + $('ul', parent).show(); + } + }); + }); + + // expand and collapse content on click + $('.header-expand-collapse').click(function() { + if ($('.expand-collapse-arrow', this).hasClass('collapsed')) { + $('.expand-collapse-arrow', this).removeClass('collapsed'); + $(this).next().show(); + } else { + $('.expand-collapse-arrow', this).addClass('collapsed'); + $(this).next().hide(); + } + }); + + $('.checkbox-label input[type=checkbox]').change(function() { + if ($(this).is(':checked')) { + $(this).parent().next().show(); + } else { + $(this).parent().next().hide(); + } + }); + + // special expand and collapse content on click for save migration profile + $('#save-migration-profile').change(function() { + if ($(this).is(':checked')) { + $('.save-settings-button').show(); + $('.migrate-db .button-primary').val(wpsdb_i10n.migrate_db_save); + } else { + $('.save-settings-button').hide(); + $('.migrate-db .button-primary').val(wpsdb_i10n.migrate_db); + } + }); + + if ($('#save-migration-profile').is(':checked')) { + $('.save-settings-button').show(); + $('.migrate-db .button-primary').val(wpsdb_i10n.migrate_db_save); + }; + + $('.checkbox-label input[type=checkbox]').each(function() { + if ($(this).is(':checked')) { + $(this).parent().next().show(); + } + }); + + $('#new-url').change(function() { + $('#new-url-missing-warning').hide(); + }); + + $('#new-path').change(function() { + $('#new-path-missing-warning').hide(); + }); + + // AJAX migrate button + $('.migrate-db-button').click(function(event) { + $(this).blur(); + event.preventDefault(); + + // check that they've selected some tables to migrate + if ($('#migrate-selected').is(':checked') && $('#select-tables').val() == + null) { + alert(wpsdb_i10n.please_select_one_table); + return; + } + + new_url_missing = false; + new_file_path_missing = false; + if ($('#new-url').length && !$('#new-url').val()) { + $('#new-url-missing-warning').show(); + $('#new-url').focus(); + $('html,body').scrollTop(0); + new_url_missing = true; + } + + if ($('#new-path').length && !$('#new-path').val()) { + $('#new-path-missing-warning').show(); + if (false == new_url_missing) { + $('#new-path').focus(); + $('html,body').scrollTop(0); + } + new_file_path_missing = true; + } + + if (true == new_url_missing || true == new_file_path_missing) return; + + // also save profile + if ($('#save-migration-profile').is(':checked')) { + + if ($.trim($('.create-new-profile').val()) == '' && $( + '#create_new').is(':checked')) { + alert(wpsdb_i10n.enter_name_for_profile); + $('.create-new-profile').focus(); + return; + } + + var create_new_profile = false; + + if ($('#create_new').is(':checked')) { + create_new_profile = true; + } + var profile_name = $('.create-new-profile').val(); + + profile = $('#migrate-form').serialize(); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_save_profile', + profile: profile, + nonce: wpsdb_nonces.save_profile, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.save_profile_problem); + }, + success: function(data) { + if (create_new_profile) { + var new_profile_key = parseInt(data, 10); + var new_profile_id = new_profile_key + 1; + var new_li = + '
  • '; + $('#create_new').parents('li').before(new_li); + $('#profile-' + new_profile_id).attr('checked', 'checked'); + $('.create-new-profile').val(''); + } + } + }); + } + + form_data = $('#migrate-form').serialize(); + + var doc_height = $(document).height(); + + $('body').append('
    '); + + $('#overlay') + .height(doc_height) + .css({ + 'position': 'fixed', + 'top': 0, + 'left': 0, + 'width': '100%', + 'z-index': 99999, + 'display': 'none', + }); + + $progress_content = progress_content_original.clone(); + migration_intent = $('input[name=action]:checked').val(); + + stage = 'backup'; + + if (migration_intent == 'savefile') { + stage = 'migrate'; + } + + if ($('#create-backup').is(':checked') == false) { + stage = 'migrate'; + } + + var table_intent = $('input[name=table_migrate_option]:checked').val(); + var connection_info = $.trim($('.pull-push-connection-info').val()) + .split("\n"); + var table_rows = ''; + + remote_site = connection_info[0]; + secret_key = connection_info[1]; + + var static_migration_label = ''; + + $('#overlay').after($progress_content); + + completed_msg = wpsdb_i10n.exporting_complete; + + if (migration_intent == 'savefile') { + static_migration_label = wpsdb_i10n.exporting_please_wait; + } else { + static_migration_label = get_default_profile_name(remote_site, + migration_intent, true) + ', ' + wpsdb_i10n.please_wait; + completed_msg = get_default_profile_name(remote_site, + migration_intent, true) + ' ' + wpsdb_i10n.complete; + } + + $('.progress-title').html(static_migration_label); + + $('#overlay').show(); + backup_option = $('input[name=backup_option]:checked').val(); + table_option = $('input[name=table_migrate_option]:checked').val(); + + if (stage == 'backup') { + if (table_option == 'migrate_only_with_prefix' && backup_option == + 'backup_selected') { + backup_option = 'backup_only_with_prefix'; + } + if (migration_intent == 'push') { + table_rows = connection_data.table_rows; + if (backup_option == 'backup_only_with_prefix') { + tables_to_migrate = connection_data.prefixed_tables; + } else if (backup_option == 'backup_selected') { + selected_tables = $('#select-tables').val(); + tables_to_migrate = get_intersect(selected_tables, + connection_data.tables); + } else if (backup_option == 'backup_manual_select') { + tables_to_migrate = $('#select-backup').val(); + } + } else { + table_rows = wpsdb_this_table_rows; + if (backup_option == 'backup_only_with_prefix') { + tables_to_migrate = wpsdb_this_prefixed_tables; + } else if (backup_option == 'backup_selected') { + selected_tables = $('#select-tables').val(); + tables_to_migrate = get_intersect(selected_tables, + wpsdb_this_tables); + } else if (backup_option == 'backup_manual_select') { + tables_to_migrate = $('#select-backup').val(); + } + } + } else { + if (table_intent == 'migrate_select') { // user has elected to migrate only certain tables + // grab tables as per what the user has selected from the multiselect box + tables_to_migrate = $('#select-tables').val(); + // user is pushing or exporting + if (migration_intent == 'push' || migration_intent == + 'savefile') { + // default value, assuming we're not backing up + table_rows = wpsdb_this_table_rows; + } else { + table_rows = connection_data.table_rows; + } + } else { + if (migration_intent == 'push' || migration_intent == + 'savefile') { + tables_to_migrate = wpsdb_this_prefixed_tables; + table_rows = wpsdb_this_table_rows; + } else { + tables_to_migrate = connection_data.prefixed_tables; + table_rows = connection_data.table_rows; + } + } + } + + function decide_tables_to_display_rows(tables_to_migrate, + table_rows) { + + var total_size = 0; + $.each(tables_to_migrate, function(index, value) { + total_size += parseInt(table_rows[value]); + }); + + var last_element = ''; + $.each(tables_to_migrate, function(index, value) { + var percent = table_rows[value] / total_size * 100; + var percent_rounded = Math.round(percent * 1000) / 1000; + $('.progress-tables').append('
    ' + value + + '
    '); + $('.progress-tables-hover-boxes').append( + '
    '); + var label = $('.progress-tables .progress-chunk:last span'); + last_element = value; + }); + + $('.progress-chunk').each(function(index) { + if ($(this).width() < 1 && tables_to_migrate[index] != + last_element) { + $(this).hide(); + $('.progress-chunk-hover[data-table=' + tables_to_migrate[ + index] + ']').hide(); + table_rows[last_element] = Number(table_rows[last_element]); + table_rows[last_element] += Number(table_rows[ + tables_to_migrate[index]]); + table_rows[tables_to_migrate[index]] = 0; + } + var element = this; + setTimeout(function() { + hide_overflowing_elements(element); + }, 0); + + function hide_overflowing_elements(element) { + if ($('span', element).innerWidth() > $(element).width()) { + $('span', element).hide(); + } + } + }); + + percent_rounded = 0; + if (table_rows[last_element] != 0) { + var percent = table_rows[last_element] / total_size * 100; + var percent_rounded = Math.round(percent * 1000) / 1000; + } + $('.progress-tables .progress-chunk:last').css('width', + percent_rounded + '%'); + $('.progress-chunk-hover:last').css('width', percent_rounded + + '%'); + + var return_vals = [table_rows, total_size]; + return return_vals; + + } + + table_details = decide_tables_to_display_rows(tables_to_migrate, + table_rows); + table_rows = table_details[0]; + total_size = table_details[1]; + + $('.progress-title').after('' + ); + + var height = $('.progress-content').outerHeight(); + $('.progress-content').css('top', '-' + height + 'px').show().animate({ + 'top': '0px' + }); + + setup_counter(); + currently_migrating = true; + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'json', + cache: false, + data: { + action: 'wpsdb_initiate_migration', + intent: migration_intent, + url: remote_site, + key: secret_key, + form_data: form_data, + stage: stage, + nonce: wpsdb_nonces.initiate_migration, + }, + error: function(jqXHR, textStatus, errorThrown) { + $('.progress-title').html('Migration failed'); + $('.progress-text').html(wpsdb_i10n.connection_local_server_problem + + ' (#112)'); + $('.progress-text').append('

    Status: ' + jqXHR.status + + ' ' + jqXHR.statusText + '

    Response:
    ' + + jqXHR.responseText); + $('.progress-text').addClass('migration-error'); + console.log(jqXHR); + console.log(textStatus); + console.log(errorThrown); + migration_error = true; + migration_complete_events(); + return; + }, + success: function(data) { + if (typeof data.wpsdb_error != 'undefined' && data.wpsdb_error == + 1) { + migration_error = true; + migration_complete_events(); + $('.progress-title').html(wpsdb_i10n.migration_failed); + $('.progress-text').addClass('migration-error'); + $('.progress-text').html(data.body); + return; + } + + dump_url = data.dump_url; + dump_filename = data.dump_filename; + + var i = 0; + var progress_size = 0; + overall_percent = 0; + var table_progress = 0; + var temp_progress = 0; + var last_progress = 0; + var overall_table_progress = 0; + + migrate_table_recursive = function(current_row, primary_keys) { + if (i >= tables_to_migrate.length) { + if (stage == 'backup') { + stage = 'migrate'; + i = 0; + progress_size = 0; + $('.progress-bar').width('0px'); + + if (table_intent == 'migrate_select') { + tables_to_migrate = $('#select-tables').val(); + if (migration_intent == 'push' || migration_intent == + 'savefile') { + table_rows = wpsdb_this_table_rows; + } else { + table_rows = connection_data.table_rows; + } + } else { + if (migration_intent == 'push' || migration_intent == + 'savefile') { + tables_to_migrate = wpsdb_this_prefixed_tables; + table_rows = wpsdb_this_table_rows; + } else { + tables_to_migrate = connection_data.prefixed_tables; + table_rows = connection_data.table_rows; + } + } + + $('.progress-tables').empty(); + $('.progress-tables-hover-boxes').empty(); + + table_details = decide_tables_to_display_rows( + tables_to_migrate, table_rows); + table_rows = table_details[0]; + total_size = table_details[1]; + } else { + hooks = $.wpsdb.apply_filters( + 'wpsdb_before_migration_complete_hooks', hooks); + hooks.push('migration_complete'); + hooks = $.wpsdb.apply_filters( + 'wpsdb_after_migration_complete_hooks', hooks); + hooks.push('migration_complete_events'); + next_step_in_migration = { + fn: wpsdb_call_next_hook + }; + execute_next_step(); + return; + } + } + + if (stage == 'backup') { + $('.progress-text').html(overall_percent + '% - ' + + wpsdb_i10n.backing_up + ' "' + tables_to_migrate[i] + + '"'); + } else { + $('.progress-text').html(overall_percent + '% - ' + + wpsdb_i10n.migrating + ' "' + tables_to_migrate[i] + + '"'); + } + + last_table = 0; + if (i == (tables_to_migrate.length - 1)) { + last_table = 1; + } + + gzip = 0; + if (migration_intent != 'savefile' && parseInt( + connection_data.gzip) == 1) { + gzip = 1; + } + + var request_data = { + action: 'wpsdb_migrate_table', + intent: migration_intent, + url: remote_site, + key: secret_key, + table: tables_to_migrate[i], + form_data: form_data, + stage: stage, + current_row: current_row, + dump_filename: dump_filename, + last_table: last_table, + primary_keys: primary_keys, + gzip: gzip, + nonce: wpsdb_nonces.migrate_table, + }; + + if (migration_intent != 'savefile') { + request_data.bottleneck = connection_data.bottleneck; + request_data.prefix = connection_data.prefix; + } + + if (connection_data && connection_data.path_current_site && + connection_data.domain) { + request_data.path_current_site = connection_data.path_current_site; + request_data.domain_current_site = connection_data.domain; + } - $('.field.comments textarea', $sidebar).blur(function() { - if ($(this).val()) { - $(this).addClass('has-content'); + doing_ajax = true; + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + timeout: 0, + data: request_data, + error: function(jqXHR, textStatus, errorThrown) { + $('.progress-title').html('Migration failed'); + $('.progress-text').html(wpsdb_i10n.table_process_problem + + ' ' + tables_to_migrate[i]); + $('.progress-text').append('

    ' + + wpsdb_i10n.status + ': ' + jqXHR.status + ' ' + + jqXHR.statusText + '

    ' + wpsdb_i10n.response + + ':
    ' + jqXHR.responseText); + $('.progress-text').addClass('migration-error'); + doing_ajax = false; + console.log(jqXHR); + console.log(textStatus); + console.log(errorThrown); + migration_error = true; + migration_complete_events(); + return; + }, + success: function(data) { + doing_ajax = false; + data = data.trim(); + try { + row_information = JSON.parse(data); + } catch (variable) { + $('.progress-title').html('Migration failed'); + if ('' == data || null == data) { + $('.progress-text').html(wpsdb_i10n.table_process_problem_empty_response + + ' ' + tables_to_migrate[i]); + } else { + $('.progress-text').html(data); + } + $('.progress-text').addClass('migration-error'); + migration_error = true; + migration_complete_events(); + return; } - else { - $(this).removeClass('has-content'); + + if (typeof row_information.wpsdb_error != 'undefined' && + row_information.wpsdb_error == 1) { + $('.progress-title').html('Migration failed'); + $('.progress-text').addClass('migration-error'); + $('.progress-text').html(row_information.body); + migration_error = true; + migration_complete_events(); + return; } + + if (row_information.current_row == '-1') { + progress_size -= overall_table_progress; + overall_table_progress = 0; + last_progress = 0; + progress_size += parseInt(table_rows[ + tables_to_migrate[i]]); + i++; + row_information.current_row = ''; + row_information.primary_keys = ''; + } else { + temp_progress = parseInt(row_information.current_row); + table_progress = temp_progress - last_progress; + last_progress = temp_progress; + progress_size += table_progress; + overall_table_progress += table_progress; + } + var percent = 100 * progress_size / total_size; + $('.progress-bar').width(percent + '%'); + overall_percent = Math.floor(percent); + next_step_in_migration = { + fn: migrate_table_recursive, + args: [row_information.current_row, row_information + .primary_keys + ] + }; + execute_next_step(); + } }); + } + + next_step_in_migration = { + fn: migrate_table_recursive, + args: ['-1', ''] + }; + execute_next_step(); + } + }); // end ajax + }); + + migration_complete_events = function() { + if (false == migration_error) { + if (non_fatal_errors == '') { + if ('savefile' != migration_intent && true == $('#save_computer') + .is(':checked')) { + $('.progress-text').css('visibility', 'hidden'); + } + $('.progress-title').html(completed_msg).append( + '
    '); + } else { + $('.progress-text').html(non_fatal_errors); + $('.progress-text').addClass('migration-error'); + $('.progress-title').html(wpsdb_i10n.completed_with_some_errors); + } + $('.progress-bar-wrapper').hide(); + } + + $('.migration-controls').hide(); + + // reset migration variables so consecutive migrations work correctly + hooks = []; + call_stack = []; + migration_error = false; + currently_migrating = false; + migration_completed = true; + migration_paused = false; + migration_cancelled = false; + doing_ajax = false; + non_fatal_errors = ''; + + $('.progress-label').remove(); + $('.migration-progress-ajax-spinner').remove(); + $('.close-progress-content').show(); + $('#overlay').css('cursor', 'pointer'); + clearInterval(elapsed_interval); + }; + + migration_complete = function() { + $('.migration-controls').fadeOut(); + if (migration_intent == 'savefile') { + currently_migrating = false; + var migrate_complete_text = 'Migration complete'; + if ($('#save_computer').is(':checked')) { + var url = wpsdb_this_download_url + encodeURIComponent( + dump_filename); + if ($('#gzip_file').is(':checked')) { + url += '&gzip=1'; + } + window.location = url; + } else { + migrate_complete_text = wpsdb_i10n.completed_dump_located_at + + '
    ' + dump_url + '.'; + } + + if (migration_error == false) { + $('.progress-text').html(migrate_complete_text); + migration_complete_events(); + $('.progress-title').html(completed_msg); + } + + } else { // rename temp tables, delete old tables + $('.progress-text').html('Finalizing migration'); + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_finalize_migration', + intent: migration_intent, + url: remote_site, + key: secret_key, + form_data: form_data, + prefix: connection_data.prefix, + temp_prefix: connection_data.temp_prefix, + tables: tables_to_migrate.join(','), + nonce: wpsdb_nonces.finalize_migration, + }, + error: function(jqXHR, textStatus, errorThrown) { + $('.progress-title').html(wpsdb_i10n.migration_failed); + $('.progress-text').html(wpsdb_i10n.finalize_tables_problem); + $('.progress-text').addClass('migration-error'); + alert(jqXHR + ' : ' + textStatus + ' : ' + errorThrown); + migration_error = true; + migration_complete_events(); + return; + }, + success: function(data) { + if ($.trim(data) != '') { + $('.progress-title').html(wpsdb_i10n.migration_failed); + $('.progress-text').html(data); + $('.progress-text').addClass('migration-error'); + migration_error = true; + migration_complete_events(); + return; + } + next_step_in_migration = { + fn: wpsdb_call_next_hook + }; + execute_next_step(); + } }); + } + }; + + // close progress pop up once migration is completed + $('body').delegate('.close-progress-content-button', 'click', function( + e) { + hide_overlay(); + }); + + $('body').delegate('#overlay', 'click', function() { + if (migration_completed == true) { + hide_overlay(); + } + }); + + function hide_overlay() { + var height = $('.progress-content').outerHeight(); + $('.progress-content').animate({ + 'top': '-' + height + 'px' + }, 400, 'swing', function() { + $('#overlay').remove(); + $('.progress-content').remove(); + }); + migration_completed = false; + } + + // AJAX save button profile + $('.save-settings-button').click(function(event) { + var profile; + $(this).blur(); + event.preventDefault(); + + if (doing_save_profile) { + return; + } + + // check that they've selected some tables to migrate + if ($('#migrate-selected').is(':checked') && $('#select-tables').val() == + null) { + alert(wpsdb_i10n.please_select_one_table); + return; + } + + if ($.trim($('.create-new-profile').val()) == '' && $('#create_new') + .is(':checked')) { + alert(wpsdb_i10n.enter_name_for_profile); + $('.create-new-profile').focus(); + return; + } + + var create_new_profile = false; + + if ($('#create_new').is(':checked')) { + create_new_profile = true; + } + var profile_name = $('.create-new-profile').val(); + + doing_save_profile = true; + profile = $('#migrate-form').serialize(); + + $('.save-settings-button').after(''); + $(this).attr('disabled', 'disabled'); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_save_profile', + profile: profile, + nonce: wpsdb_nonces.save_profile, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.save_profile_problem); + $('.save-settings-button').removeAttr('disabled'); + $('.save-profile-ajax-spinner').remove(); + $('.save-settings-button').after( + '' + wpsdb_i10n.saved + + ''); + $('.ajax-success-msg').fadeOut(2000, function() { + $(this).remove(); + }); + doing_save_profile = false; + }, + success: function(data) { + $('.save-settings-button').removeAttr('disabled'); + $('.save-profile-ajax-spinner').remove(); + $('.save-settings-button').after( + '' + wpsdb_i10n.saved + + ''); + $('.ajax-success-msg').fadeOut(2000, function() { + $(this).remove(); + }); + doing_save_profile = false; + $('.create-new-profile').val(''); + + if (create_new_profile) { + var new_profile_key = parseInt(data, 10); + var new_profile_id = new_profile_key + 1; + var new_li = + '
  • '; + $('#create_new').parents('li').before(new_li); + $('#profile-' + new_profile_id).attr('checked', 'checked'); + } + } + }); + }); + + // progress label updating + $('body').delegate('.progress-chunk-hover', 'mousemove', function(e) { + mX = e.pageX; + offset = $('.progress-bar-wrapper').offset(); + label_offset = $('.progress-label').outerWidth() / 2; + mX = (mX - offset.left) - label_offset; + $('.progress-label').css('left', mX + 'px'); + $('.progress-label').html($(this).attr('data-table')); + }); + + // show / hide progress lavel on hover + $('body').delegate('.progress-chunk-hover', 'hover', function(event) { + if (event.type === 'mouseenter') { + $('.progress-label').addClass('label-visible'); + } else { + $('.progress-label').removeClass('label-visible'); + } + }); + + // move around textarea depending on whether or not the push/pull options are selected + connection_info_box = $('.connection-info-wrapper'); + move_connection_info_box(); + + $('.migrate-selection.option-group input[type=radio]').change(function() { + move_connection_info_box(); + if (connection_established) { + change_replace_values(); + } + }); + + // save file (export) / push / pull special conditions + function move_connection_info_box() { + $('.connection-status').hide(); + $('.prefix-notice').hide(); + $('.ssl-notice').hide(); + $('.different-plugin-version-notice').hide(); + $('.step-two').show(); + $('.backup-options').show(); + $('.keep-active-plugins').show(); + $('.directory-permission-notice').hide(); + $('#create-backup').removeAttr('disabled'); + $('#create-backup-label').removeClass('disabled'); + $('.backup-option-disabled').hide(); + var connection_info = $.trim($('.pull-push-connection-info').val()).split( + "\n"); + if ($('#pull').is(':checked')) { + $('.pull-list li').append(connection_info_box); + connection_info_box.show(); + if (connection_established) { + $('.connection-status').hide(); + $('.step-two').show(); + $('.table-prefix').html(connection_data.prefix); + $('.uploads-dir').html(wpsdb_this_uploads_dir); + if (profile_name_edited == false) { + var profile_name = get_domain_name(connection_info[0]); + $('.create-new-profile').val(profile_name); + } + if (show_prefix_notice == true) { + $('.prefix-notice.pull').show(); + } + if (show_ssl_notice == true) { + $('.ssl-notice').show(); + } + if (show_version_notice == true) { + $('.different-plugin-version-notice').show(); + $('.step-two').hide(); + } + $('.directory-scope').html('local'); + if (false == wpsdb_write_permission) { + $('#create-backup').prop('checked', false); + $('#create-backup').attr('disabled', 'disabled'); + $('#create-backup-label').addClass('disabled'); + $('.backup-option-disabled').show(); + $('.upload-directory-location').html(wpsdb_this_upload_dir_long); + } + } else { + $('.connection-status').show(); + $('.step-two').hide(); + } + } else if ($('#push').is(':checked')) { + $('.push-list li').append(connection_info_box); + connection_info_box.show(); + if (connection_established) { + $('.connection-status').hide(); + $('.step-two').show(); + $('.table-prefix').html(wpsdb_this_prefix); + $('.uploads-dir').html(connection_data.uploads_dir); + if (profile_name_edited == false) { + var profile_name = get_domain_name(connection_info[0]); + $('.create-new-profile').val(profile_name); + } + if (show_prefix_notice == true) { + $('.prefix-notice.push').show(); + } + if (show_ssl_notice == true) { + $('.ssl-notice').show(); + } + if (show_version_notice == true) { + $('.different-plugin-version-notice').show(); + $('.step-two').hide(); + } + $('.directory-scope').html('remote'); + if ('0' == connection_data.write_permissions) { + $('#create-backup').prop('checked', false); + $('#create-backup').attr('disabled', 'disabled'); + $('#create-backup-label').addClass('disabled'); + $('.backup-option-disabled').show(); + $('.upload-directory-location').html(connection_data.upload_dir_long); + } + } else { + $('.connection-status').show(); + $('.step-two').hide(); + } + } else if ($('#savefile').is(':checked')) { + $('.connection-status').hide(); + $('.step-two').show(); + $('.table-prefix').html(wpsdb_this_prefix); + if (profile_name_edited == false) { + $('.create-new-profile').val(''); + } + $('.backup-options').hide(); + $('.keep-active-plugins').hide(); + if (false == wpsdb_write_permission) { + $('.directory-permission-notice').show(); + $('.step-two').hide(); + } + } + $.wpsdb.do_action('move_connection_info_box'); + } + + function change_replace_values() { + if ($('#push').is(':checked') || $('#savefile').is(':checked')) { + if (last_replace_switch == '' || last_replace_switch == 'pull') { + $('.replace-row').each(function() { + var old_val = $('.old-replace-col input', this).val(); + $('.old-replace-col input', this).val($( + '.replace-right-col input', this).val()); + $('.replace-right-col input', this).val(old_val); + }); + } + $('#select-tables').remove(); + $('.select-tables-wrap').prepend(push_select); + $('#select-post-types').remove(); + $('.select-post-types-wrap').prepend(push_post_type_select); + $('#select-backup').remove(); + $('.backup-tables-wrap').prepend(push_select_backup); + last_replace_switch = 'push'; + } else if ($('#pull').is(':checked')) { + if (last_replace_switch == '' || last_replace_switch == 'push') { + $('.replace-row').each(function() { + var old_val = $('.old-replace-col input', this).val(); + $('.old-replace-col input', this).val($( + '.replace-right-col input', this).val()); + $('.replace-right-col input', this).val(old_val); + }); + } + $('#select-tables').remove(); + $('.select-tables-wrap').prepend(pull_select); + $('#select-post-types').remove(); + $('.select-post-types-wrap').prepend(pull_post_type_select); + $('#select-backup').remove(); + $('.backup-tables-wrap').prepend(pull_select_backup); + last_replace_switch = 'pull'; + } + } + + // hide second section if pull or push is selected with no connection established + if (($('#pull').is(':checked') || $('#push').is(':checked')) && ! + connection_established) { + $('.step-two').hide(); + $('.connection-status').show(); + } + + // show / hide GUID helper description + $('.general-helper').click(function(e) { + var icon = $(this), + bubble = $(this).next(); + + // Close any that are already open + $('.helper-message').not(bubble).hide(); + + var position = icon.position(); + if (bubble.hasClass('bottom')) { + bubble.css({ + 'left': (position.left - bubble.width() / 2) + 'px', + 'top': (position.top + icon.height() + 9) + 'px' + }); + } else { + bubble.css({ + 'left': (position.left + icon.width() + 9) + 'px', + 'top': (position.top + icon.height() / 2 - 18) + 'px' + }); + } + + bubble.toggle(); + e.stopPropagation(); + }); + + $('body').click(function() { + $('.helper-message').hide(); + }); + + $('.helper-message').click(function(e) { + e.stopPropagation(); + }); + + // migrate / settings tabs + $('.nav-tab').click(function() { + $('.nav-tab').removeClass('nav-tab-active'); + $(this).addClass('nav-tab-active'); + $('.content-tab').hide(); + $('.' + $(this).attr('data-div-name')).show(); + + var hash = $(this).attr('data-div-name'); + hash = hash.replace('-tab', ''); + window.location.hash = hash; + + if ($(this).hasClass('help')) { + refresh_debug_log(); + } + }); + + // repeatable fields + $('body').delegate('.add-row', 'click', function() { + $(this).parents('tr').before($('.original-repeatable-field').clone() + .removeClass('original-repeatable-field')); + }); + + // repeatable fields + $('body').delegate('.replace-remove-row', 'click', function() { + $(this).parents('tr').remove(); + if ($('.replace-row').length < 2) { + $('.no-replaces-message').show(); + } + }); + + $('.add-replace').click(function() { + $('.replace-fields').prepend($('.original-repeatable-field').clone() + .removeClass('original-repeatable-field')); + $('.no-replaces-message').hide(); + }); + + $('body').delegate('#find-and-replace-sort tbody tr.replace-row', + 'hover', function(event) { + if (event.type === 'mouseenter') { + $('.replace-remove-row', this).show(); + } else { + $('.replace-remove-row', this).hide(); + } + }); + + $('#find-and-replace-sort tbody').sortable({ + items: '> tr:not(.pin)', + handle: 'td:first', + start: function() { + $('.sort-handle').css('cursor', '-webkit-grabbing'); + $('.sort-handle').css('cursor', '-moz-grabbing'); + }, + stop: function() { + $('.sort-handle').css('cursor', '-webkit-grab'); + $('.sort-handle').css('cursor', '-moz-grab'); + } + }); + + // delete saved profiles + $('body').delegate('.save-migration-profile-wrap li', 'hover', function( + event) { + if (event.type === 'mouseenter') { + $('.delete-profile', this).show(); + } else { + $('.delete-profile', this).hide(); + } + }); + + // check for hash in url (settings || migrate) switch tabs accordingly + if (window.location.hash) { + var hash = window.location.hash.substring(1); + switch_to_plugin_tab(hash, false); + } + + if (get_query_var('install-plugin') != '') { + hash = 'addons'; + switch_to_plugin_tab(hash, true); + } + + function switch_to_plugin_tab(hash, skip_addons_check) { + $('.nav-tab').removeClass('nav-tab-active'); + $('.nav-tab.' + hash).addClass('nav-tab-active'); + $('.content-tab').hide(); + $('.' + hash + '-tab').show(); + + if (hash == 'help') { + refresh_debug_log(); + } + } + + // regenerates the saved secret key + $('.reset-api-key').click(function() { + var answer = confirm(wpsdb_i10n.reset_api_key); + + if (!answer || doing_reset_api_key_ajax) { + return; + } + + doing_reset_api_key_ajax = true; + $('.reset-api-key').after(''); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_reset_api_key', + nonce: wpsdb_nonces.reset_api_key, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.reset_api_key_problem); + $('.reset-api-key-ajax-spinner').remove(); + doing_reset_api_key_ajax = false; + }, + success: function(data) { + $('.reset-api-key-ajax-spinner').remove(); + doing_reset_api_key_ajax = false; + $('.connection-info').html(data); + } + }); + + }); + + // show / hide table select box when specific settings change + $('input.multiselect-toggle').change(function() { + $(this).parents('.expandable-content').children('.select-wrap').toggle(); + }); + + $('.show-multiselect').each(function() { + if ($(this).is(':checked')) { + $(this).parents('.option-section').children( + '.header-expand-collapse').children('.expand-collapse-arrow').removeClass( + 'collapsed'); + $(this).parents('.expandable-content').show(); + $(this).parents('.expandable-content').children('.select-wrap').toggle(); + } + }); + + $('input[name=backup_option]').change(function() { + $('.backup-tables-wrap').hide(); + if ($(this).val() == 'backup_manual_select') { + $('.backup-tables-wrap').show(); + } + }); + + if ($('#backup-manual-select').is(':checked')) { + $('.backup-tables-wrap').show(); + } + + $('.plugin-compatibility-save').click(function() { + if (doing_plugin_compatibility_ajax) { + return; + } + $(this).addClass('disabled'); + select_element = $('#selected-plugins'); + $(select_element).attr('disabled', 'disabled'); + + doing_plugin_compatibility_ajax = true; + $(this).after('' + ); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_blacklist_plugins', + blacklist_plugins: $(select_element).val(), + }, + error: function(jqXHR, textStatus, errorThrown) { + // replace with l10n string when available + alert( + 'A problem occurred when trying to add plugins to backlist.\r\n\r\nStatus: ' + + jqXHR.status + ' ' + jqXHR.statusText + + '\r\n\r\nResponse:\r\n' + jqXHR.responseText); + $(select_element).removeAttr('disabled'); + $('.plugin-compatibility-save').removeClass('disabled'); + doing_plugin_compatibility_ajax = false; + $('.plugin-compatibility-spinner').remove(); + $('.plugin-compatibility-success-msg').show().fadeOut(2000); + }, + success: function(data) { + if ('' != $.trim(data)) { + alert(data); + } + $(select_element).removeAttr('disabled'); + $('.plugin-compatibility-save').removeClass('disabled'); + doing_plugin_compatibility_ajax = false; + $('.plugin-compatibility-spinner').remove(); + $('.plugin-compatibility-success-msg').show().fadeOut(2000); + } + }); + }); + + // delete a profile from the migrate form area + $('body').delegate('.delete-profile', 'click', function() { + var name = $(this).next().clone(); + $('input', name).remove(); + var name = $.trim($(name).html()); + var answer = confirm(wpsdb_i10n.remove_profile + ' "' + name + '"'); + + if (!answer) { + return; + } + + $(this).parent().fadeOut(500); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_delete_migration_profile', + profile_id: $(this).attr('data-profile-id'), + nonce: wpsdb_nonces.delete_migration_profile, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.remove_profile_problem); + }, + success: function(data) { + if (data == '-1') { + alert(wpsdb_i10n.remove_profile_not_found); + } + } + }); + + }); + + // deletes a profile from the main profile selection screen + $('.main-list-delete-profile-link').click(function() { + var name = $(this).prev().html(); + var answer = confirm(wpsdb_i10n.remove_profile + ' "' + name + '"'); + + if (!answer) { + return; + } + + $(this).parent().fadeOut(500); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_delete_migration_profile', + profile_id: $(this).attr('data-profile-id'), + nonce: wpsdb_nonces.delete_migration_profile, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.remove_profile_problem); + } + }); + }); - var admin_url = ajaxurl.replace( '/admin-ajax.php', '' ), - spinner_url = admin_url + '/images/wpspin_light.gif'; - - var spinner = new Image(); - spinner.src = spinner_url; + // warn the user when editing the connection info after a connection has + // been established + $('body').delegate('.temp-disabled', 'click', function() { + var answer = confirm(wpsdb_i10n.change_connection_info); - $('#migrate-form').submit(function() { - $('p.submit', this).append(''); + if (!answer) { + return; + } else { + $('.ssl-notice').hide(); + $('.different-plugin-version-notice').hide(); + $('.migrate-db-button').show(); + $('.temp-disabled').removeAttr('readonly'); + $('.temp-disabled').removeClass('temp-disabled'); + $('.connect-button').show(); + $('.step-two').hide(); + $('.connection-status').show().html(wpsdb_i10n.enter_connection_info); + connection_established = false; + } }); + + // ajax request for settings page when checking/unchecking setting radio + // buttons + $('.settings-tab input[type=checkbox]').change(function() { + if ('plugin-compatibility' == $(this).attr('id')) return; + var checked = $(this).is(':checked'); + var setting = $(this).attr('id'); + + $(this).parent().append(''); + var $label = $(this).parent(); + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: { + action: 'wpsdb_save_setting', + checked: checked, + setting: setting, + nonce: wpsdb_nonces.save_setting, + }, + error: function(jqXHR, textStatus, errorThrown) { + alert(wpsdb_i10n.save_settings_problem); + $('.ajax-spinner').remove(); + }, + success: function(data) { + $('.ajax-spinner').remove(); + $($label).append('' + + wpsdb_i10n.saved + ''); + $('.ajax-success-msg').fadeOut(2000, function() { + $(this).remove(); + }); + } + }); + + }); + + // disable form submissions + $('.migrate-form').submit(function(e) { + e.preventDefault(); + }); + + // fire connection_box_changed when the connect button is pressed + $('.connect-button').click(function(event) { + event.preventDefault(); + $(this).blur(); + connection_box_changed(); + }); + + // send paste even to connection_box_changed() function + $('.pull-push-connection-info').bind('paste', function(e) { + var $this = this; + setTimeout(function() { + connection_box_changed(); + }, 0); + + }); + + $('body').delegate('.try-again', 'click', function() { + connection_box_changed(); + }); + + $('body').delegate('.try-http', 'click', function() { + var connection_info = $.trim($('.pull-push-connection-info').val()) + .split("\n"); + var new_url = connection_info[0].replace('https', 'http'); + var new_contents = new_url + "\n" + connection_info[1]; + $('.pull-push-connection-info').val(new_contents); + connection_box_changed(); + }); + + $('.create-new-profile').change(function() { + profile_name_edited = true; + }); + + $('body').delegate('.temporarily-disable-ssl', 'click', function() { + if (window.location.hash) { + var hash = window.location.hash.substring(1); + } + $(this).attr('href', $(this).attr('href') + '&hash=' + hash); + }); + + // fired when the connection info box changes (e.g. gets pasted into) + function connection_box_changed(data) { + var $this = $('.pull-push-connection-info'); + + if (doing_ajax || $($this).hasClass('temp-disabled')) { + return; + } + + var data = $('.pull-push-connection-info').val(); + + var connection_info = $.trim(data).split("\n"); + var error = false; + var error_message = ''; + + if (connection_info == '') { + error = true; + error_message = wpsdb_i10n.connection_info_missing; + } + + if (connection_info.length != 2 && !error) { + error = true; + error_message = wpsdb_i10n.connection_info_incorrect; + } + + if (!error && !validate_url(connection_info[0])) { + error = true; + error_message = wpsdb_i10n.connection_info_url_invalid; + } + + if (!error && connection_info[1].length != 32) { + error = true; + error_message = wpsdb_i10n.connection_info_key_invalid; + } + + if (!error && connection_info[0] == wpsdb_connection_info[0]) { + error = true; + error_message = wpsdb_i10n.connection_info_local_url; + } + + if (!error && connection_info[1] == wpsdb_connection_info[1]) { + error = true; + error_message = wpsdb_i10n.connection_info_local_key; + } + + if (error) { + $('.connection-status').html(error_message); + $('.connection-status').addClass( + 'notification-message error-notice migration-error'); + return; + } + + if (wpsdb_openssl_available == false) { + connection_info[0] = connection_info[0].replace('https://', 'http://'); + var new_connection_info_contents = connection_info[0] + "\n" + + connection_info[1]; + $('.pull-push-connection-info').val(new_connection_info_contents); + } + + show_prefix_notice = false; + doing_ajax = true; + disable_export_type_controls(); + + if ($('.basic-access-auth-wrapper').is(':visible')) { + connection_info[0] = connection_info[0].replace(/\/\/(.*)@/, '//'); + connection_info[0] = connection_info[0].replace('//', '//' + + encodeURIComponent($.trim($('.auth-username').val())) + ':' + + encodeURIComponent($.trim($('.auth-password').val())) + '@'); + var new_connection_info_contents = connection_info[0] + "\n" + + connection_info[1]; + $('.pull-push-connection-info').val(new_connection_info_contents); + $('.basic-access-auth-wrapper').hide(); + } + + $('.step-two').hide(); + $('.ssl-notice').hide(); + $('.prefix-notice').hide(); + $('.connection-status').show(); + + $('.connection-status').html(wpsdb_i10n.establishing_remote_connection); + $('.connection-status').removeClass( + 'notification-message error-notice migration-error'); + $('.connection-status').append(''); + + var intent = $('input[name=action]:checked').val(); + + profile_name_edited = false; + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'json', + cache: false, + data: { + action: 'wpsdb_verify_connection_to_remote_site', + url: connection_info[0], + key: connection_info[1], + intent: intent, + nonce: wpsdb_nonces.verify_connection_to_remote_site, + }, + error: function(jqXHR, textStatus, errorThrown) { + $('.connection-status').html(wpsdb_i10n.connection_local_server_problem + + ' (#100)'); + $('.connection-status').append('

    Status: ' + jqXHR.status + + ' ' + jqXHR.statusText + '

    Response:
    ' + + jqXHR.responseText); + $('.connection-status').addClass( + 'notification-message error-notice migration-error'); + $('.ajax-spinner').remove(); + doing_ajax = false; + enable_export_type_controls(); + }, + success: function(data) { + $('.ajax-spinner').remove(); + doing_ajax = false; + enable_export_type_controls(); + + if (typeof data.wpsdb_error != 'undefined' && data.wpsdb_error == + 1) { + $('.connection-status').html(data.body); + $('.connection-status').addClass( + 'notification-message error-notice migration-error'); + + if (data.body.indexOf('401 Unauthorized') > -1) { + $('.basic-access-auth-wrapper').show(); + } + return; + } + + var profile_name = get_domain_name(connection_info[0]); + $('.create-new-profile').val(profile_name); + + $('.pull-push-connection-info').addClass('temp-disabled'); + $('.pull-push-connection-info').attr('readonly', 'readonly'); + $('.connect-button').hide(); + + $('.connection-status').hide(); + $('.step-two').show(); + + maybe_show_ssl_warning(connection_info[0], connection_info[1], + data.scheme); + maybe_show_version_warning(data.plugin_version, connection_info[ + 0]); + maybe_show_prefix_notice(data.prefix); + + connection_established = true; + connection_data = data; + move_connection_info_box(); + + var table_select = document.createElement('select'); + $(table_select).attr({ + multiple: 'multiple', + name: 'select_tables[]', + id: 'select-tables', + class: 'multiselect' + }); + + $.each(connection_data.tables, function(index, value) { + $(table_select).append(''); + }); + + pull_select = table_select; + push_select_backup = $(table_select).clone(); + $(push_select_backup).attr({ + name: 'select_backup[]', + id: 'select-backup' + }); + + var post_type_select = document.createElement('select'); + $(post_type_select).attr({ + multiple: 'multiple', + name: 'select_post_types[]', + id: 'select-post-types', + class: 'multiselect' + }); + + $.each(connection_data.post_types, function(index, value) { + $(post_type_select).append(''); + }); + + pull_post_type_select = post_type_select; + + if ($('#pull').is(':checked')) { + $('#new-url').val(remove_protocol(wpsdb_this_url)); + $('#new-path').val(wpsdb_this_path); + if (wpsdb_is_multisite == true) { + $('#new-domain').val(wpsdb_this_domain); + } + $('#old-url').val(remove_protocol(data.url)); + $('#old-path').val(data.path); + $('#select-tables').remove(); + $('.select-tables-wrap').prepend(pull_select); + $('#select-post-types').remove(); + $('.select-post-types-wrap').prepend(pull_post_type_select); + $('.table-prefix').html(data.prefix); + $('.uploads-dir').html(wpsdb_this_uploads_dir); + } else { + $('#select-backup').remove(); + $('.backup-tables-wrap').prepend(push_select_backup); + $('#new-url').val(remove_protocol(data.url)); + $('#new-path').val(data.path); + } + + next_step_in_migration = { + fn: $.wpsdb.do_action, + args: ['verify_connection_to_remote_site', connection_data] + }; + execute_next_step(); + } + }); + } + + $('body').delegate('.pause-resume', 'click', function() { + if (true == migration_paused) { + migration_paused = false; + doing_ajax = true; + $('.progress-title').html(previous_progress_title); + $('.progress-text').html(previous_progress_text); + $('.migration-progress-ajax-spinner').show(); + $('.pause-resume').html(wpsdb_i10n.pause); + // resume the timer + elapsed_interval = setInterval(count, 1000); + execute_next_step(); + } else { + migration_paused = true; + doing_ajax = false; + previous_progress_title = $('.progress-title').html(); + previous_progress_text = $('.progress-text').html(); + $('.progress-title').html(wpsdb_i10n.migration_paused); + $('.pause-resume').html(wpsdb_i10n.resume); + $('.progress-text').html(wpsdb_i10n.completing_current_request); + } + }); + + $('body').delegate('.cancel', 'click', function() { + migration_cancelled = true; + migration_paused = false; + $('.progress-text').html(wpsdb_i10n.completing_current_request); + $('.progress-title').html(wpsdb_i10n.cancelling_migration); + $('.migration-controls').fadeOut(); + $('.migration-progress-ajax-spinner').show(); + + if (false == doing_ajax) { + execute_next_step(); + } + }); + + execute_next_step = function() { + if (true == migration_paused) { + $('.migration-progress-ajax-spinner').hide(); + // pause the timer + clearInterval(elapsed_interval); + $('.progress-text').html(wpsdb_i10n.paused); + return; + } else if (true == migration_cancelled) { + migration_intent = $('input[name=action]:checked').val(); + + if ('savefile' == migration_intent) { + progress_msg = wpsdb_i10n.removing_local_sql; + } else if ('pull' == migration_intent) { + if ('backup' == stage) { + progress_msg = wpsdb_i10n.removing_local_backup; + } else { + progress_msg = wpsdb_i10n.removing_local_temp_tables; + } + } else if ('push' == migration_intent) { + if ('backup' == stage) { + progress_msg = wpsdb_i10n.removing_remote_sql; + } else { + progress_msg = wpsdb_i10n.removing_remote_temp_tables; + } + } + $('.progress-text').html(progress_msg); + + var request_data = { + action: 'wpsdb_cancel_migration', + intent: migration_intent, + url: remote_site, + key: secret_key, + stage: stage, + dump_filename: dump_filename, + form_data: form_data, + }; + + if (typeof connection_data != 'undefined') { + request_data.temp_prefix = connection_data.temp_prefix; + } + + $.ajax({ + url: ajaxurl, + type: 'POST', + dataType: 'text', + cache: false, + data: request_data, + error: function(jqXHR, textStatus, errorThrown) { + $('.progress-title').html(wpsdb_i10n.migration_cancellation_failed); + $('.progress-text').html(wpsdb_i10n.manually_remove_temp_files); + $('.progress-text').append('

    Status: ' + jqXHR.status + + ' ' + jqXHR.statusText + '

    Response:
    ' + + jqXHR.responseText); + $('.progress-text').addClass('migration-error'); + console.log(jqXHR); + console.log(textStatus); + console.log(errorThrown); + migration_error = true; + migration_complete_events(); + return; + }, + success: function(data) { + doing_ajax = false; + data = $.trim(data); + if (data != '') { + $('.progress-title').html(wpsdb_i10n.migration_cancellation_failed); + $('.progress-text').html(data); + $('.progress-text').addClass('migration-error'); + migration_error = true; + migration_complete_events(); + return; + } + completed_msg = wpsdb_i10n.migration_cancelled; + $('.progress-text').hide(); + migration_complete_events(); + } + }); + } else { + next_step_in_migration.fn.apply(null, next_step_in_migration.args); + } + } + }); })(jQuery); + +function validate_url(url) { + return /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i + .test(url); +} diff --git a/asset/sass/styles.scss b/asset/sass/styles.scss deleted file mode 100644 index 1b97ccd..0000000 --- a/asset/sass/styles.scss +++ /dev/null @@ -1,188 +0,0 @@ -#migrate-form { - padding-top: 10px; -} - -.form-table { - .row-new-url, - .row-new-path, - .row-revisions { - th, td { - padding-bottom: 20px; - border-bottom: 1px solid #ccc; - } - } - - .row-old-path, - .row-save-file, - .row-guids { - th, td { - padding-top: 20px; - } - } -} - -p.submit { - overflow: hidden; - padding-top: 20px; - border-top: 1px solid #ccc; - margin-top: 20px; - - input { - float: left; - } - - img { - float: left; - margin: 3px 0 0 5px; - } -} - -#wpmdb-container { - position: relative; -} - -#wpmdb-main { - margin-right: 320px; - min-height: 1200px; -} - -#wpmdb-sidebar { - position: absolute; - top: 0; - right: 0; - width: 250px; - border: 1px solid #ccc; - padding: 20px; - - .author { - padding-bottom: 20px; - margin-bottom: 20px; - border-bottom: 1px solid #ccc; - overflow: hidden; - - img { - float: left; - margin-right: 20px; - } - - .desc { - float: left; - } - - h3 { - font-size: 12px; - margin: 0; - } - - h2 { - font-size: 18px; - margin: 0; - padding: 0; - - a { - color: #464646; - text-decoration: none; - - &:hover { - color: #000; - } - } - } - - p { - margin: 0; - } - } - - .subscribe { - padding-bottom: 20px; - margin-bottom: 20px; - border-bottom: 1px solid #ccc; - - h2 { - padding: 0; - margin: 0; - margin-bottom: 0.5em; - color: #666; - font-size: 20px; - } - - ul { - list-style-type: disc; - } - - li { - margin-left: 1.5em; - color: #666; - } - - p { - margin: 0; - } - - p.interesting { - margin-bottom: 1em; - } - - .error { - color: red; - font-weight: bold; - margin-bottom: 1em; - } - - .thanks { - color: #333; - font-weight: bold; - font-size: 14px; - } - - .field { - margin-bottom: 1em; - - p { - margin-bottom: 0.3em; - } - - .willing-copy { - font-weight: bold; - font-size: 14px; - line-height: 1.4em; - margin-bottom: 1em; - } - - &.how-much { - input { - width: 50px; - } - } - - &.notify-me { - input { - position: absolute; - } - - label { - display: block; - padding-left: 20px; - } - - } - - &.comments { - textarea { - width: 230px; - height: 3em; - - &.has-content, - &:focus { - height: 5em; - } - } - } - - &.submit-button { - margin-bottom: 0; - } - } - } -} \ No newline at end of file diff --git a/class/wpsdb-addon.php b/class/wpsdb-addon.php new file mode 100644 index 0000000..20a196c --- /dev/null +++ b/class/wpsdb-addon.php @@ -0,0 +1,63 @@ +=' ); + $this->version_required = $version_required; + if( false == $result ) $this->hook_version_requirement_actions(); + + if ( $result ) { + // If pre-1.1.2 version of Media Files addon, + // then it's not supported by this version of core + if ( empty( $this->plugin_version ) ) { + $result = false; + } + // Check that this version of core supports the addon version + else { + $plugin_basename = sprintf( '%1$s/%1$s.php', $this->plugin_slug ); + $required_addon_version = $this->addons[$plugin_basename]['required_version']; + $result = version_compare( $this->plugin_version, $required_addon_version, '>=' ); + } + } + + return $result; + } + + function hook_version_requirement_actions() { + add_action( 'wpsdb_notices', array( $this, 'version_requirement_actions' ) ); + } + + function version_requirement_actions() { + $addon_requirement_check = get_option( 'wpsdb_addon_requirement_check', array() ); + // we only want to delete the transients once, here we keep track of which versions we've checked + if( ! isset( $addon_requirement_check[$this->plugin_slug] ) || $addon_requirement_check[$this->plugin_slug] != $GLOBALS['wpsdb_meta'][$this->plugin_slug]['version'] ) { + delete_site_transient( 'wpsdb_upgrade_data' ); + delete_site_transient( 'update_plugins' ); + $addon_requirement_check[$this->plugin_slug] = $GLOBALS['wpsdb_meta'][$this->plugin_slug]['version']; + update_option( 'wpsdb_addon_requirement_check', $addon_requirement_check ); + } + $this->version_requirement_warning(); + } + + function version_requirement_warning() { ?> +
    + Update Required — + get_plugin_name(); + $required = $this->version_required; + $installed = $GLOBALS['wpsdb_meta']['wp-sync-db']['version']; + $wpsdb_basename = sprintf( '%s/%s.php', $GLOBALS['wpsdb_meta']['wp-sync-db']['folder'], 'wp-sync-db' ); + $update = wp_nonce_url( network_admin_url( 'update.php?action=upgrade-plugin&plugin=' . urlencode( $wpsdb_basename ) ), 'upgrade-plugin_' . $wpsdb_basename ); + printf( __( 'The version of %1$s you have installed, requires version %2$s of WP Sync DB. You currently have %3$s installed. Update Now', 'wp-sync-db' ), $addon_name, $required, $installed, $update ); + ?> +
    + settings = get_option( 'wpsdb_settings' ); + + $this->addons = array( + 'wp-sync-db-media-files/wp-sync-db-media-files.php' => array( + 'name' => 'Media Files', + 'required_version' => '1.1.4b1', + ), + 'wp-sync-db-cli/wp-sync-db-cli.php' => array( + 'name' => 'CLI', + 'required_version' => '1.0b1', + ) + ); + + $this->invalid_content_verification_error = __( 'Invalid content verification signature, please verify the connection information on the remote site and try again.', 'wp-sync-db' ); + + $this->transient_timeout = 60 * 60 * 12; + $this->transient_retry_timeout = 60 * 60 * 2; + + $this->plugin_file_path = $plugin_file_path; + $this->plugin_dir_path = plugin_dir_path( $plugin_file_path ); + $this->plugin_folder_name = basename( $this->plugin_dir_path ); + $this->plugin_basename = plugin_basename( $plugin_file_path ); + $this->template_dir = $this->plugin_dir_path . 'template' . DS; + $this->plugin_title = ucwords( str_ireplace( '-', ' ', basename( $plugin_file_path ) ) ); + $this->plugin_title = str_ireplace( array( 'db', 'wp', '.php' ), array( 'DB', 'WP', '' ), $this->plugin_title ); + + if ( is_multisite() ) { + $this->plugin_base = 'settings.php?page=wp-sync-db'; + } + else { + $this->plugin_base = 'tools.php?page=wp-sync-db'; + } + + // allow devs to change the temporary prefix applied to the tables + $this->temp_prefix = apply_filters( 'wpsdb_temporary_prefix', $this->temp_prefix ); + } + + function template( $template ) { + include $this->template_dir . $template . '.php'; + } + + function open_ssl_enabled() { + if ( defined( 'OPENSSL_VERSION_TEXT' ) ) { + return true; + } + else { + return false; + } + } + + function set_time_limit() { + if ( !function_exists( 'ini_get' ) || !ini_get( 'safe_mode' ) ) { + @set_time_limit( 0 ); + } + } + + function remote_post( $url, $data, $scope, $args = array(), $expecting_serial = false ) { + $this->set_time_limit(); + + if( function_exists( 'fsockopen' ) && strpos( $url, 'https://' ) === 0 && $scope == 'ajax_verify_connection_to_remote_site' ) { + $url_parts = parse_url( $url ); + $host = $url_parts['host']; + if( $pf = @fsockopen( $host, 443, $err, $err_string, 1 ) ) { + // worked + fclose( $pf ); + } + else { + // failed + $url = substr_replace( $url, 'http', 0, 5 ); + } + } + + $sslverify = ( $this->settings['verify_ssl'] == 1 ? true : false ); + + $default_remote_post_timeout = apply_filters( 'wpsdb_default_remote_post_timeout', 60 * 20 ); + + $args = wp_parse_args( $args, array( + 'timeout' => $default_remote_post_timeout, + 'blocking' => true, + 'sslverify' => $sslverify, + ) ); + + $args['method'] = 'POST'; + if( ! isset( $args['body'] ) ) { + $args['body'] = $this->array_to_multipart( $data ); + } + $args['headers']['Content-Type'] = 'multipart/form-data; boundary=' . $this->multipart_boundary; + $args['headers']['Referer'] = network_admin_url( 'admin-ajax.php' ); + + $this->attempting_to_connect_to = $url; + + $response = wp_remote_post( $url, $args ); + + if ( ! is_wp_error( $response ) ) { + $response['body'] = trim( $response['body'], "\xef\xbb\xbf" ); + } + + if ( is_wp_error( $response ) ) { + if( strpos( $url, 'https://' ) === 0 && $scope == 'ajax_verify_connection_to_remote_site' ) { + return $this->retry_remote_post( $url, $data, $scope, $args, $expecting_serial ); + } + else if( isset( $response->errors['http_request_failed'][0] ) && strstr( $response->errors['http_request_failed'][0], 'timed out' ) ) { + $this->error = sprintf( __( 'The connection to the remote server has timed out, no changes have been committed. (#134 - scope: %s)', 'wp-sync-db' ), $scope ); + } + else if ( isset( $response->errors['http_request_failed'][0] ) && ( strstr( $response->errors['http_request_failed'][0], 'Could not resolve host' ) || strstr( $response->errors['http_request_failed'][0], 'couldn\'t connect to host' ) ) ) { + $this->error = sprintf( __( 'We could not find: %s. Are you sure this is the correct URL?', 'wp-sync-db' ), $_POST['url'] ); + $url_bits = parse_url( $_POST['url'] ); + if( strstr( $_POST['url'], 'dev.' ) || strstr( $_POST['url'], '.dev' ) || ! strstr( $url_bits['host'], '.' ) ) { + $this->error .= '
    '; + if( $_POST['intent'] == 'pull' ) { + $this->error .= __( 'It appears that you might be trying to pull from a local environment. This will not work if this website happens to be located on a remote server, it would be impossible for this server to contact your local environment.', 'wp-sync-db' ); + } + else { + $this->error .= __( 'It appears that you might be trying to push to a local environment. This will not work if this website happens to be located on a remote server, it would be impossible for this server to contact your local environment.', 'wp-sync-db' ); + } + } + } + else { + $this->error = sprintf( __( 'The connection failed, an unexpected error occurred, please contact support. (#121 - scope: %s)', 'wp-sync-db' ), $scope ); + } + $this->log_error( $this->error, $response ); + return false; + } + elseif ( (int) $response['response']['code'] < 200 || (int) $response['response']['code'] > 399 ) { + if( strpos( $url, 'https://' ) === 0 && $scope == 'ajax_verify_connection_to_remote_site' ) { + return $this->retry_remote_post( $url, $data, $scope, $args, $expecting_serial ); + } + else if( $response['response']['code'] == '401' ) { + $this->error = __( 'The remote site is protected with Basic Authentication. Please enter the username and password above to continue. (401 Unauthorized)', 'wp-sync-db' ); + $this->log_error( $this->error, $response ); + return false; + } + else { + $this->error = sprintf( __( 'Unable to connect to the remote server, please check the connection details - %1$s %2$s (#129 - scope: %3$s)', 'wp-sync-db' ), $response['response']['code'], $response['response']['message'], $scope ); + $this->log_error( $this->error, $response ); + return false; + } + } + elseif ( $expecting_serial && is_serialized( $response['body'] ) == false ) { + if( strpos( $url, 'https://' ) === 0 && $scope == 'ajax_verify_connection_to_remote_site' ) { + return $this->retry_remote_post( $url, $data, $scope, $args, $expecting_serial ); + } + $this->error = __( 'There was a problem with the AJAX request, we were expecting a serialized response, instead we received:
    ', 'wp-sync-db' ) . htmlentities( $response['body'] ); + $this->log_error( $this->error, $response ); + return false; + } + elseif ( $response['body'] === '0' ) { + if( strpos( $url, 'https://' ) === 0 && $scope == 'ajax_verify_connection_to_remote_site' ) { + return $this->retry_remote_post( $url, $data, $scope, $args, $expecting_serial ); + } + $this->error = sprintf( __( 'WP Sync DB does not seem to be installed or active on the remote site. (#131 - scope: %s)', 'wp-sync-db' ), $scope ); + $this->log_error( $this->error, $response ); + return false; + } + elseif ( $expecting_serial && is_serialized( $response['body'] ) == true && $scope == 'ajax_verify_connection_to_remote_site' ) { + $unserialized_response = unserialize( $response['body'] ); + if ( isset( $unserialized_response['error'] ) && '1' == $unserialized_response['error'] && strpos( $url, 'https://' ) === 0 ) { + return $this->retry_remote_post( $url, $data, $scope, $args, $expecting_serial ); + } + } + + return $response['body']; + } + + function retry_remote_post( $url, $data, $scope, $args = array(), $expecting_serial = false ) { + $url = substr_replace( $url, 'http', 0, 5 ); + if( $response = $this->remote_post( $url, $data, $scope, $args, $expecting_serial ) ) { + return $response; + } + return false; + } + + function array_to_multipart( $data ) { + if ( !$data || !is_array( $data ) ) { + return $data; + } + + $result = ''; + + foreach ( $data as $key => $value ) { + $result .= '--' . $this->multipart_boundary . "\r\n" . + sprintf( 'Content-Disposition: form-data; name="%s"', $key ); + + if ( 'chunk' == $key ) { + if ( $data['chunk_gzipped'] ) { + $result .= "; filename=\"chunk.txt.gz\"\r\nContent-Type: application/x-gzip"; + } + else { + $result .= "; filename=\"chunk.txt\"\r\nContent-Type: text/plain;"; + } + } + else { + $result .= "\r\nContent-Type: text/plain; charset=" . get_option( 'blog_charset' ); + } + + $result .= "\r\n\r\n" . $value . "\r\n"; + } + + $result .= "--" . $this->multipart_boundary . "--\r\n"; + + return $result; + } + + function file_to_multipart( $file ) { + $result = ''; + + if( false == file_exists( $file ) ) return false; + + $filetype = wp_check_filetype( $file ); + $contents = file_get_contents( $file ); + + $result .= '--' . $this->multipart_boundary . "\r\n" . + sprintf( 'Content-Disposition: form-data; name="media[]"; filename="%s"', basename( $file ) ); + + $result .= sprintf( "\r\nContent-Type: %s", $filetype['type'] ); + + $result .= "\r\n\r\n" . $contents . "\r\n"; + + $result .= "--" . $this->multipart_boundary . "--\r\n"; + + return $result; + } + + function log_error( $wpsdb_error, $additional_error_var = false ){ + $error_header = "********************************************\n****** Log date: " . date( 'Y/m/d H:i:s' ) . " ******\n********************************************\n\n"; + $error = $error_header . "WPSDB Error: " . $wpsdb_error . "\n\n"; + if( ! empty( $this->attempting_to_connect_to ) ) { + $error .= "Attempted to connect to: " . $this->attempting_to_connect_to . "\n\n"; + } + if( $additional_error_var !== false ){ + $error .= print_r( $additional_error_var, true ) . "\n\n"; + } + $log = get_option( 'wpsdb_error_log' ); + if( $log ) { + $log = $log . $error; + } + else { + $log = $error; + } + update_option( 'wpsdb_error_log', $log ); + } + + function display_errors() { + if ( ! empty( $this->error ) ) { + echo $this->error; + $this->error = ''; + return true; + } + return false; + } + + function filter_post_elements( $post_array, $accepted_elements ) { + if ( isset( $post_array['form_data'] ) ) { + $post_array['form_data'] = stripslashes( $post_array['form_data'] ); + } + $accepted_elements[] = 'sig'; + return array_intersect_key( $post_array, array_flip( $accepted_elements ) ); + } + + function create_signature( $data, $key ) { + if ( isset( $data['sig'] ) ) { + unset( $data['sig'] ); + } + $flat_data = implode( '', $data ); + return base64_encode( hash_hmac( 'sha1', $flat_data, $key, true ) ); + } + + function verify_signature( $data, $key ) { + if( empty( $data['sig'] ) ) { + return false; + } + if ( isset( $data['nonce'] ) ) { + unset( $data['nonce'] ); + } + $temp = $data; + $computed_signature = $this->create_signature( $temp, $key ); + return $computed_signature === $data['sig']; + } + + function diverse_array( $vector ) { + $result = array(); + foreach( $vector as $key1 => $value1 ) + foreach( $value1 as $key2 => $value2 ) + $result[$key2][$key1] = $value2; + return $result; + } + + function set_time_limit_available() { + if ( ! function_exists( 'set_time_limit' ) || ! function_exists( 'ini_get' ) ) return false; + $current_max_execution_time = ini_get( 'max_execution_time' ); + $proposed_max_execution_time = ( $current_max_execution_time == 30 ) ? 31 : 30; + @set_time_limit( $proposed_max_execution_time ); + $current_max_execution_time = ini_get( 'max_execution_time' ); + return ( $proposed_max_execution_time == $current_max_execution_time ); + } + + function get_plugin_name( $plugin = false ) { + if ( !is_admin() ) return false; + + $plugin_basename = ( false !== $plugin ? $plugin : $this->plugin_basename ); + + $plugins = get_plugins(); + + if ( !isset( $plugins[$plugin_basename]['Name'] ) ) { + return false; + } + + return $plugins[$plugin_basename]['Name']; + } + + function get_class_props() { + return get_object_vars( $this ); + } + + // Get only the table beginning with our DB prefix or temporary prefix, also skip views + function get_tables( $scope = 'regular' ) { + global $wpdb; + $prefix = ( $scope == 'temp' ? $this->temp_prefix : $wpdb->prefix ); + $tables = $wpdb->get_results( 'SHOW FULL TABLES', ARRAY_N ); + foreach ( $tables as $table ) { + if ( ( ( $scope == 'temp' || $scope == 'prefix' ) && 0 !== strpos( $table[0], $prefix ) ) || $table[1] == 'VIEW' ) { + continue; + } + $clean_tables[] = $table[0]; + } + return apply_filters( 'wpsdb_tables', $clean_tables, $scope ); + } + + function plugins_dir() { + $path = untrailingslashit( $this->plugin_dir_path ); + return substr( $path, 0, strrpos( $path, DS ) ) . DS; + } + + function is_addon_outdated( $addon_basename ) { + $addon_slug = current( explode( '/', $addon_basename ) ); + // If pre-1.1.2 version of Media Files addon, then it is outdated + if ( ! isset( $GLOBALS['wpsdb_meta'][$addon_slug]['version'] ) ) return true; + $installed_version = $GLOBALS['wpsdb_meta'][$addon_slug]['version']; + $required_version = $this->addons[$addon_basename]['required_version']; + return version_compare( $installed_version, $required_version, '<' ); + } + + function get_plugin_file_path() { + return $this->plugin_file_path; + } + + function set_cli_migration() { + $this->doing_cli_migration = true; + } + + function end_ajax( $return = false ) { + if( defined( 'DOING_WPSDB_TESTS' ) || $this->doing_cli_migration ) { + return ( false === $return ) ? NULL : $return; + } + + echo ( false === $return ) ? '' : $return; + exit; + } + + function check_ajax_referer( $action ) { + if ( defined( 'DOING_WPSDB_TESTS' ) || $this->doing_cli_migration ) return; + $result = check_ajax_referer( $action, 'nonce', false ); + if ( false === $result ) { + $return = array( 'wpsdb_error' => 1, 'body' => sprintf( __( 'Invalid nonce for: %s', 'wp-sync-db' ), $action ) ); + $this->end_ajax( json_encode( $return ) ); + } + + $cap = ( is_multisite() ) ? 'manage_network_options' : 'export'; + $cap = apply_filters( 'wpsdb_ajax_cap', $cap ); + if ( !current_user_can( $cap ) ) { + $return = array( 'wpsdb_error' => 1, 'body' => sprintf( __( 'Access denied for: %s', 'wp-sync-db' ), $action ) ); + $this->end_ajax( json_encode( $return ) ); + } + } + +} diff --git a/class/wpsdb.php b/class/wpsdb.php new file mode 100755 index 0000000..8e3d52e --- /dev/null +++ b/class/wpsdb.php @@ -0,0 +1,2523 @@ +plugin_slug = 'wp-sync-db'; + $this->plugin_version = $GLOBALS['wpsdb_meta']['wp-sync-db']['version']; + + $this->max_insert_string_len = 50000; // 50000 is the default as defined by phphmyadmin + + $default_settings = array( + 'key' => $this->generate_key(), + 'allow_pull' => false, + 'allow_push' => false, + 'profiles' => array(), + 'verify_ssl' => false, + 'blacklist_plugins' => array(), + ); + + if( empty( $this->settings['max_request'] ) ) { + $this->settings['max_request'] = min( 1024 * 1024, $this->get_bottleneck( 'max' ) ); + update_option( 'wpsdb_settings', $this->settings ); + } + + // if no settings exist then this is a fresh install, set up some default settings + if ( empty( $this->settings ) ) { + $this->settings = $default_settings; + update_option( 'wpsdb_settings', $this->settings ); + } + // When we add a new setting, an existing customer's db won't have this + // new setting, so we need to add it. Otherwise, they'll see + // array index errors in debug mode + else { + $update_settings = false; + + foreach ( $default_settings as $key => $value ) { + if ( !isset( $this->settings[$key] ) ) { + $this->settings[$key] = $value; + $update_settings = true; + } + } + + if ( $update_settings ) { + update_option( 'wpsdb_settings', $this->settings ); + } + } + + add_filter( 'plugin_action_links_' . $this->plugin_basename, array( $this, 'plugin_action_links' ) ); + add_filter( 'network_admin_plugin_action_links_' . $this->plugin_basename, array( $this, 'plugin_action_links' ) ); + + // internal AJAX handlers + add_action( 'wp_ajax_wpsdb_verify_connection_to_remote_site', array( $this, 'ajax_verify_connection_to_remote_site' ) ); + add_action( 'wp_ajax_wpsdb_reset_api_key', array( $this, 'ajax_reset_api_key' ) ); + add_action( 'wp_ajax_wpsdb_delete_migration_profile', array( $this, 'ajax_delete_migration_profile' ) ); + add_action( 'wp_ajax_wpsdb_save_setting', array( $this, 'ajax_save_setting' ) ); + add_action( 'wp_ajax_wpsdb_save_profile', array( $this, 'ajax_save_profile' ) ); + add_action( 'wp_ajax_wpsdb_initiate_migration', array( $this, 'ajax_initiate_migration' ) ); + add_action( 'wp_ajax_wpsdb_migrate_table', array( $this, 'ajax_migrate_table' ) ); + add_action( 'wp_ajax_wpsdb_finalize_migration', array( $this, 'ajax_finalize_migration' ) ); + add_action( 'wp_ajax_wpsdb_clear_log', array( $this, 'ajax_clear_log' ) ); + add_action( 'wp_ajax_wpsdb_get_log', array( $this, 'ajax_get_log' ) ); + add_action( 'wp_ajax_wpsdb_fire_migration_complete', array( $this, 'fire_migration_complete' ) ); + add_action( 'wp_ajax_wpsdb_update_max_request_size', array( $this, 'ajax_update_max_request_size' ) ); + add_action( 'wp_ajax_wpsdb_plugin_compatibility', array( $this, 'ajax_plugin_compatibility' ) ); + add_action( 'wp_ajax_wpsdb_blacklist_plugins', array( $this, 'ajax_blacklist_plugins' ) ); + add_action( 'wp_ajax_wpsdb_cancel_migration', array( $this, 'ajax_cancel_migration' ) ); + + // external AJAX handlers + add_action( 'wp_ajax_nopriv_wpsdb_verify_connection_to_remote_site', array( $this, 'respond_to_verify_connection_to_remote_site' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_remote_initiate_migration', array( $this, 'respond_to_remote_initiate_migration' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_process_chunk', array( $this, 'ajax_process_chunk' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_process_pull_request', array( $this, 'respond_to_process_pull_request' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_fire_migration_complete', array( $this, 'fire_migration_complete' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_backup_remote_table', array( $this, 'respond_to_backup_remote_table' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_remote_finalize_migration', array( $this, 'respond_to_remote_finalize_migration' ) ); + add_action( 'wp_ajax_nopriv_wpsdb_process_push_migration_cancellation', array( $this, 'respond_to_process_push_migration_cancellation' ) ); + + // Clear update transients when the user clicks the "Check Again" button from the update screen + add_action( 'current_screen', array( $this, 'check_again_clear_transients' ) ); + + $absolute_path = rtrim( ABSPATH, '\\/' ); + $site_url = rtrim( site_url( '', 'http' ), '\\/' ); + $home_url = rtrim( home_url( '', 'http' ), '\\/' ); + if ( $site_url != $home_url ) { + $difference = str_replace( $home_url, '', $site_url ); + if( strpos( $absolute_path, $difference ) !== false ) { + $absolute_path = rtrim( substr( $absolute_path, 0, -strlen( $difference ) ), '\\/' ); + } + } + $this->absolute_root_file_path = $absolute_path; + + $this->accepted_fields = array( + 'action', + 'save_computer', + 'gzip_file', + 'connection_info', + 'replace_old', + 'replace_new', + 'table_migrate_option', + 'select_tables', + 'replace_guids', + 'exclude_spam', + 'save_migration_profile', + 'save_migration_profile_option', + 'create_new_profile', + 'create_backup', + 'remove_backup', + 'keep_active_plugins', + 'select_post_types', + 'backup_option', + 'select_backup', + 'exclude_transients', + 'exclude_post_types' + ); + + $this->default_profile = array( + 'action' => 'savefile', + 'save_computer' => '1', + 'gzip_file' => '1', + 'table_migrate_option' => 'migrate_only_with_prefix', + 'replace_guids' => '1', + 'default_profile' => true, + 'name' => '', + 'select_tables' => array(), + 'select_post_types' => array(), + 'backup_option' => 'backup_only_with_prefix', + 'exclude_transients' => '1', + ); + + $this->checkbox_options = array( + 'save_computer' => '0', + 'gzip_file' => '0', + 'replace_guids' => '0', + 'exclude_spam' => '0', + 'keep_active_plugins' => '0', + 'create_backup' => '0', + 'exclude_post_types' =>'0' + ); + + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) ); + } + else { + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + } + + add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); + + // this is how many DB rows are processed at a time, allow devs to change this value + $this->rows_per_segment = apply_filters( 'wpsdb_rows_per_segment', $this->rows_per_segment ); + + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) ); + $this->plugin_base = 'settings.php?page=wp-sync-db'; + } + else { + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); + $this->plugin_base = 'tools.php?page=wp-sync-db'; + } + } + + function ajax_blacklist_plugins() { + $this->settings['blacklist_plugins'] = $_POST['blacklist_plugins']; + update_option( 'wpsdb_settings', $this->settings ); + exit; + } + + function ajax_plugin_compatibility() { + $mu_dir = ( defined( 'WPMU_PLUGIN_DIR' ) && defined( 'WPMU_PLUGIN_URL' ) ) ? WPMU_PLUGIN_DIR : trailingslashit( WP_CONTENT_DIR ) . 'mu-plugins'; + $source = trailingslashit( $this->plugin_dir_path ) . 'compatibility/wp-sync-db-compatibility.php'; + $dest = trailingslashit( $mu_dir ) . 'wp-sync-db-compatibility.php'; + if ( '1' === trim( $_POST['install'] ) ) { // install MU plugin + if ( !wp_mkdir_p( $mu_dir ) ) { + _e( sprintf( 'The following directory could not be created: %s', $mu_dir ), 'wp-sync-db' ); + exit; + } + if ( !copy( $source, $dest ) ) { + _e( sprintf( 'Could not copy the compatibility plugin from %1$s to %2$s', $source, $destination ), 'wp-sync-db' ); + exit; + } + } else { // uninstall MU plugin + if ( file_exists( $dest ) && !unlink( $dest ) ) { + _e( sprintf( 'Could not remove the compatibility plugin from %s', $dest ), 'wp-sync-db' ); + exit; + } + } + exit; + } + + function check_again_clear_transients( $current_screen ) { + if( ! isset( $current_screen->id ) || strpos( $current_screen->id, 'update-core' ) === false || ! isset( $_GET['force-check'] ) ) return; + delete_site_transient( 'wpsdb_upgrade_data' ); + delete_site_transient( 'update_plugins' ); + } + + function get_alter_table_name() { + if ( ! is_null( $this->alter_table_name ) ) { + return $this->alter_table_name; + } + global $wpdb; + $this->alter_table_name = apply_filters( 'wpsdb_alter_table_name', $wpdb->prefix . 'wpsdb_alter_statements' ); + return $this->alter_table_name; + } + + function get_create_alter_table_query() { + if ( ! is_null( $this->create_alter_table_query ) ) { + return $this->create_alter_table_query; + } + $alter_table_name = $this->get_alter_table_name(); + $this->create_alter_table_query = sprintf( "DROP TABLE IF EXISTS `%s`;\n", $alter_table_name ); + $this->create_alter_table_query .= sprintf( "CREATE TABLE `%s` ( `query` longtext NOT NULL );\n", $alter_table_name ); + $this->create_alter_table_query = apply_filters( 'wpsdb_create_alter_table_query', $this->create_alter_table_query ); + return $this->create_alter_table_query; + } + + function get_short_uploads_dir() { + $short_path = str_replace( $this->absolute_root_file_path, '', $this->get_upload_info( 'path' ) ); + return trailingslashit( substr( str_replace( '\\', '/', $short_path ), 1 ) ); + } + + function get_upload_info( $type = 'path' ) { + // Let developers define their own path to for export files + // Note: We require a very specific data set here, it should be similiar to the following + // array( + // 'path' => '/path/to/custom/uploads/directory', <- note missing end trailing slash + // 'url' => 'http://yourwebsite.com/custom/uploads/directory' <- note missing end trailing slash + // ); + $upload_info = apply_filters( 'wpsdb_upload_info', array() ); + if ( !empty( $upload_info ) ) { + return $upload_info[$type]; + } + + $upload_dir = wp_upload_dir(); + + $upload_info['path'] = $upload_dir['basedir']; + $upload_info['url'] = $upload_dir['baseurl']; + + $upload_dir_name = apply_filters( 'wpsdb_upload_dir_name', 'wp-sync-db' ); + + if( ! file_exists( $upload_dir['basedir'] . DS . $upload_dir_name ) ) { + $url = wp_nonce_url( $this->plugin_base, 'wp-sync-db-nonce' ); + + if( false === @mkdir( $upload_dir['basedir'] . DS . $upload_dir_name, 0755 ) ) { + return $upload_info[$type]; + } + + $filename = $upload_dir['basedir'] . DS . $upload_dir_name . DS . 'index.php'; + if( false === @file_put_contents( $filename, "" ) ) { + return $upload_info[$type]; + } + } + + $upload_info['path'] .= DS . $upload_dir_name; + $upload_info['url'] .= '/' . $upload_dir_name; + + return $upload_info[$type]; + } + + function ajax_update_max_request_size() { + $this->check_ajax_referer( 'update-max-request-size' ); + $this->settings['max_request'] = (int) $_POST['max_request_size'] * 1024; + update_option( 'wpsdb_settings', $this->settings ); + $result = $this->end_ajax(); + return $result; + } + + function is_json( $string, $strict = false ) { + $json = @json_decode( $string, true ); + if( $strict == true && ! is_array( $json ) ) return false; + return ! ( $json == NULL || $json == false ); + } + + function get_sql_dump_info( $migration_type, $info_type ) { + if( empty( $this->session_salt ) ) { + $this->session_salt = strtolower( wp_generate_password( 5, false, false ) ); + } + $datetime = date('YmdHis'); + $ds = ( $info_type == 'path' ? DS : '/' ); + return sprintf( '%s%s%s-%s-%s-%s.sql', $this->get_upload_info( $info_type ), $ds, sanitize_title_with_dashes( DB_NAME ), $migration_type, $datetime, $this->session_salt ); + } + + function parse_migration_form_data( $data ) { + parse_str( $data, $form_data ); + $this->accepted_fields = apply_filters( 'wpsdb_accepted_profile_fields', $this->accepted_fields ); + $form_data = array_intersect_key( $form_data, array_flip( $this->accepted_fields ) ); + unset( $form_data['replace_old'][0] ); + unset( $form_data['replace_new'][0] ); + return $form_data; + } + + function plugin_action_links( $links ) { + $link = sprintf( '%s', network_admin_url( $this->plugin_base ), __( 'Settings', 'wp-sync-db' ) ); + array_unshift( $links, $link ); + return $links; + } + + function ajax_clear_log() { + $this->check_ajax_referer( 'clear-log' ); + delete_option( 'wpsdb_error_log' ); + $result = $this->end_ajax(); + return $result; + } + + function ajax_get_log() { + $this->check_ajax_referer( 'get-log' ); + ob_start(); + $this->output_diagnostic_info(); + $this->output_log_file(); + $return = ob_get_clean(); + $result = $this->end_ajax( $return ); + return $result; + } + + function output_log_file() { + $log = get_option( 'wpsdb_error_log' ); + if( $log ) { + echo $log; + } + } + + function output_diagnostic_info() { + global $table_prefix; + global $wpdb; + + echo 'site_url(): '; + echo site_url(); + echo "\r\n"; + + echo 'home_url(): '; + echo home_url(); + echo "\r\n"; + + echo 'Table Prefix: '; + echo $table_prefix; + echo "\r\n"; + + echo 'WordPress: '; + if ( is_multisite() ) echo 'WPMU'; else echo 'WP'; echo bloginfo('version'); + echo "\r\n"; + + echo 'Web Server: '; + echo $_SERVER['SERVER_SOFTWARE']; + echo "\r\n"; + + echo 'PHP: '; + if ( function_exists( 'phpversion' ) ) echo esc_html( phpversion() ); + echo "\r\n"; + + echo 'MySQL: '; + echo esc_html( empty( $wpdb->use_mysqli ) ? mysql_get_server_info() : mysqli_get_server_info( $wpdb->dbh ) ); + echo "\r\n"; + + _e( 'ext/mysqli', 'wp-app-store' ); echo ': '; + echo empty( $wpdb->use_mysqli ) ? 'no' : 'yes'; + echo "\r\n"; + + _e( 'WP Memory Limit', 'wp-app-store' ); echo ': '; + echo WP_MEMORY_LIMIT; + echo "\r\n"; + + echo 'WPSDB Bottleneck: '; + echo size_format( $this->get_bottleneck() ); + echo "\r\n"; + + if ( function_exists( 'ini_get' ) && $suhosin_limit = ini_get( 'suhosin.post.max_value_length' ) ) { + echo 'Suhosin Post Max Value Length: '; + echo is_numeric( $suhosin_limit ) ? size_format( $suhosin_limit ) : $suhosin_limit; + echo "\r\n"; + } + + if ( function_exists( 'ini_get' ) && $suhosin_limit = ini_get( 'suhosin.request.max_value_length' ) ) { + echo 'Suhosin Request Max Value Length: '; + echo is_numeric( $suhosin_limit ) ? size_format( $suhosin_limit ) : $suhosin_limit; + echo "\r\n"; + } + + echo 'Debug Mode: '; + if ( defined('WP_DEBUG') && WP_DEBUG ) { echo 'Yes'; } else { echo 'No'; } + echo "\r\n"; + + echo 'WP Max Upload Size: '; + echo size_format( wp_max_upload_size() ); + echo "\r\n"; + + echo 'PHP Post Max Size: '; + echo size_format( $this->get_post_max_size() ); + echo "\r\n"; + + echo 'PHP Time Limit: '; + if ( function_exists( 'ini_get' ) ) echo ini_get('max_execution_time'); + echo "\r\n"; + + echo 'PHP Error Log: '; + if ( function_exists( 'ini_get' ) ) echo ini_get('error_log'); + echo "\r\n"; + + echo 'fsockopen: '; + if ( function_exists( 'fsockopen' ) ) { + echo 'Enabled'; + } else { + echo 'Disabled'; + } + echo "\r\n"; + + echo 'OpenSSL: '; + if ( $this->open_ssl_enabled() ) { + echo OPENSSL_VERSION_TEXT; + + } else { + echo 'Disabled'; + } + echo "\r\n"; + + echo 'cURL: '; + if ( function_exists( 'curl_init' ) ) { + echo 'Enabled'; + } else { + echo 'Disabled'; + } + echo "\r\n"; + echo "\r\n"; + + echo "Active Plugins:\r\n"; + + $active_plugins = (array) get_option( 'active_plugins', array() ); + + if ( is_multisite() ) { + $network_active_plugins = wp_get_active_network_plugins(); + $active_plugins = array_map( array( $this, 'remove_wp_plugin_dir' ), $network_active_plugins ); + } + + foreach ( $active_plugins as $plugin ) { + $plugin_data = @get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); + if ( empty( $plugin_data['Name'] ) ) continue; + printf( "%s (v%s) by %s\r\n", $plugin_data['Name'], $plugin_data['Version'], $plugin_data['AuthorName'] ); + } + + echo "\r\n"; + } + + function remove_wp_plugin_dir( $name ) { + $plugin = str_replace( WP_PLUGIN_DIR, '', $name ); + return substr( $plugin, 1 ); + } + + function fire_migration_complete() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'url' ) ); + if ( ! $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $error_msg = $this->invalid_content_verification_error . ' (#138)'; + $this->log_error( $error_msg, $filtered_post ); + $result = $this->end_ajax( $error_msg ); + return $result; + } + + do_action( 'wpsdb_migration_complete', 'pull', $_POST['url'] ); + $result = $this->end_ajax(); + return $result; + } + + function get_alter_queries() { + global $wpdb; + $alter_table_name = $this->get_alter_table_name(); + $sql = ''; + $alter_queries = $wpdb->get_results( "SELECT * FROM `{$alter_table_name}`", ARRAY_A ); + if( ! empty( $alter_queries ) ) { + foreach( $alter_queries as $alter_query ) { + $sql .= $alter_query['query']; + } + } + return $sql; + } + + // After table migration, delete old tables and rename new tables removing the temporarily prefix + function ajax_finalize_migration() { + $this->check_ajax_referer( 'finalize-migration' ); + global $wpdb; + $return = ''; + if ( $_POST['intent'] == 'pull' ) { + $return = $this->finalize_migration(); + } + else { + do_action( 'wpsdb_migration_complete', 'push', $_POST['url'] ); + $data = $_POST; + if ( isset( $data['nonce'] ) ) { + unset( $data['nonce'] ); + } + $data['action'] = 'wpsdb_remote_finalize_migration'; + $data['intent'] = 'pull'; + $data['prefix'] = $wpdb->prefix; + $data['type'] = 'push'; + $data['location'] = home_url(); + $data['temp_prefix'] = $this->temp_prefix; + $data['sig'] = $this->create_signature( $data, $data['key'] ); + $ajax_url = trailingslashit( $_POST['url'] ) . 'wp-admin/admin-ajax.php'; + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + ob_start(); + echo $response; + $this->display_errors(); + $return = ob_get_clean(); + } + $result = $this->end_ajax( $return ); + return $result; + } + + function respond_to_remote_finalize_migration() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent', 'url', 'key', 'form_data', 'prefix', 'type', 'location', 'tables', 'temp_prefix' ) ); + if ( ! $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $error_msg = $this->invalid_content_verification_error . ' (#123)'; + $this->log_error( $error_msg, $filtered_post ); + $result = $this->end_ajax( $error_msg ); + return $result; + } + $return = $this->finalize_migration(); + $result = $this->end_ajax( $return ); + return $result; + } + + function finalize_migration() { + global $wpdb; + + $tables = explode( ',', $_POST['tables'] ); + $temp_tables = array(); + foreach( $tables as $table ) { + $temp_prefix = stripslashes( $_POST['temp_prefix'] ); + $temp_tables[] = $temp_prefix . $table; + } + + $sql = "SET FOREIGN_KEY_CHECKS=0;\n"; + + $preserved_options = array( 'wpsdb_settings', 'wpsdb_error_log' ); + + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + if( isset( $this->form_data['keep_active_plugins'] ) ) { + $preserved_options[] = 'active_plugins'; + } + + $preserved_options = apply_filters( 'wpsdb_preserved_options', $preserved_options ); + + foreach ( $temp_tables as $table ) { + $sql .= 'DROP TABLE IF EXISTS ' . $this->backquote( substr( $table, strlen( $temp_prefix ) ) ) . ';'; + $sql .= "\n"; + $sql .= 'RENAME TABLE ' . $this->backquote( $table ) . ' TO ' . $this->backquote( substr( $table, strlen( $temp_prefix ) ) ) . ';'; + $sql .= "\n"; + } + + $preserved_options_data = $wpdb->get_results( sprintf( "SELECT * FROM %soptions WHERE `option_name` IN ('%s')", $wpdb->prefix, implode( "','", $preserved_options ) ), ARRAY_A ); + + foreach( $preserved_options_data as $option ) { + $sql .= $wpdb->prepare( "DELETE FROM `{$_POST['prefix']}options` WHERE `option_name` = %s;\n", $option['option_name'] ); + $sql .= $wpdb->prepare( "INSERT INTO `{$_POST['prefix']}options` ( `option_id`, `option_name`, `option_value`, `autoload` ) VALUES ( NULL , %s, %s, %s );\n", $option['option_name'], $option['option_value'], $option['autoload'] ); + } + + $alter_table_name = $this->get_alter_table_name(); + $sql .= $this->get_alter_queries(); + $sql .= "DROP TABLE IF EXISTS " . $this->backquote( $alter_table_name ) . ";\n"; + + $process_chunk_result = $this->process_chunk( $sql ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + + $type = ( isset( $_POST['type'] ) ? 'push' : 'pull' ); + $location = ( isset( $_POST['location'] ) ? $_POST['location'] : $_POST['url'] ); + + if( ! isset( $_POST['location'] ) ) { + $data = array(); + $data['action'] = 'wpsdb_fire_migration_complete'; + $data['url'] = home_url(); + $data['sig'] = $this->create_signature( $data, $_POST['key'] ); + $ajax_url = trailingslashit( $_POST['url'] ) . 'wp-admin/admin-ajax.php'; + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + ob_start(); + echo $response; + $this->display_errors(); + $maybe_errors = trim( ob_get_clean() ); + if( false === empty( $maybe_errors ) ) { + $result = $this->end_ajax( $maybe_errors ); + return $result; + } + } + + // flush rewrite rules to prevent 404s and other oddities + flush_rewrite_rules( true ); // true = hard refresh, recreates the .htaccess file + + do_action( 'wpsdb_migration_complete', $type, $location ); + } + + function ajax_process_chunk() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'table', 'chunk_gzipped' ) ); + $gzip = ( isset( $_POST['chunk_gzipped'] ) && $_POST['chunk_gzipped'] ); + + $tmp_file_name = 'chunk.txt'; + if( $gzip ) { + $tmp_file_name .= '.gz'; + } + + $tmp_file_path = wp_tempnam( $tmp_file_name ); + if ( !isset( $_FILES['chunk']['tmp_name'] ) || !move_uploaded_file( $_FILES['chunk']['tmp_name'], $tmp_file_path ) ) { + $result = $this->end_ajax( __( 'Could not upload the SQL to the server. (#135)', 'wp-sync-db' ) ); + return $result; + } + + if ( false === ( $chunk = file_get_contents( $tmp_file_path ) ) ) { + $result = $this->end_ajax( __( 'Could not read the SQL file we uploaded to the server. (#136)', 'wp-sync-db' ) ); + return $result; + } + + @unlink( $tmp_file_path ); + + $filtered_post['chunk'] = $chunk; + + if ( !$this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $error_msg = $this->invalid_content_verification_error . ' (#130)'; + $this->log_error( $error_msg, $filtered_post ); + $result = $this->end_ajax( $error_msg ); + return $result; + } + + if ( $this->settings['allow_push'] != true ) { + $result = $this->end_ajax( __( 'The connection succeeded but the remote site is configured to reject push connections. You can change this in the "settings" tab on the remote site. (#133)', 'wp-sync-db' ) ); + return $result; + } + + if( $gzip ) { + $filtered_post['chunk'] = gzuncompress( $filtered_post['chunk'] ); + } + + $process_chunk_result = $this->process_chunk( $filtered_post['chunk'] ); + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + + function process_chunk( $chunk ) { + // prepare db + global $wpdb; + $this->set_time_limit(); + + $queries = array_filter( explode( ";\n", $chunk ) ); + array_unshift( $queries, "SET sql_mode='NO_AUTO_VALUE_ON_ZERO';" ); + + ob_start(); + $wpdb->show_errors(); + if( empty( $wpdb->charset ) ) { + $charset = ( defined( 'DB_CHARSET' ) ? DB_CHARSET : 'utf8' ); + $wpdb->charset = $charset; + $wpdb->set_charset( $wpdb->dbh, $wpdb->charset ); + } + foreach( $queries as $query ) { + if( false === $wpdb->query( $query ) ) { + $return = ob_get_clean(); + $result = $this->end_ajax( $return ); + return $result; + } + } + return true; + } + + function ajax_migrate_table() { + $this->check_ajax_referer( 'migrate-table' ); + global $wpdb; + + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + + $result = ''; + // checks if we're performing a backup, if so, continue with the backup and exit immediately after + if ( $_POST['stage'] == 'backup' && $_POST['intent'] != 'savefile' ) { + // if performing a push we need to backup the REMOTE machine's DB + if ( $_POST['intent'] == 'push' ) { + $data = $_POST; + if ( isset( $data['nonce'] ) ) { + unset( $data['nonce'] ); + } + $data['action'] = 'wpsdb_backup_remote_table'; + $data['intent'] = 'pull'; + $ajax_url = trailingslashit( $_POST['url'] ) . 'wp-admin/admin-ajax.php'; + $data['primary_keys'] = stripslashes( $data['primary_keys'] ); + $data['sig'] = $this->create_signature( $data, $data['key'] ); + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + ob_start(); + $this->display_errors(); + $return = ob_get_clean(); + $return .= $response; + } + else { + $return = $this->handle_table_backup(); + } + $result = $this->end_ajax( $return ); + return $result; + } + + // Pull and push need to be handled differently for obvious reasons, trigger different code depending on the migration intent (push or pull) + if ( $_POST['intent'] == 'push' || $_POST['intent'] == 'savefile' ) { + $this->maximum_chunk_size = $this->get_bottleneck(); + if ( isset( $_POST['bottleneck'] ) ) { + $this->maximum_chunk_size = (int) $_POST['bottleneck']; + } + if ( $_POST['intent'] == 'push' ) { + $this->remote_key = $_POST['key']; + $this->remote_url = $_POST['url']; + } + $sql_dump_file_name = $this->get_upload_info( 'path' ) . DS; + $sql_dump_file_name .= $this->format_dump_name( $_POST['dump_filename'] ); + + if ( $_POST['intent'] == 'savefile' ) { + $this->fp = $this->open( $sql_dump_file_name ); + } + $result = $this->export_table( $_POST['table'] ); + if ( $_POST['intent'] == 'savefile' ) { + $this->close( $this->fp ); + } + ob_start(); + $this->display_errors(); + $maybe_errors = trim( ob_get_clean() ); + if( false === empty( $maybe_errors ) ) { + $result = $this->end_ajax( $maybe_errors ); + return $result; + } + return $result; + } + else { + $data = $_POST; + if ( isset( $data['nonce'] ) ) { + unset( $data['nonce'] ); + } + $data['action'] = 'wpsdb_process_pull_request'; + $data['pull_limit'] = $this->get_sensible_pull_limit(); + if( is_multisite() ) { + $data['path_current_site'] = $this->get_path_current_site(); + $data['domain_current_site'] = $this->get_domain_current_site(); + } + $data['prefix'] = $wpdb->prefix; + if ( isset( $data['sig'] ) ) { + unset( $data['sig'] ); + } + $ajax_url = trailingslashit( $data['url'] ) . 'wp-admin/admin-ajax.php'; + $data['primary_keys'] = stripslashes( $data['primary_keys'] ); + $data['sig'] = $this->create_signature( $data, $data['key'] ); + + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + ob_start(); + $this->display_errors(); + $maybe_errors = trim( ob_get_clean() ); + if( false === empty( $maybe_errors ) ) { + $result = $this->end_ajax( $maybe_errors ); + return $result; + } + + if( strpos( $response, ';' ) === false ) { + $result = $this->end_ajax( $response ); + return $result; + } + + // returned data is just a big string like this query;query;query;33 + // need to split this up into a chunk and row_tracker + $row_information = trim( substr( strrchr( $response, "\n" ), 1 ) ); + $row_information = explode( ',', $row_information ); + $chunk = substr( $response, 0, strrpos( $response, ";\n" ) + 1 ); + + if ( ! empty( $chunk ) ) { + $process_chunk_result = $this->process_chunk( $chunk ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + } + + $result = $this->end_ajax( json_encode( + array( + 'current_row' => $row_information[0], + 'primary_keys' => $row_information[1] + ) + ) ); + } + return $result; + } + + function respond_to_backup_remote_table() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent', 'url', 'key', 'table', 'form_data', 'stage', 'bottleneck', 'prefix', 'current_row', 'dump_filename', 'last_table', 'gzip', 'primary_keys', 'path_current_site', 'domain_current_site' ) ); + $filtered_post['primary_keys'] = stripslashes( $filtered_post['primary_keys'] ); + if ( ! $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $error_msg = $this->invalid_content_verification_error . ' (#137)'; + $this->log_error( $error_msg, $filtered_post ); + $result = $this->end_ajax( $error_msg ); + return $result; + } + + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + $result = $this->handle_table_backup(); + return $result; + } + + function handle_table_backup() { + if ( isset( $this->form_data['gzip_file'] ) ) { + unset( $this->form_data['gzip_file'] ); + } + $this->maximum_chunk_size = $this->get_bottleneck(); + $sql_dump_file_name = $this->get_upload_info( 'path' ) . DS; + $sql_dump_file_name .= $this->format_dump_name( $_POST['dump_filename'] ); + $file_created = file_exists( $sql_dump_file_name ); + $this->fp = $this->open( $sql_dump_file_name ); + if ( $file_created == false ) { + $this->db_backup_header(); + } + $result = $this->export_table( $_POST['table'] ); + if( isset( $this->fp ) ) { + $this->close( $this->fp ); + } + ob_start(); + $this->display_errors(); + $maybe_errors = trim( ob_get_clean() ); + if( false === empty( $maybe_errors ) ) { + $result = $this->end_ajax( $maybe_errors ); + return $result; + } + + return $result; + } + + function respond_to_process_pull_request() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent', 'url', 'key', 'table', 'form_data', 'stage', 'bottleneck', 'prefix', 'current_row', 'dump_filename', 'pull_limit', 'last_table', 'gzip', 'primary_keys', 'path_current_site', 'domain_current_site' ) ); + + // verification will fail unless we strip slashes on primary_keys and form_data + $filtered_post['primary_keys'] = stripslashes( $filtered_post['primary_keys'] ); + $filtered_post['form_data'] = stripslashes( $filtered_post['form_data'] ); + if( isset( $filtered_post['path_current_site'] ) ) { + $filtered_post['path_current_site'] = stripslashes( $filtered_post['path_current_site'] ); + } + + if ( ! $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $error_msg = $this->invalid_content_verification_error . ' (#124)'; + $this->log_error( $error_msg, $filtered_post ); + $result = $this->end_ajax( $error_msg ); + return $result; + } + + if ( $this->settings['allow_pull'] != true ) { + $result = $this->end_ajax( __( 'The connection succeeded but the remote site is configured to reject pull connections. You can change this in the "settings" tab on the remote site. (#132)', 'wp-sync-db' ) ); + return $result; + } + + $this->maximum_chunk_size = $_POST['pull_limit']; + $this->export_table( $_POST['table'] ); + ob_start(); + $this->display_errors(); + $return = ob_get_clean(); + $result = $this->end_ajax( $return ); + return $result; + } + + // Occurs right before the first table is migrated / backed up during the migration process + // Does a quick check to make sure the verification string is valid and also opens / creates files for writing to (if required) + function ajax_initiate_migration() { + $this->check_ajax_referer( 'initiate-migration' ); + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + if ( $_POST['intent'] == 'savefile' ) { + + $return = array( + 'code' => 200, + 'message' => 'OK', + 'body' => json_encode( array( 'error' => 0 ) ), + ); + + $return['dump_filename'] = basename( $this->get_sql_dump_info( 'migrate', 'path' ) ); + $return['dump_url'] = $this->get_sql_dump_info( 'migrate', 'url' ); + $dump_filename_no_extension = substr( $return['dump_filename'], 0, -4 ); + + $create_alter_table_query = $this->get_create_alter_table_query(); + // sets up our table to store 'ALTER' queries + $process_chunk_result = $this->process_chunk( $create_alter_table_query ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + + if ( $this->gzip() && isset( $this->form_data['gzip_file'] ) ) { + $return['dump_filename'] .= '.gz'; + $return['dump_url'] .= '.gz'; + } + $this->fp = $this->open( $this->get_upload_info( 'path' ) . DS . $return['dump_filename'] ); + $this->db_backup_header(); + $this->close( $this->fp ); + + $return['dump_filename'] = $dump_filename_no_extension; + } + else { // does one last check that our verification string is valid + + $data = array( + 'action' => 'wpsdb_remote_initiate_migration', + 'intent' => $_POST['intent'], + 'form_data' => $_POST['form_data'], + ); + + $data['sig'] = $this->create_signature( $data, $_POST['key'] ); + $ajax_url = trailingslashit( $_POST['url'] ) . 'wp-admin/admin-ajax.php'; + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + + if ( false === $response ) { + $return = array( 'wpsdb_error' => 1, 'body' => $this->error ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + $return = @unserialize( trim( $response ) ); + + if ( false === $return ) { + $error_msg = __( 'Failed attempting to unserialize the response from the remote server. Please contact support.', 'wp-sync-db' ); + $return = array( 'wpsdb_error' => 1, 'body' => $error_msg ); + $this->log_error( $error_msg, $response ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + if ( isset( $return['error'] ) && $return['error'] == 1 ) { + $return = array( 'wpsdb_error' => 1, 'body' => $return['message'] ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + if( $_POST['intent'] == 'pull' ) { + // sets up our table to store 'ALTER' queries + $create_alter_table_query = $this->get_create_alter_table_query(); + $process_chunk_result = $this->process_chunk( $create_alter_table_query ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + } + + if( ! empty( $this->form_data['create_backup'] ) && $_POST['intent'] == 'pull' ) { + $return['dump_filename'] = basename( $this->get_sql_dump_info( 'backup', 'path' ) ); + $return['dump_filename'] = substr( $return['dump_filename'], 0, -4 ); + $return['dump_url'] = $this->get_sql_dump_info( 'backup', 'url' ); + } + + } + + $return['dump_filename'] = ( empty( $return['dump_filename'] ) ) ? '' : $return['dump_filename']; + $return['dump_url'] = ( empty( $return['dump_url'] ) ) ? '' : $return['dump_url']; + + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + // End point for the above remote_post call, ensures that the verification string is valid before continuing with the migration + function respond_to_remote_initiate_migration() { + $return = array(); + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent', 'form_data' ) ); + if ( $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + if ( isset( $this->settings['allow_' . $_POST['intent']] ) && ( true === $this->settings['allow_' . $_POST['intent']] || 1 === $this->settings['allow_' . $_POST['intent']] ) ) { + $return['error'] = 0; + } + else { + $return['error'] = 1; + if( $_POST['intent'] == 'pull' ) { + $intent = __( 'pull', 'wp-sync-db' ); + } + else { + $intent = __( 'push', 'wp-sync-db' ); + } + $return['message'] = sprintf( __( 'The connection succeeded but the remote site is configured to reject %s connections. You can change this in the "settings" tab on the remote site. (#110)', 'wp-sync-db'), $intent ); + } + } + else { + $return['error'] = 1; + $error_msg = $this->invalid_content_verification_error . ' (#111)'; + $this->log_error( $error_msg, $filtered_post ); + $return['message'] = $error_msg; + } + + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + if( ! empty( $this->form_data['create_backup'] ) && $_POST['intent'] == 'push' ) { + $return['dump_filename'] = basename( $this->get_sql_dump_info( 'backup', 'path' ) ); + $return['dump_filename'] = substr( $return['dump_filename'], 0, -4 ); + $return['dump_url'] = $this->get_sql_dump_info( 'backup', 'url' ); + } + + if( $_POST['intent'] == 'push' ) { + // sets up our table to store 'ALTER' queries + $create_alter_table_query = $this->get_create_alter_table_query(); + $process_chunk_result = $this->process_chunk( $create_alter_table_query ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + } + + $result = $this->end_ajax( serialize( $return ) ); + return $result; + } + + function ajax_save_profile() { + $this->check_ajax_referer( 'save-profile' ); + $profile = $this->parse_migration_form_data( $_POST['profile'] ); + $profile = wp_parse_args( $profile, $this->checkbox_options ); + if ( isset( $profile['save_migration_profile_option'] ) && $profile['save_migration_profile_option'] == 'new' ) { + $profile['name'] = $profile['create_new_profile']; + $this->settings['profiles'][] = $profile; + } + else { + $key = $profile['save_migration_profile_option']; + $name = $this->settings['profiles'][$key]['name']; + $this->settings['profiles'][$key] = $profile; + $this->settings['profiles'][$key]['name'] = $name; + } + update_option( 'wpsdb_settings', $this->settings ); + end( $this->settings['profiles'] ); + $key = key( $this->settings['profiles'] ); + $result = $this->end_ajax( $key ); + return $result; + } + + function ajax_save_setting() { + $this->check_ajax_referer( 'save-setting' ); + $this->settings[$_POST['setting']] = ( $_POST['checked'] == 'false' ? false : true ); + update_option( 'wpsdb_settings', $this->settings ); + $result = $this->end_ajax(); + return $result; + } + + function ajax_delete_migration_profile() { + $this->check_ajax_referer( 'delete-migration-profile' ); + $key = absint( $_POST['profile_id'] ); + --$key; + $return = ''; + if ( isset( $this->settings['profiles'][$key] ) ) { + unset( $this->settings['profiles'][$key] ); + update_option( 'wpsdb_settings', $this->settings ); + } + else { + $return = '-1'; + } + $result = $this->end_ajax( $return ); + return $result; + } + + function ajax_reset_api_key() { + $this->check_ajax_referer( 'reset-api-key' ); + $this->settings['key'] = $this->generate_key(); + update_option( 'wpsdb_settings', $this->settings ); + $result = $this->end_ajax( sprintf( "%s\n%s", site_url( '', 'https' ), $this->settings['key'] ) ); + return $result; + } + + // AJAX endpoint for when the user pastes into the connection info box (or when they click "connect") + // Responsible for contacting the remote website and retrieving info and testing the verification string + function ajax_verify_connection_to_remote_site() { + $this->check_ajax_referer( 'verify-connection-to-remote-site' ); + $data = array( + 'action' => 'wpsdb_verify_connection_to_remote_site', + 'intent' => $_POST['intent'] + ); + + $data['sig'] = $this->create_signature( $data, $_POST['key'] ); + $ajax_url = trailingslashit( $_POST['url'] ) . 'wp-admin/admin-ajax.php'; + $timeout = apply_filters( 'wpsdb_prepare_remote_connection_timeout', 10 ); + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__, compact( 'timeout' ), true ); + $url_bits = parse_url( $this->attempting_to_connect_to ); + $return = $response; + + $alt_action = ''; + + if ( false === $response ) { + $return = array( 'wpsdb_error' => 1, 'body' => $this->error ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + $response = unserialize( trim( $response ) ); + + if ( false === $response ) { + $error_msg = __( 'Failed attempting to unserialize the response from the remote server. Please contact support.', 'wp-sync-db' ); + $return = array( 'wpsdb_error' => 1, 'body' => $error_msg ); + $this->log_error( $error_msg ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + if ( isset( $response['error'] ) && $response['error'] == 1 ) { + $return = array( 'wpsdb_error' => 1, 'body' => $response['message'] ); + $this->log_error( $response['message'], $response ); + $result = $this->end_ajax( json_encode( $return ) ); + return $result; + } + + if ( isset( $_POST['convert_post_type_selection'] ) && '1' == $_POST['convert_post_type_selection'] ) { + $profile = (int) $_POST['profile']; + unset( $this->settings['profiles'][$profile]['post_type_migrate_option'] ); + $this->settings['profiles'][$profile]['exclude_post_types'] = '1'; + $this->settings['profiles'][$profile]['select_post_types'] = array_values( array_diff( $response['post_types'], $this->settings['profiles'][$profile]['select_post_types'] ) ); + $response['select_post_types'] = $this->settings['profiles'][$profile]['select_post_types']; + update_option( 'wpsdb_settings', $this->settings ); + } + + $response['scheme'] = $url_bits['scheme']; + $return = json_encode( $response ); + + $result = $this->end_ajax( $return ); + return $result; + } + + // End point for the above remote_post call, returns table information, absolute file path, table prefix, etc + function respond_to_verify_connection_to_remote_site() { + global $wpdb; + + $return = array(); + + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent' ) ); + if ( !$this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + $return['error'] = 1; + $return['message'] = $this->invalid_content_verification_error . ' (#120) ' . __( 'Try again?', 'wp-sync-db' ) . ''; + $this->log_error( $this->invalid_content_verification_error . ' (#120)', $filtered_post ); + $result = $this->end_ajax( serialize( $return ) ); + return $result; + } + + if ( !isset( $this->settings['allow_' . $_POST['intent']] ) || $this->settings['allow_' . $_POST['intent']] != true ) { + $return['error'] = 1; + if( $_POST['intent'] == 'pull' ) { + $intent = __( 'pull', 'wp-sync-db' ); + } + else { + $intent = __( 'push', 'wp-sync-db' ); + } + $return['message'] = sprintf( __( 'The connection succeeded but the remote site is configured to reject %s connections. You can change this in the "settings" tab on the remote site. (#122) Try again?', 'wp-sync-db' ), $intent ); + $result = $this->end_ajax( serialize( $return ) ); + return $result; + } + + $return['tables'] = $this->get_tables(); + $return['prefixed_tables'] = $this->get_tables( 'prefix' ); + $return['table_sizes'] = $this->get_table_sizes(); + $return['table_rows'] = $this->get_table_row_count(); + $return['table_sizes_hr'] = array_map( array( $this, 'format_table_sizes' ), $this->get_table_sizes() ); + $return['path'] = $this->absolute_root_file_path; + $return['url'] = home_url(); + $return['prefix'] = $wpdb->prefix; + $return['bottleneck'] = $this->get_bottleneck(); + $return['error'] = 0; + $return['plugin_version'] = $this->plugin_version; + $return['domain'] = $this->get_domain_current_site(); + $return['path_current_site'] = $this->get_path_current_site(); + $return['uploads_dir'] = $this->get_short_uploads_dir(); + $return['gzip'] = ( $this->gzip() ? '1' : '0' ); + $return['post_types'] = $this->get_post_types(); + $return['write_permissions'] = ( is_writeable( $this->get_upload_info( 'path' ) ) ? '1' : '0' ); + $return['upload_dir_long'] = $this->get_upload_info( 'path' ); + $return['temp_prefix'] = $this->temp_prefix; + $return = apply_filters( 'wpsdb_establish_remote_connection_data', $return ); + $result = $this->end_ajax( serialize( $return ) ); + return $result; + } + + function format_table_sizes( $size ) { + $size *= 1024; + return size_format( $size ); + } + // Generates our secret key + function generate_key() { + $keyset = 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'; + $key = ''; + for ( $i = 0; $i < 32; $i++ ) { + $key .= substr( $keyset, rand( 0, strlen( $keyset ) -1 ), 1 ); + } + return $key; + } + + function get_post_types() { + global $wpdb; + + if( is_multisite() ) { + $tables = $this->get_tables(); + $sql = "SELECT `post_type` FROM `{$wpdb->prefix}posts` "; + foreach( $tables as $table ) { + if( 0 == preg_match( '/' . $wpdb->prefix . '[0-9]+_posts/', $table ) ) continue; + $blog_id = str_replace( array( $wpdb->prefix, '_posts' ), array( '', '' ), $table ); + $sql .= "UNION SELECT `post_type` FROM `{$wpdb->prefix}" . $blog_id . "_posts` "; + } + $sql .= ";"; + $post_types = $wpdb->get_results( $sql, ARRAY_A ); + } + else { + $post_types = $wpdb->get_results( + "SELECT DISTINCT `post_type` + FROM `{$wpdb->prefix}posts` + WHERE 1;", ARRAY_A + ); + } + + $return = array( 'revision' ); + foreach( $post_types as $post_type ) { + $return[] = $post_type['post_type']; + } + return apply_filters( 'wpsdb_post_types', array_unique( $return ) ); + } + + // Retrieves the specified profile, if -1, returns the default profile + function get_profile( $profile_id ) { + --$profile_id; + if ( $profile_id == '-1' || ! isset( $this->settings['profiles'][$profile_id] ) ) { + return $this->default_profile; + } + return $this->settings['profiles'][$profile_id]; + } + + function get_table_row_count() { + global $wpdb; + $results = $wpdb->get_results( $wpdb->prepare( + 'SELECT table_name, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = %s', DB_NAME + ), ARRAY_A + ); + $return = array(); + foreach( $results as $results ) { + $return[$results['table_name']] = ( $results['TABLE_ROWS'] == 0 ? 1 : $results['TABLE_ROWS'] ); + } + return $return; + } + + function get_table_sizes( $scope = 'regular' ) { + global $wpdb; + $prefix = ( $scope == 'temp' ? $this->temp_prefix : $wpdb->prefix ); + $results = $wpdb->get_results( $wpdb->prepare( + 'SELECT TABLE_NAME AS "table", + ROUND((data_length + index_length)/1024,0) AS "size" + FROM information_schema.TABLES + WHERE information_schema.TABLES.table_schema="%s" + AND information_schema.TABLES.table_type="%s"', DB_NAME, "BASE TABLE" + ), ARRAY_A + ); + + $return = array(); + + foreach ( $results as $result ) { + $return[$result['table']] = $result['size']; + } + + return apply_filters( 'wpsdb_table_sizes', $return, $scope ); + } + + function get_post_max_size() { + $val = trim( ini_get( 'post_max_size' ) ); + $last = strtolower( $val[ strlen( $val ) - 1 ] ); + $val = (int) $val; + switch ( $last ) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + return $val; + } + + function get_sensible_pull_limit() { + return apply_filters( 'wpsdb_sensible_pull_limit', min( 26214400, $this->settings['max_request'] ) ); + } + + function get_bottleneck( $type = 'regular' ) { + $suhosin_limit = false; + $suhosin_request_limit = false; + $suhosin_post_limit = false; + + if ( function_exists( 'ini_get' ) ) { + $suhosin_request_limit = $this->return_bytes( ini_get( 'suhosin.request.max_value_length' ) ); + $suhosin_post_limit = $this->return_bytes( ini_get( 'suhosin.post.max_value_length' ) ); + } + + if ( $suhosin_request_limit && $suhosin_post_limit ) { + $suhosin_limit = min( $suhosin_request_limit, $suhosin_post_limit ); + } + + // we have to account for HTTP headers and other bloating, here we minus 1kb for bloat + $post_max_upper_size = apply_filters( 'wpsdb_post_max_upper_size', 26214400 ); + $calculated_bottleneck = min( ( $this->get_post_max_size() - 1024 ), $post_max_upper_size ); + + if ( $suhosin_limit ) { + $calculated_bottleneck = min( $calculated_bottleneck, $suhosin_limit - 1024 ); + } + + if( $type != 'max' ) { + $calculated_bottleneck = min( $calculated_bottleneck, $this->settings['max_request'] ); + } + + return apply_filters( 'wpsdb_bottleneck', $calculated_bottleneck ); + } + + function format_dump_name( $dump_name ) { + $extension = '.sql'; + $dump_name = sanitize_file_name( $dump_name ); + if ( $this->gzip() && isset( $this->form_data['gzip_file'] ) ) { + $extension .= '.gz'; + } + return $dump_name . $extension; + } + + function options_page() { + ?> + +
    + +

    Migrate DB

    + + + + + + addons as $addon_basename => $addon ) { + if( false == $this->is_addon_outdated( $addon_basename ) || false == is_plugin_active( $addon_basename ) ) continue; + $update_url = wp_nonce_url( network_admin_url( 'update.php?action=upgrade-plugin&plugin=' . urlencode( $addon_basename ) ), 'upgrade-plugin_' . $addon_basename ); + $addon_slug = current( explode( '/', $addon_basename ) ); + if ( isset( $GLOBALS['wpsdb_meta'][$addon_slug]['version'] ) ) { + $version = ' (' . $GLOBALS['wpsdb_meta'][$addon_slug]['version'] . ')'; + } + else { + $version = ''; + } + ?> +
    + Update Required — + Update Now', 'wp-sync-db' ), $addon['name'], $version, $update_url ); ?> +
    + +
    + PHP Safe Mode Enabled — We do not officially support running this plugin in safe mode because set_time_limit() has no effect. Therefore we can't extend the run time of the script and ensure it doesn't time out before the migration completes. We haven't disabled the plugin however, so you're free to cross your fingers and hope for the best. However, if you have trouble, we can't help you until you turn off safe mode.", 'wp-sync-db' ); + if ( function_exists( 'ini_get' ) ) { + printf( __( 'Your current PHP run time limit is set to %s seconds.', 'wp-sync-db' ), ini_get( 'max_execution_time' ) ); + } ?> +
    + + + + + set_time_limit_available() && !$hide_warning && !$safe_mode ) { + ?> +
    + PHP Function Disabled — The set_time_limit() function is currently disabled on your server. We use this function to ensure that the migration doesn't time out. We haven't disabled the plugin however, so you're free to cross your fingers and hope for the best. You may want to contact your web host to enable this function.", 'wp-sync-db' ); + if ( function_exists( 'ini_get' ) ) { + printf( __( 'Your current PHP run time limit is set to %s seconds.', 'wp-sync-db' ), ini_get( 'max_execution_time' ) ); + } ?> +
    + + +
    + + 1 profile saved + if ( ! empty( $this->settings['profiles'] ) && ! isset( $_GET['wpsdb-profile'] ) ) { + $this->template( 'profile' ); + } + else { + $this->template( 'migrate' ); + } + + $this->template( 'settings' ); + + $this->template( 'help' ); + ?> + +
    + +
    + form_data['replace_old']; + $replace = $this->form_data['replace_new']; + $new = str_ireplace( $search, $replace, $subject, $count ); + + /* + * Automatically replace URLs for subdomain based multisite installations + * e.g. //site1.example.com -> //site1.example.local for site with domain example.com + * NB: only handles the current network site, does not work for additional networks / mapped domains + */ + $subdomain_replace_enabled = apply_filters( 'wpsdb_subdomain_replace', true ); // allow developers to turn off this functionality + if ( $subdomain_replace_enabled && is_multisite() && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL & !empty( $_POST['domain_current_site'] ) ) { + $pattern = '|//(.*?)\\.' . preg_quote( $this->get_domain_current_site(), '|' ) . '|'; + $replacement = '//$1.' . trim( $_POST['domain_current_site'] ); + $new = preg_replace( $pattern, $replacement, $new ); + } + + return $new; + } + + function process_sql_constraint( $create_query, $table, &$alter_table_query ) { + if( preg_match( '@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query ) ) { + + $sql_constraints_query = ''; + + $nl_nix = "\n"; + $nl_win = "\r\n"; + $nl_mac = "\r"; + if( strpos( $create_query, $nl_win ) !== false ) { + $crlf = $nl_win; + } + elseif( strpos( $create_query, $nl_mac ) !== false ) { + $crlf = $nl_mac; + } + elseif( strpos( $create_query, $nl_nix ) !== false ) { + $crlf = $nl_nix; + } + + // Split the query into lines, so we can easily handle it. + // We know lines are separated by $crlf (done few lines above). + $sql_lines = explode( $crlf, $create_query ); + $sql_count = count( $sql_lines ); + + // lets find first line with constraints + for( $i = 0; $i < $sql_count; $i++ ) { + if (preg_match( + '@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', + $sql_lines[$i] + )) { + break; + } + } + + // If we really found a constraint + if( $i != $sql_count ) { + + // remove, from the end of create statement + $sql_lines[$i - 1] = preg_replace( + '@,$@', + '', + $sql_lines[$i - 1] + ); + + // let's do the work + $sql_constraints_query .= 'ALTER TABLE ' + . $this->backquote( $table ) + . $crlf; + + $first = true; + for( $j = $i; $j < $sql_count; $j++ ) { + if( preg_match( + '@CONSTRAINT|FOREIGN[\s]+KEY@', + $sql_lines[$j] + )) { + if( strpos( $sql_lines[$j], 'CONSTRAINT' ) === false ) { + $tmp_str = preg_replace( + '/(FOREIGN[\s]+KEY)/', + 'ADD \1', + $sql_lines[$j] + ); + $sql_constraints_query .= $tmp_str; + } + else { + $tmp_str = preg_replace( + '/(CONSTRAINT)/', + 'ADD \1', + $sql_lines[$j] + ); + $sql_constraints_query .= $tmp_str; + preg_match( + '/(CONSTRAINT)([\s])([\S]*)([\s])/', + $sql_lines[$j], + $matches + ); + } + $first = false; + } + else { + break; + } + } + $sql_constraints_query .= ";\n"; + + $create_query = implode( + $crlf, + array_slice($sql_lines, 0, $i) + ) + . $crlf + . implode( + $crlf, + array_slice( $sql_lines, $j, $sql_count - 1 ) + ); + unset( $sql_lines ); + + $alter_table_query = $sql_constraints_query; + return $create_query; + } + } + return $create_query; + } + + /** + * Taken partially from phpMyAdmin and partially from + * Alain Wolf, Zurich - Switzerland + * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/ + * Modified by Scott Merrill (http://www.skippy.net/) + * to use the WordPress $wpdb object + * + * @param string $table + * @return void + */ + function export_table( $table ) { + global $wpdb; + $this->set_time_limit(); + + if ( empty( $this->form_data ) ) { + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + } + + $temp_prefix = $this->temp_prefix; + $remote_prefix = ( isset( $_POST['prefix'] ) ? $_POST['prefix'] : $wpdb->prefix ); + + $table_structure = $wpdb->get_results( "DESCRIBE " . $this->backquote( $table ) ); + if ( ! $table_structure ) { + $this->error = __( 'Failed to retrieve table structure, please ensure your database is online. (#125)', 'wp-sync-db' ); + return false; + } + + $current_row = -1; + if ( ! empty( $_POST['current_row'] ) ) { + $temp_current_row = trim( $_POST['current_row'] ); + if ( ! empty( $temp_current_row ) ) { + $current_row = (int) $temp_current_row; + } + } + + if ( $current_row == -1 ) { + // Add SQL statement to drop existing table + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( "# " . sprintf( __( 'Delete any existing table %s', 'wp-sync-db' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); + $this->stow( "\n" ); + $this->stow( "DROP TABLE IF EXISTS " . $this->backquote( $table ) . ";\n" ); + } + else { + $this->stow( "DROP TABLE IF EXISTS " . $this->backquote( $temp_prefix . $table ) . ";\n" ); + } + + // Table structure + // Comment in SQL-file + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( "# " . sprintf( __( 'Table structure of table %s', 'wp-sync-db' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); + $this->stow( "\n" ); + } + + $create_table = $wpdb->get_results( "SHOW CREATE TABLE " . $this->backquote( $table ), ARRAY_N ); + if ( false === $create_table ) { + $this->error = __( 'Failed to generate the create table query, please ensure your database is online. (#126)', 'wp-sync-db' ); + return false; + } + + if ( $this->form_data['action'] != 'savefile' && $_POST['stage'] != 'backup' ) { + $create_table[0][1] = str_replace( 'CREATE TABLE `', 'CREATE TABLE `' . $temp_prefix, $create_table[0][1] ); + } + + $create_table[0][1] = str_replace( 'TYPE=', 'ENGINE=', $create_table[0][1] ); + + $alter_table_query = ''; + $create_table[0][1] = $this->process_sql_constraint( $create_table[0][1], $table, $alter_table_query ); + + $create_table[0][1] = apply_filters( 'wpsdb_create_table_query', $create_table[0][1], $table ); + + $this->stow( $create_table[0][1] . ";\n" ); + + if( ! empty( $alter_table_query ) ) { + $alter_table_name = $this->get_alter_table_name(); + $insert = sprintf( "INSERT INTO %s ( `query` ) VALUES ( '%s' );\n", $this->backquote( $alter_table_name ), esc_sql( $alter_table_query ) ); + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $process_chunk_result = $this->process_chunk( $insert ); + if( true !== $process_chunk_result ) { + $result = $this->end_ajax( $process_chunk_result ); + return $result; + } + } + else { + $this->stow( $insert ); + } + } + + // Comment in SQL-file + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'Data contents of table %s', 'wp-sync-db' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); + } + } + + // $defs = mysql defaults, looks up the default for that paricular column, used later on to prevent empty inserts values for that column + // $ints = holds a list of the possible integar types so as to not wrap them in quotation marks later in the insert statements + $defs = array(); + $ints = array(); + foreach ( $table_structure as $struct ) { + if ( ( 0 === strpos( $struct->Type, 'tinyint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'smallint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'mediumint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'int' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'bigint' ) ) ) { + $defs[strtolower( $struct->Field )] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; + $ints[strtolower( $struct->Field )] = "1"; + } + } + + // Batch by $row_inc + + $row_inc = $this->rows_per_segment; + $row_start = 0; + if ( $current_row != -1 ) { + $row_start = $current_row; + } + + $this->row_tracker = $row_start; + + // \x08\\x09, not required + $search = array( "\x00", "\x0a", "\x0d", "\x1a" ); + $replace = array( '\0', '\n', '\r', '\Z' ); + + $query_size = 0; + + $table_name = $table; + + if ( $this->form_data['action'] != 'savefile' && $_POST['stage'] != 'backup' ) { + $table_name = $temp_prefix . $table; + } + + $this->primary_keys = array(); + $use_primary_keys = true; + foreach( $table_structure as $col ){ + $field_set[] = $this->backquote( $col->Field ); + if( $col->Key == 'PRI' && true == $use_primary_keys ) { + if( false === strpos( $col->Type, 'int' ) ) { + $use_primary_keys = false; + $this->primary_keys = array(); + continue; + } + $this->primary_keys[$col->Field] = 0; + } + } + + $first_select = true; + if( ! empty( $_POST['primary_keys'] ) ) { + $_POST['primary_keys'] = trim( $_POST['primary_keys'] ); + if( ! empty( $_POST['primary_keys'] ) && is_serialized( $_POST['primary_keys'] ) ) { + $this->primary_keys = unserialize( stripslashes( $_POST['primary_keys'] ) ); + $first_select = false; + } + } + + $fields = implode( ', ', $field_set ); + + $insert_buffer = $insert_query_template = "INSERT INTO " . $this->backquote( $table_name ) . " ( " . $fields . ") VALUES\n"; + + do { + $join = array(); + $where = 'WHERE 1=1'; + $order_by = ''; + // We need ORDER BY here because with LIMIT, sometimes it will return + // the same results from the previous query and we'll have duplicate insert statements + if ( 'backup' != $_POST['stage'] && isset( $this->form_data['exclude_spam'] ) ) { + if ( $this->table_is( 'comments', $table ) ) { + $where .= ' AND comment_approved != "spam"'; + } + elseif ( $this->table_is( 'commentmeta', $table ) ) { + extract( $this->get_ms_compat_table_names( array( 'commentmeta', 'comments' ), $table ) ); + $join[] = sprintf( 'INNER JOIN %1$s ON %1$s.comment_ID = %2$s.comment_id', $this->backquote( $comments_table ), $this->backquote( $commentmeta_table ) ); + $where .= sprintf( ' AND %1$s.comment_approved != \'spam\'', $this->backquote( $comments_table ) ); + } + } + + if ( 'backup' != $_POST['stage'] && isset( $this->form_data['exclude_post_types'] ) && ! empty( $this->form_data['select_post_types'] ) ) { + $post_types = '\'' . implode( '\', \'', $this->form_data['select_post_types'] ) . '\''; + if( $this->table_is( 'posts', $table ) ) { + $where .= ' AND `post_type` NOT IN ( ' . $post_types . ' )'; + } + elseif( $this->table_is( 'postmeta', $table ) ) { + extract( $this->get_ms_compat_table_names( array( 'postmeta', 'posts' ), $table ) ); + $join[] = sprintf( 'INNER JOIN %1$s ON %1$s.ID = %2$s.post_id', $this->backquote( $posts_table ), $this->backquote( $postmeta_table ) ); + $where .= sprintf( ' AND %1$s.post_type NOT IN ( ' . $post_types . ' )', $this->backquote( $posts_table ) ); + } + elseif ( $this->table_is( 'comments', $table ) ) { + extract( $this->get_ms_compat_table_names( array( 'comments', 'posts' ), $table ) ); + $join[] = sprintf( 'INNER JOIN %1$s ON %1$s.ID = %2$s.comment_post_ID', $this->backquote( $posts_table ), $this->backquote( $comments_table ) ); + $where .= sprintf( ' AND %1$s.post_type NOT IN ( ' . $post_types . ' )', $this->backquote( $posts_table ) ); + } + elseif( $this->table_is( 'commentmeta', $table ) ) { + extract( $this->get_ms_compat_table_names( array( 'commentmeta', 'posts', 'comments' ), $table ) ); + $join[] = sprintf( 'INNER JOIN %1$s ON %1$s.comment_ID = %2$s.comment_id', $this->backquote( $comments_table ), $this->backquote( $commentmeta_table ) ); + $join[] = sprintf( 'INNER JOIN %2$s ON %2$s.ID = %1$s.comment_post_ID', $this->backquote( $comments_table ), $this->backquote( $posts_table ) ); + $where .= sprintf( ' AND %1$s.post_type NOT IN ( ' . $post_types . ' )', $this->backquote( $posts_table ) ); + } + } + + if ( 'backup' != $_POST['stage'] && true === apply_filters( 'wpsdb_exclude_transients', true ) && isset( $this->form_data['exclude_transients'] ) && '1' === $this->form_data['exclude_transients'] && ( $this->table_is( 'options', $table ) || ( isset( $wpdb->sitemeta ) && $wpdb->sitemeta == $table ) ) ) { + $col_name = 'option_name'; + + if( isset( $wpdb->sitemeta ) && $wpdb->sitemeta == $table ) { + $col_name = 'meta_key'; + } + + $where .= " AND `{$col_name}` NOT LIKE '\_transient\_%' AND `{$col_name}` NOT LIKE '\_site\_transient\_%'"; + } + + $limit = "LIMIT {$row_start}, {$row_inc}"; + + if( ! empty( $this->primary_keys ) ) { + $primary_keys_keys = array_keys( $this->primary_keys ); + $primary_keys_keys = array_map( array( $this, 'backquote' ), $primary_keys_keys ); + + $order_by = 'ORDER BY ' . implode( ',', $primary_keys_keys ); + $limit = "LIMIT $row_inc"; + if( false == $first_select ) { + $where .= ' AND '; + + $temp_primary_keys = $this->primary_keys; + $primary_key_count = count( $temp_primary_keys ); + + // build a list of clauses, iteratively reducing the number of fields compared in the compound key + // e.g. (a = 1 AND b = 2 AND c > 3) OR (a = 1 AND b > 2) OR (a > 1) + $clauses = array(); + for( $j = 0; $j < $primary_key_count; $j++ ) { + // build a subclause for each field in the compound index + $subclauses = array(); + $i = 0; + foreach( $temp_primary_keys as $primary_key => $value ) { + // only the last field in the key should be different in this subclause + $operator = ( count( $temp_primary_keys ) - 1 == $i ? '>' : '=' ); + $subclauses[] = sprintf( '%s %s %s', $this->backquote( $primary_key ), $operator, $wpdb->prepare( '%s', $value ) ); + ++$i; + } + + // remove last field from array to reduce fields in next clause + array_pop( $temp_primary_keys ); + + // join subclauses into a single clause + // NB: AND needs to be wrapped in () as it has higher precedence than OR + $clauses[] = '( ' . implode( ' AND ', $subclauses ) . ' )'; + } + // join clauses into a single clause + // NB: OR needs to be wrapped in () as it has lower precedence than AND + $where .= '( ' . implode( ' OR ', $clauses ) . ' )'; + } + $first_select = false; + } + + $join = implode( ' ', array_unique( $join ) ); + $join = apply_filters( 'wpsdb_rows_join', $join, $table ); + $where = apply_filters( 'wpsdb_rows_where', $where, $table ); + $order_by = apply_filters( 'wpsdb_rows_order_by', $order_by, $table ); + $limit = apply_filters( 'wpsdb_rows_limit', $limit, $table ); + + $sql = "SELECT " . $this->backquote( $table ) . ".* FROM " . $this->backquote( $table ) . " $join $where $order_by $limit"; + $sql = apply_filters( 'wpsdb_rows_sql', $sql, $table ); + + $table_data = $wpdb->get_results( $sql ); + + if ( $table_data ) { + foreach ( $table_data as $row ) { + $values = array(); + foreach ( $row as $key => $value ) { + if ( isset( $ints[strtolower( $key )] ) && $ints[strtolower( $key )] ) { + // make sure there are no blank spots in the insert syntax, + // yet try to avoid quotation marks around integers + $value = ( null === $value || '' === $value ) ? $defs[strtolower( $key )] : $value; + $values[] = ( '' === $value ) ? "''" : $value; + } else { + if ( null === $value ) { + $values[] = 'NULL'; + } + else { + + if( is_multisite() && 'path' == $key && $_POST['stage'] != 'backup' && ( $wpdb->site == $table || $wpdb->blogs == $table ) ) { + $old_path_current_site = $this->get_path_current_site(); + if( ! empty( $_POST['path_current_site'] ) ) { + $new_path_current_site = stripslashes( $_POST['path_current_site'] ); + } + else { + $new_path_current_site = $this->get_path_from_url( $this->form_data['replace_new'][1] ); + } + + if( $old_path_current_site != $new_path_current_site ) { + $pos = strpos( $value, $old_path_current_site ); + $value = substr_replace( $value, $new_path_current_site, $pos, strlen( $old_path_current_site ) ); + } + } + + if( is_multisite() && 'domain' == $key && $_POST['stage'] != 'backup' && ( $wpdb->site == $table || $wpdb->blogs == $table ) ) { + if( ! empty( $_POST['domain_current_site'] ) ) { + $main_domain_replace = $_POST['domain_current_site']; + } + else { + $url = parse_url( $this->form_data['replace_new'][1] ); + $main_domain_replace = $url['host']; + } + + $main_domain_find = sprintf( "/%s/", $this->get_domain_current_site() ); + $domain_replaces[$main_domain_find] = $main_domain_replace; + $domain_replaces = apply_filters( 'wpsdb_domain_replaces', $domain_replaces ); + + $value = preg_replace( array_keys( $domain_replaces ), array_values( $domain_replaces ), $value ); + } + + if ( 'guid' != $key || ( isset( $this->form_data['replace_guids'] ) && $this->table_is( 'posts', $table ) ) ) { + if ( $_POST['stage'] != 'backup' ) { + $value = $this->recursive_unserialize_replace( $value ); + } + } + + $values[] = "'" . str_replace( $search, $replace, $this->sql_addslashes( $value ) ) . "'"; + } + } + } + + $insert_line = '(' . implode( ', ', $values ) . '),'; + $insert_line .= "\n"; + + if ( ( strlen( $this->current_chunk ) + strlen( $insert_line ) + strlen( $insert_buffer ) + 10 ) > $this->maximum_chunk_size ) { + if( $insert_buffer == $insert_query_template ) { + $insert_buffer .= $insert_line; + + ++$this->row_tracker; + + if( ! empty( $this->primary_keys ) ) { + foreach( $this->primary_keys as $primary_key => $value ) { + $this->primary_keys[$primary_key] = $row->$primary_key; + } + } + } + $insert_buffer = rtrim( $insert_buffer, "\n," ); + $insert_buffer .= " ;\n"; + $this->stow( $insert_buffer ); + $insert_buffer = $insert_query_template; + $query_size = 0; + return $this->transfer_chunk(); + } + + if ( ( $query_size + strlen( $insert_line ) ) > $this->max_insert_string_len && $insert_buffer != $insert_query_template ) { + $insert_buffer = rtrim( $insert_buffer, "\n," ); + $insert_buffer .= " ;\n"; + $this->stow( $insert_buffer ); + $insert_buffer = $insert_query_template; + $query_size = 0; + } + + $insert_buffer .= $insert_line; + $query_size += strlen( $insert_line ); + + ++$this->row_tracker; + + if( ! empty( $this->primary_keys ) ) { + foreach( $this->primary_keys as $primary_key => $value ) { + $this->primary_keys[$primary_key] = $row->$primary_key; + } + } + } + $row_start += $row_inc; + + if ( $insert_buffer != $insert_query_template ) { + $insert_buffer = rtrim( $insert_buffer, "\n," ); + $insert_buffer .= " ;\n"; + $this->stow( $insert_buffer ); + $insert_buffer = $insert_query_template; + $query_size = 0; + } + + } + } while ( count( $table_data ) > 0 ); + + // Create footer/closing comment in SQL-file + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $this->stow( "\n" ); + $this->stow( "#\n" ); + $this->stow( "# " . sprintf( __( 'End of data contents of table %s', 'wp-sync-db' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "# --------------------------------------------------------\n" ); + $this->stow( "\n" ); + + if( $_POST['last_table'] == '1' ) { + $this->stow( "#\n" ); + $this->stow( "# Add constraints back in\n" ); + $this->stow( "#\n\n" ); + $this->stow( $this->get_alter_queries() ); + $alter_table_name = $this->get_alter_table_name(); + if ( $this->form_data['action'] == 'savefile' ) { + $wpdb->query( "DROP TABLE IF EXISTS " . $this->backquote( $alter_table_name ) . ";" ); + } + } + } + + $this->row_tracker = -1; + return $this->transfer_chunk(); + + } // end backup_table() + + function table_is( $desired_table, $given_table ) { + global $wpdb; + return ( $wpdb->{$desired_table} == $given_table || preg_match( '/' . $wpdb->prefix . '[0-9]+_' . $desired_table . '/', $given_table ) ); + } + + /** + * return multisite-compatible names for requested tables, based on queried table name + * + * @param array $tables list of table names required + * @param string $queried_table name of table from which to derive the blog ID + * + * @return array list of table names altered for multisite compatibility + */ + function get_ms_compat_table_names( $tables, $queried_table ) { + global $wpdb; + + // default table prefix + $prefix = $wpdb->prefix; + + // if multisite, extract blog ID from queried table name and add to prefix + // won't match for primary blog because it uses standard table names, i.e. blog_id will never be 1 + if ( is_multisite() && preg_match( '/^' . preg_quote( $wpdb->prefix, '/' ) . '([0-9]+)_/', $queried_table, $matches ) ) { + $blog_id = $matches[1]; + $prefix .= $blog_id . '_'; + } + + // build table names + $ms_compat_table_names = array(); + foreach( $tables as $table ) { + $ms_compat_table_names[$table . '_table'] = $prefix . $table; + } + return $ms_compat_table_names; + } + + /** + * Take a serialized array and unserialize it replacing elements as needed and + * unserialising any subordinate arrays and performing the replace on those too. + * + * Mostly from https://github.com/interconnectit/Search-Replace-DB + * + * @param array $data Used to pass any subordinate arrays back to in. + * @param bool $serialized Does the array passed via $data need serialising. + * @param bool $parent_serialized Passes whether the original data passed in was serialized + * + * @return array The original array with all elements replaced as needed. + */ + function recursive_unserialize_replace( $data, $serialized = false, $parent_serialized = false ) { + + $is_json = false; + // some unseriliased data cannot be re-serialized eg. SimpleXMLElements + try { + + if ( is_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) { + // PHP currently has a bug that doesn't allow you to clone the DateInterval / DatePeriod classes. + // We skip them here as they probably won't need data to be replaced anyway + if( is_object( $unserialized ) ) { + if( $unserialized instanceof DateInterval || $unserialized instanceof DatePeriod ) return $data; + } + $data = $this->recursive_unserialize_replace( $unserialized, true, true ); + } + elseif ( is_array( $data ) ) { + $_tmp = array( ); + foreach ( $data as $key => $value ) { + $_tmp[ $key ] = $this->recursive_unserialize_replace( $value, false, $parent_serialized ); + } + + $data = $_tmp; + unset( $_tmp ); + } + // Submitted by Tina Matter + elseif ( is_object( $data ) ) { + $_tmp = clone $data; + foreach ( $data as $key => $value ) { + $_tmp->$key = $this->recursive_unserialize_replace( $value, false, $parent_serialized ); + } + + $data = $_tmp; + unset( $_tmp ); + } + elseif ( $this->is_json( $data, true ) ) { + $_tmp = array( ); + $data = json_decode( $data, true ); + foreach ( $data as $key => $value ) { + $_tmp[ $key ] = $this->recursive_unserialize_replace( $value, false, $parent_serialized ); + } + + $data = $_tmp; + unset( $_tmp ); + $is_json = true; + } + elseif ( is_string( $data ) ) { + $data = $this->apply_replaces( $data, $parent_serialized ); + } + + if ( $serialized ) + return serialize( $data ); + + if ( $is_json ) + return json_encode( $data ); + + } catch( Exception $error ) { + + } + + return $data; + } + + function db_backup_header() { + $charset = ( defined( 'DB_CHARSET' ) ? DB_CHARSET : 'utf8' ); + $this->stow( "# " . __( 'WordPress MySQL database migration', 'wp-sync-db' ) . "\n", false ); + $this->stow( "#\n", false ); + $this->stow( "# " . sprintf( __( 'Generated: %s', 'wp-sync-db' ), date( "l j. F Y H:i T" ) ) . "\n", false ); + $this->stow( "# " . sprintf( __( 'Hostname: %s', 'wp-sync-db' ), DB_HOST ) . "\n", false ); + $this->stow( "# " . sprintf( __( 'Database: %s', 'wp-sync-db' ), $this->backquote( DB_NAME ) ) . "\n", false ); + $this->stow( "# --------------------------------------------------------\n\n", false ); + $this->stow( "/*!40101 SET NAMES $charset */;\n\n", false ); + $this->stow( "SET sql_mode='NO_AUTO_VALUE_ON_ZERO';\n\n", false ); + } + + function gzip() { + return function_exists( 'gzopen' ); + } + + function open( $filename = '', $mode = 'a' ) { + if ( '' == $filename ) return false; + if ( $this->gzip() && isset( $this->form_data['gzip_file'] ) ) + $fp = gzopen( $filename, $mode ); + else + $fp = fopen( $filename, $mode ); + return $fp; + } + + function close( $fp ) { + if ( $this->gzip() && isset( $this->form_data['gzip_file'] ) ) gzclose( $fp ); + else fclose( $fp ); + unset( $this->fp ); + } + + function stow( $query_line, $replace = true ) { + $this->current_chunk .= $query_line; + if ( $this->form_data['action'] == 'savefile' || $_POST['stage'] == 'backup' ) { + if ( $this->gzip() && isset( $this->form_data['gzip_file'] ) ) { + if ( ! @gzwrite( $this->fp, $query_line ) ) { + $this->error = __( 'Failed to write the gzipped SQL data to the file. (#127)', 'wp-sync-db' ); + return false; + } + } + else { + if ( false === @fwrite( $this->fp, $query_line ) ) { + $this->error = __( 'Failed to write the SQL data to the file. (#128)', 'wp-sync-db' ); + return false; + } + } + } + else if ( $_POST['intent'] == 'pull' ) { + echo $query_line; + } + } + + // Called in the $this->stow function once our chunk buffer is full, will transfer the SQL to the remote server for importing + function transfer_chunk() { + if( $_POST['intent'] == 'savefile' || $_POST['stage'] == 'backup' ) { + $this->close( $this->fp ); + $result = $this->end_ajax( json_encode( + array( + 'current_row' => $this->row_tracker, + 'primary_keys' => serialize( $this->primary_keys ) + ) + ) ); + return $result; + } + + if ( $_POST['intent'] == 'pull' ) { + $result = $this->end_ajax( $this->row_tracker . ',' . serialize( $this->primary_keys ) ); + return $result; + } + + $chunk_gzipped = '0'; + if( isset( $_POST['gzip'] ) && $_POST['gzip'] == '1' && $this->gzip() ) { + $this->current_chunk = gzcompress( $this->current_chunk ); + $chunk_gzipped = '1'; + } + + $data = array( + 'action' => 'wpsdb_process_chunk', + 'table' => $_POST['table'], + 'chunk_gzipped' => $chunk_gzipped, + 'chunk' => $this->current_chunk // NEEDS TO BE the last element in this array because of adding it back into the array in ajax_process_chunk() + ); + + $data['sig'] = $this->create_signature( $data, $_POST['key'] ); + + $ajax_url = trailingslashit( $this->remote_url ) . 'wp-admin/admin-ajax.php'; + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + ob_start(); + $this->display_errors(); + $response = ob_get_clean(); + $response .= trim( $response ); + if( ! empty( $response ) ) { + $result = $this->end_ajax( $response ); + return $result; + } + + $result = $this->end_ajax( json_encode( + array( + 'current_row' => $this->row_tracker, + 'primary_keys' => serialize( $this->primary_keys ) + ) + ) ); + return $result; + } + + /** + * Add backquotes to tables and db-names in + * SQL queries. Taken from phpMyAdmin. + */ + function backquote( $a_name ) { + if ( !empty( $a_name ) && $a_name != '*' ) { + if ( is_array( $a_name ) ) { + $result = array(); + reset( $a_name ); + while ( list( $key, $val ) = each( $a_name ) ) + $result[$key] = '`' . $val . '`'; + return $result; + } else { + return '`' . $a_name . '`'; + } + } else { + return $a_name; + } + } + + /** + * Better addslashes for SQL queries. + * Taken from phpMyAdmin. + */ + function sql_addslashes( $a_string = '', $is_like = false ) { + if ( $is_like ) $a_string = str_replace( '\\', '\\\\\\\\', $a_string ); + else $a_string = str_replace( '\\', '\\\\', $a_string ); + return str_replace( '\'', '\\\'', $a_string ); + } + + function network_admin_menu() { + $hook_suffix = add_submenu_page( 'settings.php', 'Migrate DB', 'Migrate DB', 'manage_network_options', 'wp-sync-db', array( $this, 'options_page' ) ); + $this->after_admin_menu( $hook_suffix ); + } + + function admin_menu() { + $hook_suffix = add_management_page( 'Migrate DB', 'Migrate DB', 'export', 'wp-sync-db', array( $this, 'options_page' ) ); + $this->after_admin_menu( $hook_suffix ); + } + + function after_admin_menu( $hook_suffix ) { + add_action( 'admin_head-' . $hook_suffix, array( $this, 'admin_head_connection_info' ) ); + add_action( 'load-' . $hook_suffix , array( $this, 'load_assets' ) ); + } + + function admin_body_class( $classes ) { + if ( !$classes ) { + $classes = array(); + } + else { + $classes = explode( ' ', $classes ); + } + + // Recommended way to target WP 3.8+ + // http://make.wordpress.org/ui/2013/11/19/targeting-the-new-dashboard-design-in-a-post-mp6-world/ + if ( version_compare( $GLOBALS['wp_version'], '3.8-alpha', '>' ) ) { + if ( !in_array( 'mp6', $classes ) ) { + $classes[] = 'mp6'; + } + } + + return implode( ' ', $classes ); + } + + function load_assets() { + if ( ! empty( $_GET['download'] ) ) { + $this->download_file(); + } + + $plugins_url = trailingslashit( plugins_url( '', $this->plugin_file_path ) ); + + $version = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? time() : $this->plugin_version; + + $src = $plugins_url . 'asset/css/styles.css'; + wp_enqueue_style( 'wp-sync-db-styles', $src, array(), $version ); + + $src = $plugins_url . 'asset/js/common.js'; + wp_enqueue_script( 'wp-sync-db-common', $src, NULL, $version, true ); + + $src = $plugins_url . 'asset/js/hook.js'; + wp_enqueue_script( 'wp-sync-db-hook', $src, NULL, $version, true ); + + do_action( 'wpsdb_load_assets' ); + + $src = $plugins_url . 'asset/js/script.js'; + wp_enqueue_script( 'wp-sync-db-script', $src, array( 'jquery' ), $version, true ); + + wp_localize_script( 'wp-sync-db-script', 'wpsdb_i10n', array( + 'max_request_size_problem' => __( "A problem occurred when trying to change the maximum request size, please try again.", 'wp-sync-db' ), + 'establishing_remote_connection' => __( "Establishing connection to remote server, please wait", 'wp-sync-db' ), + 'connection_local_server_problem' => __( "A problem occurred when attempting to connect to the local server, please check the details and try again.", 'wp-sync-db' ), + 'clear_log_problem' => __( "An error occurred when trying to clear the debug log. Please contact support. (#132)", 'wp-sync-db' ), + 'update_log_problem' => __( "An error occurred when trying to update the debug log. Please contact support. (#133)", 'wp-sync-db' ), + 'migrate_db_save' => __( "Migrate DB & Save", 'wp-sync-db' ), + 'migrate_db' => __( "Migrate DB", 'wp-sync-db' ), + 'please_select_one_table' => __( "Please select at least one table to migrate.", 'wp-sync-db' ), + 'enter_name_for_profile' => __( "Please enter a name for your migration profile.", 'wp-sync-db' ), + 'save_profile_problem' => __( "An error occurred when attempting to save the migration profile. Please see the Help tab for details on how to request support. (#118)", 'wp-sync-db' ), + 'exporting_complete' => __( "Exporting complete", 'wp-sync-db' ), + 'exporting_please_wait' => __( "Exporting, please wait...", 'wp-sync-db' ), + 'please_wait' => __( "please wait...", 'wp-sync-db' ), + 'complete' => __( "complete", 'wp-sync-db' ), + 'migration_failed' => __( "Migration failed", 'wp-sync-db' ), + 'backing_up' => __( "Backing up", 'wp-sync-db' ), + 'migrating' => __( "Migrating", 'wp-sync-db' ), + 'status' => __( "Status", 'wp-sync-db' ), + 'response' => __( "Response", 'wp-sync-db' ), + 'table_process_problem' => __( "A problem occurred when attempting to process the following table (#113)", 'wp-sync-db' ), + 'table_process_problem_empty_response' => __( "A problem occurred when processing the following table. We were expecting a response in JSON format but instead received an empty response.", 'wp-sync-db' ), + 'completed_with_some_errors' => __( "Migration completed with some errors", 'wp-sync-db' ), + 'completed_dump_located_at' => __( "Migration complete, your backup is located at:", 'wp-sync-db' ), + 'finalize_tables_problem' => __( "A problem occurred when finalizing the backup. (#132)", 'wp-sync-db' ), + 'saved' => __( "Saved", 'wp-sync-db' ), + 'reset_api_key' => __( "Any sites setup to use the current API key will no longer be able to connect. You will need to update those sites with the newly generated API key. Do you wish to continue?", 'wp-sync-db' ), + 'reset_api_key_problem' => __( "An error occurred when trying to generate the API key. Please see the Help tab for details on how to request support. (#105)", 'wp-sync-db' ), + 'remove_profile' => __( "You are removing the following migration profile. This cannot be undone. Do you wish to continue?", 'wp-sync-db' ), + 'remove_profile_problem' => __( "An error occurred when trying to delete the profile. Please see the Help tab for details on how to request support. (#106)", 'wp-sync-db' ), + 'remove_profile_not_found' => __( "The selected migration profile could not be deleted because it was not found.\nPlease refresh this page to see an accurate list of the currently available migration profiles.", 'wp-sync-db' ), + 'change_connection_info' => __( "If you change the connection details, you will lose any replaces and table selections you have made below. Do you wish to continue?", 'wp-sync-db' ), + 'enter_connection_info' => __( "Please enter the connection information above to continue.", 'wp-sync-db' ), + 'save_settings_problem' => __( "An error occurred when trying to save the settings. Please try again. If the problem persists, please see the Help tab for details on how to request support. (#108)", 'wp-sync-db' ), + 'connection_info_missing' => __( "The connection information appears to be missing, please enter it to continue.", 'wp-sync-db' ), + 'connection_info_incorrect' => __( "The connection information appears to be incorrect, it should consist of two lines. The first being the remote server's URL and the second being the secret key.", 'wp-sync-db' ), + 'connection_info_url_invalid' => __( "The URL on the first line appears to be invalid, please check it and try again.", 'wp-sync-db' ), + 'connection_info_key_invalid' => __( "The secret key on the second line appears to be invalid. It should be a 32 character string that consists of letters, numbers and special characters only.", 'wp-sync-db' ), + 'connection_info_local_url' => __( "It appears you've entered the URL for this website, you need to provide the URL of the remote website instead.", 'wp-sync-db' ), + 'connection_info_local_key' => __( "It appears you've entered the secret key for this website, you need to provide the secret key for the remote website instead.", 'wp-sync-db' ), + 'time_elapsed' => __( "Time Elapsed:", 'wp-sync-db' ), + 'pause' => __( "Pause", 'wp-sync-db' ), + 'migration_paused' => __( "Migration Paused", 'wp-sync-db' ), + 'resume' => __( "Resume", 'wp-sync-db' ), + 'completing_current_request' => __( "Completing current request", 'wp-sync-db' ), + 'cancelling_migration' => __( "Cancelling migration", 'wp-sync-db' ), + 'paused' => __( "Paused", 'wp-sync-db' ), + 'removing_local_sql' => __( "Removing the local MySQL export file", 'wp-sync-db' ), + 'removing_local_backup' => __( "Removing the local backup MySQL export file", 'wp-sync-db' ), + 'removing_local_temp_tables' => __( "Removing the local temporary tables", 'wp-sync-db' ), + 'removing_remote_sql' => __( "Removing the remote backup MySQL export file", 'wp-sync-db' ), + 'removing_remote_temp_tables' => __( "Removing the remote temporary tables", 'wp-sync-db' ), + 'migration_cancellation_failed' => __( "Migration cancellation failed", 'wp-sync-db' ), + 'manually_remove_temp_files' => __( "A problem occurred while cancelling the migration, you may have to manually delete some temporary files / tables.", 'wp-sync-db' ), + 'migration_cancelled' => __( "Migration cancelled", 'wp-sync-db' ), + ) ); + + wp_enqueue_script('jquery'); + wp_enqueue_script('jquery-ui-core'); + wp_enqueue_script('jquery-ui-slider'); + wp_enqueue_script('jquery-ui-sortable'); + + } + + function download_file() { + // dont need to check for user permissions as our 'add_management_page' already takes care of this + $this->set_time_limit(); + + $dump_name = $this->format_dump_name( $_GET['download'] ); + if( isset( $_GET['gzip'] ) ) { + $dump_name .= '.gz'; + } + $diskfile = $this->get_upload_info( 'path' ) . DS . $dump_name; + $filename = basename( $diskfile ); + $last_dash = strrpos( $filename, '-' ); + $salt = substr( $filename, $last_dash, 6 ); + $filename_no_salt = str_replace( $salt, '', $filename ); + + if ( file_exists( $diskfile ) ) { + header( 'Content-Description: File Transfer' ); + header( 'Content-Type: application/octet-stream' ); + header( 'Content-Length: ' . filesize( $diskfile ) ); + header( 'Content-Disposition: attachment; filename=' . $filename_no_salt ); + $success = readfile( $diskfile ); + unlink( $diskfile ); + exit; + } + else { + wp_die( __( 'Could not find the file to download:', 'wp-sync-db' ) . '
    ' . $diskfile ); + } + } + + function admin_head_connection_info() { + global $table_prefix; + + $nonces = array( + 'update_max_request_size' => wp_create_nonce( 'update-max-request-size' ), + 'verify_connection_to_remote_site' => wp_create_nonce( 'verify-connection-to-remote-site' ), + 'clear_log' => wp_create_nonce( 'clear-log' ), + 'get_log' => wp_create_nonce( 'get-log' ), + 'save_profile' => wp_create_nonce( 'save-profile' ), + 'initiate_migration' => wp_create_nonce( 'initiate-migration' ), + 'migrate_table' => wp_create_nonce( 'migrate-table' ), + 'finalize_migration' => wp_create_nonce( 'finalize-migration' ), + 'reset_api_key' => wp_create_nonce( 'reset-api-key' ), + 'delete_migration_profile' => wp_create_nonce( 'delete-migration-profile' ), + 'save_setting' => wp_create_nonce( 'save-setting' ), + ); + + $nonces = apply_filters( 'wpsdb_nonces', $nonces ); + + ?> + + get_post_types(); + $profile['select_post_types'] = array_diff( $all_post_types, $profile['select_post_types'] ); + $profile_changed = true; + } + + if ( $profile_changed ) { + $this->settings['profiles'][$profile_id] = $profile; + update_option( 'wpsdb_settings', $this->settings ); + } + return $profile; + } + + function get_path_from_url( $url ) { + $parts = parse_url( $url ); + return ( ! empty( $parts['path'] ) ) ? trailingslashit( $parts['path'] ) : '/'; + } + + function get_path_current_site() { + if( ! is_multisite() ) return ''; + $current_site = get_current_site(); + return $current_site->path; + } + + function get_domain_current_site() { + if( ! is_multisite() ) return ''; + $current_site = get_current_site(); + return $current_site->domain; + } + + function return_bytes($val) { + if( is_numeric( $val ) ) return $val; + if( empty( $val ) ) return false; + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + $val = (int) $val; + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + break; + default : + $val = false; + break; + } + + return $val; + } + + function maybe_checked( $option ) { + echo ( isset( $option ) && $option == '1' ) ? ' checked="checked"' : ''; + } + + function ajax_cancel_migration() { + $this->form_data = $this->parse_migration_form_data( $_POST['form_data'] ); + + switch( $_POST['intent'] ) { + case 'savefile' : + $this->delete_export_file( $_POST['dump_filename'], false ); + break; + + case 'push' : + $data = $_POST; + $data['action'] = 'wpsdb_process_push_migration_cancellation'; + $data['temp_prefix'] = $this->temp_prefix; + $ajax_url = trailingslashit( $data['url'] ) . 'wp-admin/admin-ajax.php'; + $data['sig'] = $this->create_signature( $data, $data['key'] ); + + $response = $this->remote_post( $ajax_url, $data, __FUNCTION__ ); + $this->display_errors(); + + echo trim( $response ); + break; + + case 'pull' : + if( $_POST['stage'] == 'backup' ) { + $this->delete_export_file( $_POST['dump_filename'], true ); +} + else { + $this->delete_temporary_tables( $_POST['temp_prefix'] ); + } + break; + + default: + break; + } + + exit; + } + + function respond_to_process_push_migration_cancellation() { + $filtered_post = $this->filter_post_elements( $_POST, array( 'action', 'intent', 'url', 'key', 'form_data', 'dump_filename', 'temp_prefix', 'stage' ) ); + if ( ! $this->verify_signature( $filtered_post, $this->settings['key'] ) ) { + echo $this->invalid_content_verification_error; + exit; + } + + $this->form_data = $this->parse_migration_form_data( $filtered_post['form_data'] ); + + if( $filtered_post['stage'] == 'backup' ) { + $this->delete_export_file( $filtered_post['dump_filename'], true ); + } + else { + $this->delete_temporary_tables( $filtered_post['temp_prefix'] ); + } + exit; + } + + function delete_export_file( $filename, $is_backup ) { + $dump_file = $this->format_dump_name( $filename ); + if( true == $is_backup ) { + $dump_file = preg_replace( '/.gz$/', '', $dump_file ); + } + $dump_file = $this->get_upload_info( 'path' ) . DS . $dump_file; + + if( empty( $dump_file ) || false == file_exists( $dump_file ) ) { + _e( 'MySQL export file not found.', 'wp-sync-db' ); + exit; + } + + if( false === @unlink( $dump_file ) ) { + e( 'Could not delete the MySQL export file.', 'wp-sync-db' ); + exit; + } + } + + function delete_temporary_tables( $prefix ) { + $tables = $this->get_tables(); + $delete_queries = ''; + foreach( $tables as $table ) { + if( 0 !== strpos( $table, $prefix ) ) continue; + $delete_queries .= sprintf( "DROP TABLE %s;\n", $this->backquote( $table ) ); + } + $this->process_chunk( $delete_queries ); + } + + function empty_current_chunk() { + $this->current_chunk = ''; + } + +} diff --git a/compatibility/wp-sync-db-compatibility.php b/compatibility/wp-sync-db-compatibility.php new file mode 100644 index 0000000..69c24a4 --- /dev/null +++ b/compatibility/wp-sync-db-compatibility.php @@ -0,0 +1,50 @@ + $plugin ) { + if ( false !== strpos( $plugin, 'wp-sync-db' ) || !isset( $blacklist_plugins[$plugin] ) ) continue; + unset( $plugins[$key] ); + } + return $plugins; +} +add_filter( 'option_active_plugins', 'wpsdbc_exclude_plugins' ); + + +/** +* remove network-active plugins +* @param array $plugins array of plugins keyed by name (name=>timestamp pairs) +* @return array +*/ +function wpsdbc_exclude_site_plugins( $plugins ) { + if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX || !isset( $_POST['action'] ) || false === strpos( $_POST['action'], 'wpsdb' ) ) return $plugins; + $wpsdb_settings = get_option( 'wpsdb_settings' ); + if ( !empty( $wpsdb_settings['blacklist_plugins'] ) ) { + $blacklist_plugins = array_flip( $wpsdb_settings['blacklist_plugins'] ); + } + foreach( array_keys( $plugins ) as $plugin ) { + if ( false !== strpos( $plugin, 'wp-sync-db' ) || !isset( $blacklist_plugins[$plugin] ) ) continue; + unset( $plugins[$plugin] ); + } + return $plugins; +} +add_filter( 'site_option_active_sitewide_plugins', 'wpsdbc_exclude_site_plugins' ); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..451bb2f --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "name": "wp-sync-db/wp-sync-db", + "type": "wordpress-plugin", + "homepage": "https://github.com/wp-sync-db/wp-sync-db", + "license": "GPL-2.0", + "description": "WP Sync DB eliminates the manual work of migrating a WP database.", + "keywords": ["plugin","wordpress","wp-sync-db","db"], + "require": { + "composer/installers": "~1.0.6" + }, + "scripts": { + "test": "./test.sh" + } +} diff --git a/languages/wp-sync-db-en.pot b/languages/wp-sync-db-en.pot new file mode 100644 index 0000000..1fe566e --- /dev/null +++ b/languages/wp-sync-db-en.pot @@ -0,0 +1,1085 @@ +msgid "" +msgstr "" +"Project-Id-Version: WP Sync DB\n" +"POT-Creation-Date: 2014-05-28 13:07+1000\n" +"PO-Revision-Date: 2014-05-28 13:08+1000\n" +"Last-Translator: Delicious Brains \n" +"Language-Team: Delicious Brains \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.6.5\n" +"X-Poedit-Basepath: ..\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;" +"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" +"_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-SearchPath-0: .\n" + +#: class/wpsdb-addon.php:57 +#, php-format +msgid "" +"The version of %1$s you have installed, requires version %2$s of WP Sync " +"DB. You currently have %3$s installed. Update " +"Now" +msgstr "" + +#: class/wpsdb-base.php:39 +msgid "" +"Invalid content verification signature, please verify the connection " +"information on the remote site and try again." +msgstr "" + +#: class/wpsdb-base.php:154 +#, php-format +msgid "" +"The connection to the remote server has timed out, no changes have been " +"committed. (#134 - scope: %s)" +msgstr "" + +#: class/wpsdb-base.php:157 +#, php-format +msgid "We could not find: %s. Are you sure this is the correct URL?" +msgstr "" + +#: class/wpsdb-base.php:162 +msgid "" +"It appears that you might be trying to pull from a local environment. This " +"will not work if this website happens to be located on a remote " +"server, it would be impossible for this server to contact your local " +"environment." +msgstr "" + +#: class/wpsdb-base.php:165 +msgid "" +"It appears that you might be trying to push to a local environment. This " +"will not work if this website happens to be located on a remote " +"server, it would be impossible for this server to contact your local " +"environment." +msgstr "" + +#: class/wpsdb-base.php:170 +#, php-format +msgid "" +"The connection failed, an unexpected error occurred, please contact support. " +"(#121 - scope: %s)" +msgstr "" + +#: class/wpsdb-base.php:180 +msgid "" +"The remote site is protected with Basic Authentication. Please enter the " +"username and password above to continue. (401 Unauthorized)" +msgstr "" + +#: class/wpsdb-base.php:185 +#, php-format +msgid "" +"Unable to connect to the remote server, please check the connection details " +"- %1$s %2$s (#129 - scope: %3$s)" +msgstr "" + +#: class/wpsdb-base.php:194 +msgid "" +"There was a problem with the AJAX request, we were expecting a serialized " +"response, instead we received:
    " +msgstr "" + +#: class/wpsdb-base.php:202 +#, php-format +msgid "" +"WP Sync DB does not seem to be installed or active on the remote " +"site. (#131 - scope: %s)" +msgstr "" + +#: class/wpsdb-base.php:359 +#, php-format +msgid "" +"Could not connect to deliciousbrains.com — You will " +"not receive update notifications or be able to activate your license until " +"this is fixed. This issue is often caused by an improperly configured SSL " +"server (https). We recommend fixing the " +"SSL configuration on your server, but if you need a quick fix you can:" +"

    Temporarily " +"disable SSL for connections to deliciousbrains.com

    " +msgstr "" + +#: class/wpsdb-base.php:380 +msgid "Could not retrieve version details. Please try again." +msgstr "" + +#: class/wpsdb-base.php:412 +msgid "There is a new version of " +msgstr "" + +#: class/wpsdb-base.php:414 +#, php-format +msgid "View version %s details" +msgstr "" + +#: class/wpsdb-base.php:422 class/wpsdb-base.php:509 +#: class/wpsdb.php:417 class/wpsdb.php:1435 +msgid "Settings" +msgstr "" + +#: class/wpsdb-base.php:478 +msgid "My Account" +msgstr "" + +#: class/wpsdb-base.php:704 +msgid "Update Available" +msgstr "" + +#: class/wpsdb-base.php:705 +#, php-format +msgid "" +"%1$s %2$s is now available. You currently have %3$s installed. %5$s" +msgstr "" + +#: class/wpsdb-base.php:705 +msgid "Update Now" +msgstr "" + +#: class/wpsdb-base.php:763 +#, php-format +msgid "" +"An Unexpected Error Occurred — Please contact us at " +"%2$s and quote the following:" +msgstr "" + +#: class/wpsdb-base.php:787 +#, php-format +msgid "Invalid nonce for: %s" +msgstr "" + +#: class/wpsdb-base.php:794 +#, php-format +msgid "Access denied for: %s" +msgstr "" + +#: class/wpsdb.php:317 +msgid "Addons Unavailable" +msgstr "" + +#: class/wpsdb.php:330 +msgid "Installed" +msgstr "" + +#: class/wpsdb.php:332 +msgid "Activated" +msgstr "" + +#: class/wpsdb.php:336 +msgid "Activate" +msgstr "" + +#: class/wpsdb.php:341 +msgid "Install" +msgstr "" + +#: class/wpsdb.php:344 +msgid "Download" +msgstr "" + +#: class/wpsdb.php:478 +msgid "ext/mysqli" +msgstr "" + +#: class/wpsdb.php:482 +msgid "WP Memory Limit" +msgstr "" + +#: class/wpsdb.php:725 +msgid "Could not upload the SQL to the server. (#135)" +msgstr "" + +#: class/wpsdb.php:730 +msgid "Could not read the SQL file we uploaded to the server. (#136)" +msgstr "" + +#: class/wpsdb.php:746 +msgid "" +"The connection succeeded but the remote site is configured to reject push " +"connections. You can change this in the \"settings\" tab on the remote site. " +"(#133)" +msgstr "" + +#: class/wpsdb.php:963 +msgid "" +"The connection succeeded but the remote site is configured to reject pull " +"connections. You can change this in the \"settings\" tab on the remote site. " +"(#132)" +msgstr "" + +#: class/wpsdb.php:1032 class/wpsdb.php:1204 +msgid "" +"Failed attempting to unserialize the response from the remote server. Please " +"contact support." +msgstr "" + +#: class/wpsdb.php:1081 class/wpsdb.php:1252 +msgid "pull" +msgstr "" + +#: class/wpsdb.php:1084 class/wpsdb.php:1255 +msgid "push" +msgstr "" + +#: class/wpsdb.php:1086 +#, php-format +msgid "" +"The connection succeeded but the remote site is configured to reject %s " +"connections. You can change this in the \"settings\" tab on the remote site. " +"(#110)" +msgstr "" + +#: class/wpsdb.php:1175 +msgid "" +"Please activate your license before attempting a pull or push migration." +msgstr "" + +#: class/wpsdb.php:1243 +msgid "Try again?" +msgstr "" + +#: class/wpsdb.php:1257 +#, php-format +msgid "" +"The connection succeeded but the remote site is configured to reject %s " +"connections. You can change this in the \"settings\" tab on the remote site. " +"(#122) Try again?" +msgstr "" + +#: class/wpsdb.php:1435 +msgid "Migrate" +msgstr "" + +#: class/wpsdb.php:1435 +msgid "Addons" +msgstr "" + +#: class/wpsdb.php:1435 +msgid "Help" +msgstr "" + +#: class/wpsdb.php:1455 +#, php-format +msgid "" +"The version of the %1$s addon you have installed%2$s is out-of-date and will " +"not work with this version WP Sync DB. Update Now" +msgstr "" + +#: class/wpsdb.php:1464 +msgid "" +"PHP Safe Mode Enabled — We do not officially support " +"running this plugin in safe mode because set_time_limit() has " +"no effect. Therefore we can't extend the run time of the script and ensure " +"it doesn't time out before the migration completes. We haven't disabled the " +"plugin however, so you're free to cross your fingers and hope for the best. " +"However, if you have trouble, we can't help you until you turn off safe mode." +msgstr "" + +#: class/wpsdb.php:1466 class/wpsdb.php:1485 +#, php-format +msgid "Your current PHP run time limit is set to %s seconds." +msgstr "" + +#: class/wpsdb.php:1474 +#, php-format +msgid "" +"Internet Explorer Not Supported — Less than 2% of our " +"customers use IE, so we've decided not to spend time supporting it. We ask " +"that you use Firefox or a Webkit-based browser like Chrome or Safari " +"instead. If this is a problem for you, please let us know." +msgstr "" + +#: class/wpsdb.php:1483 +msgid "" +"PHP Function Disabled — The set_time_limit() function is currently disabled on your server. We use this function to " +"ensure that the migration doesn't time out. We haven't disabled the plugin " +"however, so you're free to cross your fingers and hope for the best. You may " +"want to contact your web host to enable this function." +msgstr "" + +#: class/wpsdb.php:1660 +msgid "" +"Failed to retrieve table structure, please ensure your database is online. " +"(#125)" +msgstr "" + +#: class/wpsdb.php:1677 +#, php-format +msgid "Delete any existing table %s" +msgstr "" + +#: class/wpsdb.php:1691 +#, php-format +msgid "Table structure of table %s" +msgstr "" + +#: class/wpsdb.php:1698 +msgid "" +"Failed to generate the create table query, please ensure your database is " +"online. (#126)" +msgstr "" + +#: class/wpsdb.php:1734 +#, php-format +msgid "Data contents of table %s" +msgstr "" + +#: class/wpsdb.php:2022 +#, php-format +msgid "End of data contents of table %s" +msgstr "" + +#: class/wpsdb.php:2153 +msgid "WordPress MySQL database migration" +msgstr "" + +#: class/wpsdb.php:2155 +#, php-format +msgid "Generated: %s" +msgstr "" + +#: class/wpsdb.php:2156 +#, php-format +msgid "Hostname: %s" +msgstr "" + +#: class/wpsdb.php:2157 +#, php-format +msgid "Database: %s" +msgstr "" + +#: class/wpsdb.php:2187 +msgid "Failed to write the gzipped SQL data to the file. (#127)" +msgstr "" + +#: class/wpsdb.php:2193 +msgid "Failed to write the SQL data to the file. (#128)" +msgstr "" + +#: class/wpsdb.php:2382 +msgid "" +"A problem occurred when trying to change the maximum request size, please " +"try again." +msgstr "" + +#: class/wpsdb.php:2383 class/wpsdb.php:2593 +msgid "A problem occurred when trying to check the license, please try again." +msgstr "" + +#: class/wpsdb.php:2384 +msgid "Establishing connection to remote server, please wait" +msgstr "" + +#: class/wpsdb.php:2385 +msgid "" +"A problem occurred when attempting to connect to the local server, please " +"check the details and try again." +msgstr "" + +#: class/wpsdb.php:2386 +msgid "Please enter your license key." +msgstr "" + +#: class/wpsdb.php:2387 +msgid "" +"A problem occurred when trying to register the license, please try again." +msgstr "" + +#: class/wpsdb.php:2388 +msgid "" +"Your license has been activated. You will now receive automatic updates and " +"access to email support." +msgstr "" + +#: class/wpsdb.php:2389 template/help.php:29 +msgid "Fetching license details, please wait..." +msgstr "" + +#: class/wpsdb.php:2390 +msgid "" +"An error occurred when trying to clear the debug log. Please contact " +"support. (#132)" +msgstr "" + +#: class/wpsdb.php:2391 +msgid "" +"An error occurred when trying to update the debug log. Please contact " +"support. (#133)" +msgstr "" + +#: class/wpsdb.php:2392 +msgid "Migrate DB & Save" +msgstr "" + +#: class/wpsdb.php:2393 +msgid "Migrate DB" +msgstr "" + +#: class/wpsdb.php:2394 +msgid "Please select at least one table to migrate." +msgstr "" + +#: class/wpsdb.php:2395 +msgid "Please enter a name for your migration profile." +msgstr "" + +#: class/wpsdb.php:2396 +msgid "" +"An error occurred when attempting to save the migration profile. Please see " +"the Help tab for details on how to request support. (#118)" +msgstr "" + +#: class/wpsdb.php:2397 +msgid "Exporting complete" +msgstr "" + +#: class/wpsdb.php:2398 +msgid "Exporting, please wait..." +msgstr "" + +#: class/wpsdb.php:2399 +msgid "please wait..." +msgstr "" + +#: class/wpsdb.php:2400 +msgid "complete" +msgstr "" + +#: class/wpsdb.php:2401 +msgid "Migration failed" +msgstr "" + +#: class/wpsdb.php:2402 +msgid "Backing up" +msgstr "" + +#: class/wpsdb.php:2403 +msgid "Migrating" +msgstr "" + +#: class/wpsdb.php:2404 +msgid "Status" +msgstr "" + +#: class/wpsdb.php:2405 +msgid "Response" +msgstr "" + +#: class/wpsdb.php:2406 +msgid "" +"A problem occurred when attempting to process the following table (#113)" +msgstr "" + +#: class/wpsdb.php:2407 +msgid "" +"A problem occurred when processing the following table. We were expecting a " +"response in JSON format but instead received an empty response." +msgstr "" + +#: class/wpsdb.php:2408 +msgid "Migration completed with some errors" +msgstr "" + +#: class/wpsdb.php:2409 +msgid "Migration complete, your backup is located at:" +msgstr "" + +#: class/wpsdb.php:2410 +msgid "A problem occurred when finalizing the backup. (#132)" +msgstr "" + +#: class/wpsdb.php:2411 template/settings.php:78 template/settings.php:92 +msgid "Saved" +msgstr "" + +#: class/wpsdb.php:2412 +msgid "" +"Any sites setup to use the current API key will no longer be able to " +"connect. You will need to update those sites with the newly generated API " +"key. Do you wish to continue?" +msgstr "" + +#: class/wpsdb.php:2413 +msgid "" +"An error occurred when trying to generate the API key. Please see the Help " +"tab for details on how to request support. (#105)" +msgstr "" + +#: class/wpsdb.php:2414 +msgid "" +"You are removing the following migration profile. This cannot be undone. Do " +"you wish to continue?" +msgstr "" + +#: class/wpsdb.php:2415 +msgid "" +"An error occurred when trying to delete the profile. Please see the Help tab " +"for details on how to request support. (#106)" +msgstr "" + +#: class/wpsdb.php:2416 +msgid "" +"The selected migration profile could not be deleted because it was not " +"found.\n" +"Please refresh this page to see an accurate list of the currently available " +"migration profiles." +msgstr "" + +#: class/wpsdb.php:2417 +msgid "" +"If you change the connection details, you will lose any replaces and table " +"selections you have made below. Do you wish to continue?" +msgstr "" + +#: class/wpsdb.php:2418 template/migrate.php:129 +msgid "Please enter the connection information above to continue." +msgstr "" + +#: class/wpsdb.php:2419 +msgid "" +"An error occurred when trying to save the settings. Please try again. If the " +"problem persists, please see the Help tab for details on how to request " +"support. (#108)" +msgstr "" + +#: class/wpsdb.php:2420 +msgid "" +"The connection information appears to be missing, please enter it to " +"continue." +msgstr "" + +#: class/wpsdb.php:2421 +msgid "" +"The connection information appears to be incorrect, it should consist of two " +"lines. The first being the remote server's URL and the second being the " +"secret key." +msgstr "" + +#: class/wpsdb.php:2422 +msgid "" +"The URL on the first line appears to be invalid, please check it and try " +"again." +msgstr "" + +#: class/wpsdb.php:2423 +msgid "" +"The secret key on the second line appears to be invalid. It should be a 32 " +"character string that consists of letters, numbers and special characters " +"only." +msgstr "" + +#: class/wpsdb.php:2424 +msgid "" +"It appears you've entered the URL for this website, you need to provide the " +"URL of the remote website instead." +msgstr "" + +#: class/wpsdb.php:2425 +msgid "" +"It appears you've entered the secret key for this website, you need to " +"provide the secret key for the remote website instead." +msgstr "" + +#: class/wpsdb.php:2426 template/migrate-progress.php:8 +msgid "Time Elapsed:" +msgstr "" + +#: class/wpsdb.php:2427 template/migrate-progress.php:19 +msgid "Pause" +msgstr "" + +#: class/wpsdb.php:2428 +msgid "Migration Paused" +msgstr "" + +#: class/wpsdb.php:2429 +msgid "Resume" +msgstr "" + +#: class/wpsdb.php:2430 +msgid "Completing current request" +msgstr "" + +#: class/wpsdb.php:2431 +msgid "Cancelling migration" +msgstr "" + +#: class/wpsdb.php:2432 +msgid "Paused" +msgstr "" + +#: class/wpsdb.php:2433 +msgid "Removing the local MySQL export file" +msgstr "" + +#: class/wpsdb.php:2434 +msgid "Removing the local backup MySQL export file" +msgstr "" + +#: class/wpsdb.php:2435 +msgid "Removing the local temporary tables" +msgstr "" + +#: class/wpsdb.php:2436 +msgid "Removing the remote backup MySQL export file" +msgstr "" + +#: class/wpsdb.php:2437 +msgid "Removing the remote temporary tables" +msgstr "" + +#: class/wpsdb.php:2438 +msgid "Migration cancellation failed" +msgstr "" + +#: class/wpsdb.php:2439 +msgid "" +"A problem occurred while cancelling the migration, you may have to manually " +"delete some temporary files / tables." +msgstr "" + +#: class/wpsdb.php:2440 +msgid "Migration cancelled" +msgstr "" + +#: class/wpsdb.php:2474 +msgid "Could not find the file to download:" +msgstr "" + +#: class/wpsdb.php:2652 +msgctxt "" +"\"Remove\" in this context is used to delete a license, example formatting: " +"xxxx-xxxx-xxxx Remove" +msgid "Remove" +msgstr "" + +#: class/wpsdb.php:2785 +msgid "MySQL export file not found." +msgstr "" + +#: template/addons.php:7 +msgid "Fetching addon details, please wait..." +msgstr "" + +#: template/addons.php:9 template/help.php:31 +msgid "" +"We couldn't find your license information. Please switch to the settings tab " +"and enter your license." +msgstr "" + +#: template/addons.php:10 +msgid "Once completed, you may visit this tab to view the available addons." +msgstr "" + +#: template/help.php:4 +msgid "Feature Walkthrough" +msgstr "" + +#: template/help.php:5 +msgid "" +"A brief walkthrough of the WP Sync DB plugin showing all of the different " +"options and explaining them." +msgstr "" + +#: template/help.php:8 +msgid "Pulling Live Data Into Your Local Development Environment" +msgstr "" + +#: template/help.php:9 +msgid "" +"This screencast demonstrates how you can pull data from a remote, live " +"WordPress install and update the data in your local development environment." +msgstr "" + +#: template/help.php:12 +msgid "Pushing Local Development Data to a Staging Environment" +msgstr "" + +#: template/help.php:13 +msgid "" +"This screencast demonstrates how you can push a local WordPress database " +"you've been using for development to a staging environment." +msgstr "" + +#: template/help.php:16 +msgid "Media Files Addon Demo" +msgstr "" + +#: template/help.php:17 +msgid "" +"A short demo of how the Media Files addon allows you to sync up your " +"WordPress Media Libraries." +msgstr "" + +#: template/help.php:26 +msgid "Email Support" +msgstr "" + +#: template/help.php:32 +msgid "Once completed, you may visit this tab to view your support details." +msgstr "" + +#: template/help.php:38 +msgid "Diagnostic Info & Error Log" +msgstr "" + +#: template/help.php:40 +msgid "Clear Error Log" +msgstr "" + +#: template/help.php:44 +msgid "Videos" +msgstr "" + +#: template/migrate-progress.php:4 +msgid "Please wait while migration is running..." +msgstr "" + +#: template/migrate-progress.php:7 +msgid "Establishing Connection" +msgstr "" + +#: template/migrate-progress.php:20 +msgid "Cancel" +msgstr "" + +#: template/migrate.php:61 template/migrate.php:467 +msgid "Back to select a saved profile" +msgstr "" + +#: template/migrate.php:70 +msgid "Export File" +msgstr "" + +#: template/migrate.php:76 +msgid "Save as file to your computer" +msgstr "" + +#: template/migrate.php:83 +msgid "Compress file with gzip" +msgstr "" + +#: template/migrate.php:92 +msgid "Pull" +msgstr "" + +#: template/migrate.php:92 +msgid "Replace this site's db with remote db" +msgstr "" + +#: template/migrate.php:101 +msgid "Push" +msgstr "" + +#: template/migrate.php:101 +msgid "Replace remote db with this site's db" +msgstr "" + +#: template/migrate.php:110 +msgid "Connection Info - Site URL & Secret Key" +msgstr "" + +#: template/migrate.php:120 +msgid "SSL Disabled" +msgstr "" + +#: template/migrate.php:120 +msgid "" +"We couldn't connect over SSL but regular http (no SSL) appears to be working " +"so we've switched to that. If you run a push or pull, your data will be " +"transmitted unencrypted. Most people are fine with this, but just a heads up." +msgstr "" + +#: template/migrate.php:132 +msgid "Version Mismatch" +msgstr "" + +#: template/migrate.php:132 +#, php-format +msgid "" +"We've detected you have version of WP " +"Sync DB at but are using %1$s " +"here. Please go to the Plugins page on both installs " +"and check for updates." +msgstr "" + +#: template/migrate.php:136 +msgid "Cannot Access Uploads Directory" +msgstr "" + +#: template/migrate.php:138 +msgid "" +"We require write permissions to the standard WordPress uploads directory. " +"Without this permission exports are unavailable. Please grant 755 " +"permissions on the following directory:" +msgstr "" + +#: template/migrate.php:147 +msgid "Find" +msgstr "" + +#: template/migrate.php:148 +msgid "Replace" +msgstr "" + +#: template/migrate.php:151 +msgid "" +"Doesn't look we have any replaces yet, add one?" +msgstr "" + +#: template/migrate.php:230 +#, php-format +msgid "" +"New URL Missing — Please enter the protocol-relative " +"URL of the remote website in the \"New URL\" field. If you are unsure of " +"what this URL should be, please consult our " +"documentation on find and replace fields." +msgstr "" + +#: template/migrate.php:231 +#, php-format +msgid "" +"New File Path Missing — Please enter the root file " +"path of the remote website in the \"New file path\" field. If you are unsure " +"of what the file path should be, please consult our documentation on find and replace fields." +msgstr "" + +#: template/migrate.php:248 +msgid "Migrate all tables with prefix" +msgstr "" + +#: template/migrate.php:254 +msgid "Migrate only selected tables below" +msgstr "" + +#: template/migrate.php:272 template/migrate.php:300 template/migrate.php:395 +#: template/settings.php:70 +msgid "Select All" +msgstr "" + +#: template/migrate.php:274 template/migrate.php:302 template/migrate.php:397 +#: template/settings.php:72 +msgid "Deselect All" +msgstr "" + +#: template/migrate.php:276 template/migrate.php:304 template/migrate.php:399 +#: template/settings.php:74 +msgid "Invert Selection" +msgstr "" + +#: template/migrate.php:284 +msgid "Exclude Post Types" +msgstr "" + +#: template/migrate.php:312 +msgid "Advanced Options" +msgstr "" + +#: template/migrate.php:321 +msgid "Replace GUIDs" +msgstr "" + +#: template/migrate.php:327 +#, php-format +msgid "" +"Although the WordPress Codex emphasizes " +"that GUIDs should not be changed, this is limited to sites that are already " +"live. If the site has never been live, I recommend replacing the GUIDs. For " +"example, you may be developing a new site locally at dev.somedomain.com and " +"want to migrate the site live to somedomain.com." +msgstr "" + +#: template/migrate.php:333 +msgid "Exclude spam comments" +msgstr "" + +#: template/migrate.php:339 +msgid "" +"Do not migrate the 'active_plugins' setting (i.e. which plugins are " +"activated/deactivated)" +msgstr "" + +#: template/migrate.php:356 +msgid "" +"Backup the local database before " +"replacing it" +msgstr "" + +#: template/migrate.php:357 +msgid "An SQL file will be saved to" +msgstr "" + +#: template/migrate.php:365 +msgid "Backup all tables with prefix" +msgstr "" + +#: template/migrate.php:371 +msgid "Backup only tables selected for migration" +msgstr "" + +#: template/migrate.php:377 +msgid "Backup only selected tables below" +msgstr "" + +#: template/migrate.php:402 +#, php-format +msgid "" +"The backup option has been disabled as your local uploads directory is currently not writeable. The following " +"directory should have 755 permissions: %s

    " +msgstr "" + +#: template/migrate.php:410 +msgid "Save Migration Profile" +msgstr "" + +#: template/migrate.php:410 +msgid "Save the above settings for the next time you do a similiar migration" +msgstr "" + +#: template/migrate.php:429 +msgid "Create new profile" +msgstr "" + +#: template/migrate.php:438 template/migrate.php:448 +msgid "Warning: Different Table Prefixes" +msgstr "" + +#: template/migrate.php:440 +msgid "" +"Whoa! We've detected that the database table prefix differs between " +"installations. Clicking the Migrate DB button below will create new database " +"tables in your local database with prefix \"\"." +msgstr "" + +#: template/migrate.php:442 +#, php-format +msgid "" +"However, your local install is configured to use table prefix \"%1$s\" and " +"will ignore the migrated tables. So, AFTER migration is complete, you " +"will need to edit your local install's wp-config.php and change the \"%1$s\" " +"variable to \"\"." +msgstr "" + +#: template/migrate.php:444 +msgid "" +"This will allow your local install the use the migrated tables. Once you do " +"this, you shouldn't have to do it again." +msgstr "" + +#: template/migrate.php:450 +#, php-format +msgid "" +"Whoa! We've detected that the database table prefix differs between " +"installations. Clicking the Migrate DB button below will create new database " +"tables in the remote database with prefix \"%s\"." +msgstr "" + +#: template/migrate.php:452 +#, php-format +msgid "" +"However, your remote install is configured to use table prefix \"\" and will ignore the migrated tables. So, " +"AFTER migration is complete, you will need to edit your remote " +"install's wp-config.php and change the \"\" variable to \"%s\"." +msgstr "" + +#: template/migrate.php:454 +msgid "" +"This will allow your remote install the use the migrated tables. Once you do " +"this, you shouldn't have to do it again." +msgstr "" + +#: template/profile.php:2 +msgid "Would you like to use a saved migration profile?" +msgstr "" + +#: template/profile.php:7 +msgid "Nope, let's start fresh..." +msgstr "" + +#: template/settings.php:20 +msgid "" +"Accept pull requests allow this database to be exported and downloaded" +msgstr "" + +#: template/settings.php:26 +msgid "Accept push requests allow this database to be overwritten" +msgstr "" + +#: template/settings.php:32 +msgid "Enable SSL verification" +msgstr "" + +#: template/settings.php:36 +msgid "" +"We disable SSL verification by default because a lot of people's " +"environments are not setup for it to work. For example, with XAMPP, you have " +"to manually enable OpenSSL by editing the php.ini. Without SSL verification, " +"an HTTPS connection is vulnerable to a man-in-the-middle attack, so we do " +"recommend you configure your environment and enable this." +msgstr "" + +#: template/settings.php:43 +msgid "Connection Info" +msgstr "" + +#: template/settings.php:45 +msgid "Reset API Key" +msgstr "" + +#: template/settings.php:51 +msgid "" +"Improve performance and reliability by not loading the following plugins for " +"migration requests" +msgstr "" + +#: template/settings.php:55 +msgid "" +"Some plugins add a lot of overhead to each request, requiring extra memory " +"and CPU. And some plugins even interfere with migrations and cause them to " +"fail. We recommend only loading plugins that affect migration requests, for " +"example a plugin that hooks into WP Sync DB." +msgstr "" + +#: template/settings.php:77 +msgid "Save Changes" +msgstr "" + +#: template/settings.php:85 +msgid "Maximum Request Size" +msgstr "" + +#: template/settings.php:88 +#, php-format +msgid "" +"We've detected that your server supports requests up to %s, but it's " +"possible that your server has limitations that we could not detect. To be on " +"the safe side, we set the default to 1 MB, but you can try throttling it up " +"to get better performance. If you're getting a 413 error or having trouble " +"with time outs, try throttling this setting down." +msgstr "" + +#: template/settings.php:100 +msgid "Your License" +msgstr "" + +#: template/settings.php:103 +msgid "The license key is currently defined in wp-config.php." +msgstr "" + +#: template/settings.php:111 +msgid "Activate License" +msgstr "" diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 8d78a6d..0000000 --- a/readme.txt +++ /dev/null @@ -1,80 +0,0 @@ -=== WP Migrate DB === -Contributors: bradt -Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VPMGLLK94XJC -Tags: database, migrate, backup, mysql -Requires at least: 2.0.3 -Tested up to: 3.5 -Stable tag: 0.4.3 -License: GPLv2 - -Exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer. - -== Description == - -WP Migrate DB exports your database as a MySQL data dump (much like phpMyAdmin), does a find and replace on URLs and file paths, then allows you to save it to your computer. It is perfect for developers who develop locally and need to move their Wordpress site to a staging or production server. - -It even takes into account serialized data and updates the string length values. - -Example: s:5:"hello" becomes s:11:"hello world" - -[**Contribute on Github**](https://github.com/bradt/wp-migrate-db) - -== Installation == - -1. Use WordPress' built-in installer -2. Access the WP Migrate DB menu option under Tools - -== Screenshots == - -1. Main screen -2. Saving the exported database - -== Changelog == - -= 0.4.3 - 2012-12-18 = -* Fixed deprecated error notices when debug mode is on -* Bug fix: [Exports views as tables](https://github.com/bradt/wp-migrate-db/issues/3) -* Compatibility tested with WordPress 3.5 - -= 0.4.2 - 2012-09-13 = -* Moved screenshots to /assets folder and updated them to support retina -* Added sidebar including author profile and survey to gauge interest for a pro version - -= 0.4.1 - 2012-08-15 = -* Removed WP App Store installer - not allowed in WP.org repo - -= 0.4 - 2012-08-07 = -* New: More than 4x faster than version 0.3 due to find & replace improvements -* New: Option to turn off replacing GUIDs -* New: Option to exclude spam comments and post revisions from the export -* New: Option to save file with gzip compression -* New: Added date and time to file names -* New: Display path to SQL file on the server -* New: WP App Store installer integration -* Bug fix: Notices and warnings displayed when WP_DEBUG is on - -= 0.3 - 2011-12-16 = -* Bug fix: [Null formatting error](http://plugins.trac.wordpress.org/ticket/1430) -* Bug fix: [Deprecated capability](http://plugins.trac.wordpress.org/ticket/1431) -* Bug fix: Serialized string lengths incorrect when string contains double quotes - -= 0.2.2 - 2011-09-23 = -* Bug fix: [Breaks Export](http://wordpress.org/support/topic/plugin-wp-migrate-db-breaks-export?replies=1) - -= 0.2.1 - 2009-12-13 = -* Moved to Wordpress.org hosting - -= 0.2 - 2009-04-03 = -* Moved menu link from "Settings" to "Tools" -* The random string of characters no longer appears in the filename on save. - -= 0.1 - 2009-03-20 = -* First release - -== Upgrade Notice == - -= 0.4 = -Runs export over 4x faster and adds some nice new features often requested. Upgrade recommended. - -= 0.2.2 = -This version fixes a bug that breaks the WordPress core export feature. It is highly recommended that everyone upgrade. diff --git a/template/help.php b/template/help.php new file mode 100755 index 0000000..2fe6616 --- /dev/null +++ b/template/help.php @@ -0,0 +1,48 @@ + array( + 'title' => __( 'Feature Walkthrough', 'wp-sync-db' ), + 'desc' => __( 'A brief walkthrough of the WP Sync DB plugin showing all of the different options and explaining them.', 'wp-sync-db' ) + ), + 'IFdHIpf6jjc' => array( + 'title' => __( 'Pulling Live Data Into Your Local Development Environment', 'wp-sync-db' ), + 'desc' => __( 'This screencast demonstrates how you can pull data from a remote, live WordPress install and update the data in your local development environment.', 'wp-sync-db' ) + ), + 'FjTzNqAlQE0' => array( + 'title' => __( 'Pushing Local Development Data to a Staging Environment', 'wp-sync-db' ), + 'desc' => __( 'This screencast demonstrates how you can push a local WordPress database you\'ve been using for development to a staging environment.', 'wp-sync-db' ) + ), + '0aR8-jC2XXM' => array( + 'title' => __( 'Media Files Addon Demo', 'wp-sync-db' ), + 'desc' => __( 'A short demo of how the Media Files addon allows you to sync up your WordPress Media Libraries.', 'wp-sync-db' ) + ) +); +?> + +
    +
    +

    Support

    +

    Please report bugs or ask questions in the GitHub Issue Tracker.

    +
    +
    +

    + + +
    +
    +

    + + +
      + $video ) : ?> +
    • + +

      +

      + +

      +
    • + +
    +
    +
    diff --git a/template/migrate-progress.php b/template/migrate-progress.php new file mode 100644 index 0000000..1b3f148 --- /dev/null +++ b/template/migrate-progress.php @@ -0,0 +1,23 @@ +
    + × +
    +

    +
    +
    +
    + +
    +
    +
    +
    +
    wp_options
    +
    +
    +
    + +
    + + +
    + +
    diff --git a/template/migrate.php b/template/migrate.php new file mode 100644 index 0000000..f54a92f --- /dev/null +++ b/template/migrate.php @@ -0,0 +1,471 @@ +get_profile( $_GET['wpsdb-profile'] ); +} +else{ + $loaded_profile = $this->default_profile; +} + +$is_default_profile = isset( $loaded_profile['default_profile'] ); + +$convert_exclude_revisions = false; +$convert_post_type_selection = false; +if( ! $is_default_profile ) { + if( isset( $loaded_profile['exclude_revisions'] ) ) { + $convert_exclude_revisions = true; + } + /* We used to provide users the option of selecting which post types they'd like to migrate. + * We found that our wording for this funtionality was a little confusing so we switched it to instead read "Exclude Post Types" + * Once we made the switch we needed a way of inverting their saved post type selection to instead exclude the select post types. + * This was required to make their select compatible with the new "exclude" wording. + * This is easy enough for "push" and "export" saved profile as we know which post types exist on the local system and + * can easily invert the selection. Pull saved profiles is a little tricker. + * $this->maybe_update_profile() is used to update deprecated profile options to their new values. + * At the time of page request $this->maybe_update_profile() cannot be used to update a pull profile as we don't know which + * post types exist on the remote machine. As such we invert this selection later using the $convert_post_type_selection flag below. + */ + if ( isset( $loaded_profile['post_type_migrate_option'] ) && 'migrate_select_post_types' == $loaded_profile['post_type_migrate_option'] && 'pull' == $loaded_profile['action'] ) { + $convert_post_type_selection = true; + } + $loaded_profile = $this->maybe_update_profile( $loaded_profile, $_GET['wpsdb-profile'] ); +} + +if( false == $is_default_profile ) { + $loaded_profile = wp_parse_args( $loaded_profile, $this->default_profile ); +} +$loaded_profile = wp_parse_args( $loaded_profile, $this->checkbox_options ); +?> + + +
    + +
    + + settings['profiles'] ) > 0 ){ ?> + + + +
    + +
      +
    • + +
        +
      • + +
      • + gzip() ) : ?> +
      • + +
      • + +
      +
    • +
    • + +
        +
      • +
      +
    • +
    • + +
        +
      • +
      +
    • +
    + +
    + +
    +
    + + +
    + +
    + +
    + +
    + +
    + +

    + + + + + +
    + +
    +
    +
    +
    +
    + +

    add one?', 'wp-sync-db' ); ?>

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + +
    + + + + + + + + + +
    + + + + + + + + +
    + + + + + + + + +
    Add Row
    + +
    New URL Missing — Please enter the protocol-relative URL of the remote website in the "New URL" field. If you are unsure of what this URL should be, please consult our documentation on find and replace fields.', 'wp-sync-db' ), 'https://deliciousbrains.com/wp-sync-db/documentation/#find-and-replace' ); ?>
    +
    New File Path Missing — Please enter the root file path of the remote website in the "New file path" field. If you are unsure of what the file path should be, please consult our documentation on find and replace fields.', 'wp-sync-db' ), 'https://deliciousbrains.com/wp-sync-db/documentation/#find-and-replace' ); ?>
    + +
    + +
    + get_table_sizes(); ?> +
    + +
    Tables
    +
    + + +
    + +
    + + + +
    + +
    +
    + +
    +
    + +
    + +
      +
    • + + + + +
      + WordPress Codex emphasizes that GUIDs should not be changed, this is limited to sites that are already live. If the site has never been live, I recommend replacing the GUIDs. For example, you may be developing a new site locally at dev.somedomain.com and want to migrate the site live to somedomain.com.', 'wp-sync-db' ), 'http://codex.wordpress.org/Changing_The_Site_URL#Important_GUID_Note' ); ?> +
      +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    + +
    +
    + +
    + + +
    +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    + +
    + +
    + + / + + / + +
    +
    + ', 'wp-sync-db' ), $this->get_upload_info( 'path' ) ); ?> +
    + + + +
    + + +
    +
      + settings['profiles'] as $profile_id => $profile ){ ++$profile_id; ?> +
    • + + +
    • + +
    • + + +
    • +
    +
    +
    + +
    +

    + +

    ".', 'wp-sync-db' ); ?>

    + +

    AFTER migration is complete, you will need to edit your local install\'s wp-config.php and change the "%1$s" variable to "".', 'wp-sync-db' ), $wpdb->prefix, $wpdb->prefix ); ?>

    + +

    +
    + +
    +

    + +

    prefix ); ?>

    + +

    " and will ignore the migrated tables. So, AFTER migration is complete, you will need to edit your remote install\'s wp-config.php and change the "" variable to "%s".', 'wp-sync-db' ), $wpdb->prefix ); ?>

    + +

    +
    + +

    + + + +

    + +
    + + settings['profiles'] ) > 0 ){ ?> + + + +
    + template( 'migrate-progress' ); + ?> + +
    diff --git a/template/profile.php b/template/profile.php new file mode 100644 index 0000000..1f26fe4 --- /dev/null +++ b/template/profile.php @@ -0,0 +1,9 @@ +
    +

    +
      + settings['profiles'] as $key => $profile ) { ++$key ?> +
    • ×
    • + +
    • +
    +
    diff --git a/template/settings.php b/template/settings.php new file mode 100755 index 0000000..9d99b8c --- /dev/null +++ b/template/settings.php @@ -0,0 +1,96 @@ +
    + + settings['key'] ); + $pull_checked = ( $this->settings['allow_pull'] ? ' checked="checked"' : '' ); + $push_checked = ( $this->settings['allow_push'] ? ' checked="checked"' : '' ); + $verify_ssl_checked = ( $this->settings['verify_ssl'] ? ' checked="checked"' : '' ); + $plugin_compatibility_checked = ( isset( $GLOBALS['wpsdb_compatibility'] ) ? ' checked="checked"' : '' ); + ?> + +
    + +
    +
      +
    • + +
    • +
    • + +
    • +
    • + + +
      + +
      +
    • +
    +
    + +
    + + +
    +
    + +
    + + +
    +
    +
    + +
    + +
    + + / + + / + + +

    + + +

    +
    +
    + +
    +
    +
    + +
    + get_bottleneck( 'max' ) ) ); ?> +
    +
    +
    + +
    +
    +
    + +
    +
    diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..e717455 --- /dev/null +++ b/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +set -o pipefail + +files=(wp-sync-db.php class/*.php compatibility/*.php template/*.php); +for file in "${files[@]}" +do + php -l "$file"; +done diff --git a/wp-migrate-db.php b/wp-migrate-db.php deleted file mode 100644 index de1580d..0000000 --- a/wp-migrate-db.php +++ /dev/null @@ -1,810 +0,0 @@ -errors = array(); - $this->upload_dir = ( defined('WP_CONTENT_DIR') ) ? WP_CONTENT_DIR . '/uploads' : ABSPATH . 'wp-content' . DS . 'uploads'; - $this->upload_url = ( defined('WP_CONTENT_URL') ) ? WP_CONTENT_URL . '/uploads' : get_option('siteurl') . '/wp-content/uploads'; - - $this->datetime = date('YmdHis'); - - $this->replaced['serialized']['count'] = 0; - $this->replaced['serialized']['strings'] = ''; - $this->replaced['nonserialized']['count'] = 0; - - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); - add_action( 'wp_ajax_subscribe_submission', array( $this, 'subscribe_submission' ) ); - - $this->handle_request(); - } - - function subscribe_submission() { - $response = wp_remote_post( 'http://bradt.ca/wpmdb-subscribe.php', array( - 'timeout' => 60, - 'body' => $_POST - )); - - if ( is_wp_error( $response ) ) { - echo "Error attempting to save your submission."; - } - else { - echo $response['body']; - } - - die(); // this is required to return a proper result - } - - function handle_request() { - if ( !isset( $_GET['page'] ) || 'wp-migrate-db' != $_GET['page'] ) - return; - - if (isset($_POST['Submit'])) { - $this->options_validate(); - } - - if ( empty( $this->errors ) && isset( $_POST['savefile'] ) && $_POST['savefile'] ) { - add_action( 'admin_head-tools_page_wp-migrate-db', array( $this, 'admin_head' ) ); - } - - if ( isset( $_GET['download'] ) && $_GET['download']) { - add_action( 'admin_init', array( $this, 'download_file' ) ); - } - } - - function get_filename( $datetime, $gzip ) { - $hash = substr( sha1( DB_PASSWORD . AUTH_SALT ), -5 ); - $filename = DB_NAME . '-migrate-' . $datetime . '-' . $hash . '.sql'; - if ( $gzip ) $filename .= '.gz'; - return $filename; - } - - function get_nicename( $datetime, $gzip ) { - $name = DB_NAME . '-migrate-' . $datetime . '.sql'; - if ( $gzip ) $name .= '.gz'; - return $name; - } - - function options_validate() { - if (!isset($_POST['old_url']) || !$_POST['old_url']) { - $this->errors['old_url'] = __('Please enter the current URL.', 'wp-migrate-db'); - } - - if (!isset($_POST['new_url']) || !$_POST['new_url']) { - $this->errors['new_url'] = __('Please enter a new URL.', 'wp-migrate-db'); - } - - if (!isset($_POST['old_path']) || !$_POST['old_path']) { - $this->errors['old_path'] = __('Please enter the current file path.', 'wp-migrate-db'); - } - - if (!isset($_POST['new_path']) || !$_POST['new_path']) { - $this->errors['new_path'] = __('Please enter a new file path.', 'wp-migrate-db'); - } - } - - function show_error($key) { - if (isset($this->errors[$key])) { - echo '
    ', $this->errors[$key], ''; - } - } - - function options_page() { - ?> - -
    -

    WP Migrate DB

    - -
    - -
    - - errors)) { - $this->fp = $this->open($this->upload_dir . DS . $this->get_filename( $this->datetime, isset( $_POST['gzipfile'] ) ) ); - $this->db_backup_header(); - $this->db_backup(); - $this->close($this->fp); - } - - if (empty($this->errors)) { - ?> - -
    - - -

    - Your database (SQL) file has been successfully generated. - Your download should begin any second. -

    - -

    - Your database (SQL) file has been successfully generated and - saved to
    upload_dir . DS . $this->get_filename( $this->datetime, isset( $_POST['gzipfile'] ) ); ?>. - Click - here to download. -

    - - -
    - -

    - Non-Serialized Strings Replaced: replaced['nonserialized']['count']; ?>
    - Serialized Strings Replaced: replaced['serialized']['count']; ?>
    - -

    - errors))) { - if (!is_writable($this->upload_dir)) { - ?> - -
    -

    - The directory upload_dir; ?> needs - to be writable. -

    -
    - - errors)) { - ?> - -
    -

    - Sorry, there were errors with your form submission. - Please correct them below and try again. -

    -
    - - - -

    - WP Migrate DB exports your database as a MySQL data dump (much like phpMyAdmin), - does a find and replace on URLs and file paths, then allows you to save - it to your computer. It even takes into account serialized data and updates the - string length values. -

    -

    - Example: s:5:"hello" becomes s:11:"hello world" -

    - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - gzip() ) : ?> - - - - - - -
    - - - - show_error('old_url'); ?> -
    - - - - show_error('new_url'); ?> -
    - - - - show_error('old_path'); ?> -
    - - - - show_error('new_path'); ?> -
    Data Options - - - show more - - -
      - -
      - -
    File Options - -
      - -
    - -

    - -

    -
    - - -
    - -
    - -
    - -
    -

    Created & maintained by

    -

    Brad Touesnard

    -

    - Profile -    - Donate -

    -
    -
    - - - - -
    - WP App Store -

    - Purchase & install themes and plugins from top brands directly from your WordPress dashboard. - Check it out » -

    -
    - -
    - -
    -
    - replaced['serialized']['strings'] .= $old_line . "\n"; - $this->replaced['serialized']['strings'] .= $new_line . "\n\n"; - - $this->replaced['serialized']['count'] += $count; - } - } - } - } - } - - $subject = str_replace($search_esc, $replace_esc, $subject, $count); - - $this->replaced['nonserialized']['count'] += $count; - - return $subject; - } - - function apply_replaces( $subject, $is_serialized = false ) { - $search = array( $_POST['old_path'], $_POST['old_url'] ); - $replace = array( $_POST['new_path'], $_POST['new_url'] ); - $new = str_replace( $search, $replace, $subject, $count ); - - if ( $count ) { - if ( $is_serialized ) { - $this->replaced['serialized']['strings'] .= $subject . "\n"; - $this->replaced['serialized']['strings'] .= $new . "\n\n"; - $this->replaced['serialized']['count'] += $count; - } - else { - $this->replaced['nonserialized']['count'] += $count; - } - } - - return $new; - } - - /** - * Taken partially from phpMyAdmin and partially from - * Alain Wolf, Zurich - Switzerland - * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/ - - * Modified by Scott Merrill (http://www.skippy.net/) - * to use the WordPress $wpdb object - * @param string $table - * @param string $segment - * @return void - */ - function backup_table($table, $segment = 'none') { - global $wpdb; - - $table_structure = $wpdb->get_results("DESCRIBE $table"); - if (! $table_structure) { - $this->error(__('Error getting table details','wp-migrate-db') . ": $table"); - return false; - } - - if(($segment == 'none') || ($segment == 0)) { - // Add SQL statement to drop existing table - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('Delete any existing table %s','wp-migrate-db'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); - $this->stow("\n"); - $this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n"); - - // Table structure - // Comment in SQL-file - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('Table structure of table %s','wp-migrate-db'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); - $this->stow("\n"); - - $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N); - if (false === $create_table) { - $err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-migrate-db'), $table); - $this->error($err_msg); - $this->stow("#\n# $err_msg\n#\n"); - } - $this->stow($create_table[0][1] . ' ;'); - - if (false === $table_structure) { - $err_msg = sprintf(__('Error getting table structure of %s','wp-migrate-db'), $table); - $this->error($err_msg); - $this->stow("#\n# $err_msg\n#\n"); - } - - // Comment in SQL-file - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow('# ' . sprintf(__('Data contents of table %s','wp-migrate-db'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); - } - - if(($segment == 'none') || ($segment >= 0)) { - $defs = array(); - $ints = array(); - foreach ($table_structure as $struct) { - if ( (0 === strpos($struct->Type, 'tinyint')) || - (0 === strpos(strtolower($struct->Type), 'smallint')) || - (0 === strpos(strtolower($struct->Type), 'mediumint')) || - (0 === strpos(strtolower($struct->Type), 'int')) || - (0 === strpos(strtolower($struct->Type), 'bigint')) ) { - $defs[strtolower($struct->Field)] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; - $ints[strtolower($struct->Field)] = "1"; - } - } - - - // Batch by $row_inc - - if($segment == 'none') { - $row_start = 0; - $row_inc = ROWS_PER_SEGMENT; - } else { - $row_start = $segment * ROWS_PER_SEGMENT; - $row_inc = ROWS_PER_SEGMENT; - } - - do { - $where = ''; - if ( isset( $_POST['exclude-spam'] ) && $wpdb->comments == $table ) { - $where = ' WHERE comment_approved != "spam"'; - } elseif ( isset( $_POST['exclude-revisions'] ) && $wpdb->posts == $table ) { - $where = ' WHERE post_type != "revision"'; - } - - if ( !ini_get('safe_mode')) @set_time_limit(15*60); - $table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A); - - $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; - // \x08\\x09, not required - $search = array("\x00", "\x0a", "\x0d", "\x1a"); - $replace = array('\0', '\n', '\r', '\Z'); - if($table_data) { - foreach ($table_data as $row) { - $values = array(); - foreach ($row as $key => $value) { - if (isset( $ints[strtolower($key)] ) && $ints[strtolower($key)]) { - // make sure there are no blank spots in the insert syntax, - // yet try to avoid quotation marks around integers - $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value; - $values[] = ( '' === $value ) ? "''" : $value; - } else { - if (null === $value) { - $values[] = 'NULL'; - } - else { - if ( is_serialized( $value ) && false !== ( $data = @unserialize( $value ) ) ) { - if ( is_array( $data ) ) { - array_walk_recursive( $data, array( $this, 'replace_array_values' ) ); - } - elseif ( is_string( $data ) ) { - $data = $this->apply_replaces( $data, true ); - } - - $value = serialize( $data ); - } - // Skip replacing GUID if the option is set - elseif ( 'guid' != $key || isset( $_POST['replaceguids'] ) ) { - $value = $this->apply_replaces( $value ); - } - - $values[] = "'" . str_replace( $search, $replace, $this->sql_addslashes( $value ) ) . "'"; - } - } - } - $this->stow(" \n" . $entries . implode(', ', $values) . ') ;'); - } - $row_start += $row_inc; - } - } while((count($table_data) > 0) and ($segment=='none')); - } - - if(($segment == 'none') || ($segment < 0)) { - // Create footer/closing comment in SQL-file - $this->stow("\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('End of data contents of table %s','wp-migrate-db'),$this->backquote($table)) . "\n"); - $this->stow("# --------------------------------------------------------\n"); - $this->stow("\n"); - } - } // end backup_table() - - function replace_array_values( &$value, $key ) { - if ( !is_string( $value ) ) return; - $value = $this->apply_replaces( $value, true ); - } - - function db_backup() { - global $table_prefix, $wpdb; - - $tables = $wpdb->get_results("SHOW FULL TABLES", ARRAY_N); - - /* - if (is_writable($this->backup_dir)) { - $this->fp = $this->open($this->backup_dir . $this->backup_filename); - if(!$this->fp) { - $this->error(__('Could not open the backup file for writing!','wp-migrate-db')); - return false; - } - } else { - $this->error(__('The backup directory is not writeable!','wp-migrate-db')); - return false; - }*/ - - foreach ($tables as $table) { - if ( 'VIEW' == $table[1] ) continue; - $table = $table[0]; - // Increase script execution time-limit to 15 min for every table. - if ( !ini_get('safe_mode')) @set_time_limit(15*60); - // Create the SQL statements - $this->stow("# --------------------------------------------------------\n"); - $this->stow("# " . sprintf(__('Table: %s','wp-migrate-db'),$this->backquote($table)) . "\n"); - $this->stow("# --------------------------------------------------------\n"); - $this->backup_table($table); - } - - //$this->close($this->fp); - - if (count($this->errors)) { - return false; - } else { - //return $this->backup_filename; - return true; - } - - } //wp_db_backup - - function db_backup_header() { - $this->stow("# " . __('WordPress MySQL database migration','wp-migrate-db') . "\n", false); - $this->stow("# " . sprintf(__('From %s to %s','wp-migrate-db'), $_POST['old_url'], $_POST['new_url']) . "\n", false); - $this->stow("#\n", false); - $this->stow("# " . sprintf(__('Generated: %s','wp-migrate-db'),date("l j. F Y H:i T")) . "\n", false); - $this->stow("# " . sprintf(__('Hostname: %s','wp-migrate-db'),DB_HOST) . "\n", false); - $this->stow("# " . sprintf(__('Database: %s','wp-migrate-db'),$this->backquote(DB_NAME)) . "\n", false); - $this->stow("# --------------------------------------------------------\n\n", false); - } - - function gzip() { - return function_exists('gzopen'); - } - - function open($filename = '', $mode = 'w') { - if ('' == $filename) return false; - if ($this->gzip() && isset( $_POST['gzipfile'] )) - $fp = gzopen($filename, $mode); - else - $fp = fopen($filename, $mode); - return $fp; - } - - function close($fp) { - if ($this->gzip() && isset( $_POST['gzipfile'] )) gzclose($fp); - else fclose($fp); - } - - function stow($query_line, $replace = true) { - if ($this->gzip() && isset( $_POST['gzipfile'] )) { - if(! @gzwrite($this->fp, $query_line)) - $this->errors['file_write'] = __('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg; - } else { - if(false === @fwrite($this->fp, $query_line)) - $this->error['file_write'] = __('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg; - } - } - - /** - * Add backquotes to tables and db-names in - * SQL queries. Taken from phpMyAdmin. - */ - function backquote($a_name) { - if (!empty($a_name) && $a_name != '*') { - if (is_array($a_name)) { - $result = array(); - reset($a_name); - while(list($key, $val) = each($a_name)) - $result[$key] = '`' . $val . '`'; - return $result; - } else { - return '`' . $a_name . '`'; - } - } else { - return $a_name; - } - } - - /** - * Better addslashes for SQL queries. - * Taken from phpMyAdmin. - */ - function sql_addslashes($a_string = '', $is_like = false) { - if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string); - else $a_string = str_replace('\\', '\\\\', $a_string); - return str_replace('\'', '\\\'', $a_string); - } - - function download_file() { - set_time_limit(0); - $datetime = preg_replace( '@[^0-9]@', '', $_GET['download'] ); - $diskfile = $this->upload_dir . DS . $this->get_filename( $datetime, isset( $_GET['gz'] ) ); - if (file_exists($diskfile)) { - header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Length: ' . filesize($diskfile)); - header('Content-Disposition: attachment; filename=' . $this->get_nicename( $datetime, isset( $_GET['gz'] ) ) ); - $success = readfile($diskfile); - unlink($diskfile); - exit; - } - else { - wp_die("Could not find the file to download:
    $diskfile."); - } - } - - function admin_menu() { - if (function_exists('add_management_page')) { - add_management_page('WP Migrate DB','WP Migrate DB','update_core','wp-migrate-db',array($this, 'options_page')); - } - - $src = plugins_url( 'asset/css/styles.css', __FILE__ ); - wp_enqueue_style( 'wp-migrate-db-styles', $src ); - $src = plugins_url( 'asset/js/script.js', __FILE__ ); - wp_enqueue_script( 'wp-migrate-db-script', $src, array( 'jquery' ), false, true ); - } - - function admin_head() { - $url = admin_url('tools.php?page=wp-migrate-db&download=' . urlencode( $this->datetime ) ); - if ( isset( $_POST['gzipfile'] ) ) $url .= '&gz=1'; - ?> - -