本文整理汇总了PHP中DUP_Util类的典型用法代码示例。如果您正苦于以下问题:PHP DUP_Util类的具体用法?PHP DUP_Util怎么用?PHP DUP_Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DUP_Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFromTemplate
/**
* createFromTemplate
* Generates the final installer file from the template file
*/
private function createFromTemplate($template)
{
global $wpdb;
DUP_Log::Info("INSTALLER FILE: Preping for use");
$installer = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH_TMP) . "/{$this->Package->NameHash}_installer.php";
//$tablePrefix = (is_multisite()) ? $wpdb->get_blog_prefix() : $wpdb->prefix;
//Option values to delete at install time
$deleteOpts = $GLOBALS['DUPLICATOR_OPTS_DELETE'];
$replace_items = array("fwrite_url_old" => get_option('siteurl'), "fwrite_package_name" => "{$this->Package->NameHash}_archive.zip", "fwrite_package_notes" => $this->Package->Notes, "fwrite_secure_name" => $this->Package->NameHash, "fwrite_url_new" => $this->Package->Installer->OptsURLNew, "fwrite_dbhost" => $this->Package->Installer->OptsDBHost, "fwrite_dbname" => $this->Package->Installer->OptsDBName, "fwrite_dbuser" => $this->Package->Installer->OptsDBUser, "fwrite_dbpass" => '', "fwrite_ssl_admin" => $this->Package->Installer->OptsSSLAdmin, "fwrite_ssl_login" => $this->Package->Installer->OptsSSLLogin, "fwrite_cache_wp" => $this->Package->Installer->OptsCacheWP, "fwrite_cache_path" => $this->Package->Installer->OptsCachePath, "fwrite_wp_tableprefix" => $wpdb->prefix, "fwrite_opts_delete" => json_encode($deleteOpts), "fwrite_blogname" => esc_html(get_option('blogname')), "fwrite_wproot" => DUPLICATOR_WPROOTPATH, "fwrite_duplicator_version" => DUPLICATOR_VERSION);
if (file_exists($template) && is_readable($template)) {
$err_msg = "ERROR: Unable to read/write installer. \nERROR INFO: Check permission/owner on file and parent folder.\nInstaller File = <{$installer}>";
$install_str = $this->parseTemplate($template, $replace_items);
empty($install_str) ? DUP_Log::Error("{$err_msg}", "DUP_Installer::createFromTemplate => file-empty-read") : DUP_Log::Info("INSTALLER FILE: Template parsed with new data");
//INSTALLER FILE
$fp = !file_exists($installer) ? fopen($installer, 'x+') : fopen($installer, 'w');
if (!$fp || !fwrite($fp, $install_str, strlen($install_str))) {
DUP_Log::Error("{$err_msg}", "DUP_Installer::createFromTemplate => file-write-error");
}
@fclose($fp);
} else {
DUP_Log::Error("Installer Template missing or unreadable.", "Template [{$template}]");
}
@unlink($template);
DUP_Log::Info("INSTALLER FILE: Complete [{$installer}]");
}
示例2: duplicator_activate
function duplicator_activate()
{
global $wpdb;
$table_name = $wpdb->prefix . "duplicator_packages";
//PRIMARY KEY must have 2 spaces before for dbDelta to work
$sql = "CREATE TABLE `{$table_name}` (\r\n\t\t\t`id`\t\tBIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\r\n\t\t\t`name`\t\tVARCHAR(250)\tNOT NULL,\r\n\t\t\t`hash`\t\tVARCHAR(50)\t\tNOT NULL,\r\n\t\t\t`status`\tINT(11)\t\t\tNOT NULL,\r\n\t\t\t`created`\tDATETIME\t\tNOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t\t`owner`\t\tVARCHAR(60)\t\tNOT NULL,\r\n\t\t\t`package`\tMEDIUMBLOB\t\tNOT NULL )";
require_once DUPLICATOR_WPROOTPATH . 'wp-admin/includes/upgrade.php';
@dbDelta($sql);
//WordPress Options Hooks
update_option('duplicator_version_plugin', DUPLICATOR_VERSION);
//Setup All Directories
DUP_Util::InitSnapshotDirectory();
}
示例3: SaveViewStateByPost
/**
* Saves the state of a UI element via post params
* @return json result string
* <code>
* //JavaScript Ajax Request
* Duplicator.UI.SaveViewStateByPost('dup-pack-archive-panel', 1);
*
* //Call PHP Code
* $view_state = DUP_UI::GetViewStateValue('dup-pack-archive-panel');
* $ui_css_archive = ($view_state == 1) ? 'display:block' : 'display:none';
* </code>
*/
public static function SaveViewStateByPost()
{
DUP_Util::CheckPermissions('read');
$post = stripslashes_deep($_POST);
$key = esc_html($post['key']);
$value = esc_html($post['value']);
$success = self::SaveViewState($key, $value);
//Show Results as JSON
$json = array();
$json['key'] = $key;
$json['value'] = $value;
$json['update-success'] = $success;
die(json_encode($json));
}
示例4: duplicator_activate
function duplicator_activate()
{
global $wpdb;
//Only update database on version update
if (DUPLICATOR_VERSION != get_option("duplicator_version_plugin")) {
$table_name = $wpdb->prefix . "duplicator_packages";
//PRIMARY KEY must have 2 spaces before for dbDelta to work
//see: https://codex.wordpress.org/Creating_Tables_with_Plugins
$sql = "CREATE TABLE `{$table_name}` (\n\t\t\t id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t name VARCHAR(250) NOT NULL,\n\t\t\t hash VARCHAR(50) NOT NULL,\n\t\t\t status INT(11) NOT NULL,\n\t\t\t created DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\t owner VARCHAR(60) NOT NULL,\n\t\t\t package MEDIUMBLOB NOT NULL,\n\t\t\t PRIMARY KEY (id),\n\t\t\t KEY hash (hash))";
require_once DUPLICATOR_WPROOTPATH . 'wp-admin/includes/upgrade.php';
@dbDelta($sql);
}
//WordPress Options Hooks
update_option('duplicator_version_plugin', DUPLICATOR_VERSION);
//Setup All Directories
DUP_Util::InitSnapshotDirectory();
}
示例5: GetChecks
/**
* Gets the system checks which are not required
* @return array An array of system checks
*/
public static function GetChecks()
{
$checks = array();
//CHK-SRV-100: PHP SETTINGS
$php_test1 = ini_get("open_basedir");
$php_test1 = empty($php_test1) ? true : false;
$php_test2 = ini_get("max_execution_time");
$php_test2 = $php_test2 > DUPLICATOR_SCAN_TIMEOUT || strcmp($php_test2, 'Off') == 0 || $php_test2 == 0 ? 'Good' : 'Warn';
$checks['CHK-SRV-100'] = $php_test1 && $php_test2 ? 'Good' : 'Warn';
//CHK-SRV-101: WORDPRESS SETTINGS
//Version
global $wp_version;
$version_test = version_compare($wp_version, DUPLICATOR_SCAN_MIN_WP) >= 0 ? true : false;
//Cache
$Package = DUP_Package::GetActive();
$cache_path = DUP_Util::SafePath(WP_CONTENT_DIR) . '/cache';
$dirEmpty = DUP_Util::IsDirectoryEmpty($cache_path);
$dirSize = DUP_Util::GetDirectorySize($cache_path);
$cach_filtered = in_array($cache_path, explode(';', $Package->Archive->FilterDirs));
$cache_test = $cach_filtered || $dirEmpty || $dirSize < DUPLICATOR_SCAN_CACHESIZE ? true : false;
//Core Files
$files = array();
$files['wp-config.php'] = file_exists(DUP_Util::SafePath(DUPLICATOR_WPROOTPATH . '/wp-config.php'));
$files_test = $files['wp-config.php'];
$checks['CHK-SRV-101'] = $files_test && $cache_test && $version_test ? 'Good' : 'Warn';
//CHK-SRV-102: WEB SERVER
$servers = $GLOBALS['DUPLICATOR_SERVER_LIST'];
$test = false;
foreach ($servers as $value) {
if (stristr($_SERVER['SERVER_SOFTWARE'], $value)) {
$test = true;
break;
}
}
$checks['CHK-SRV-102'] = $test ? 'Good' : 'Warn';
//RESULTS
$result = in_array('Warn', $checks);
$checks['Success'] = !$result;
return $checks;
}
示例6: switch
<?php
require_once DUPLICATOR_PLUGIN_PATH . 'classes/package.php';
global $wpdb;
//POST BACK
$action_updated = null;
if (isset($_POST['action'])) {
$action_result = DUP_Settings::DeleteWPOption($_POST['action']);
switch ($_POST['action']) {
case 'duplicator_package_active':
$action_response = __('Package settings have been reset.', 'duplicator');
break;
}
}
DUP_Util::InitSnapshotDirectory();
$Package = DUP_Package::GetActive();
$package_hash = $Package->MakeHash();
$dup_tests = array();
$dup_tests = DUP_Server::GetRequirements();
$default_name = DUP_Package::GetDefaultName();
$view_state = DUP_UI::GetViewStateArray();
$ui_css_storage = isset($view_state['dup-pack-storage-panel']) && $view_state['dup-pack-storage-panel'] ? 'display:block' : 'display:none';
$ui_css_archive = isset($view_state['dup-pack-archive-panel']) && $view_state['dup-pack-archive-panel'] ? 'display:block' : 'display:none';
$ui_css_installer = isset($view_state['dup-pack-installer-panel']) && $view_state['dup-pack-installer-panel'] ? 'display:block' : 'display:none';
$dup_intaller_files = implode(", ", array_keys(DUP_Server::GetInstallerFiles()));
$dbbuild_mode = DUP_Settings::Get('package_mysqldump') && DUP_Database::GetMySqlDumpPath() ? 'mysqldump' : 'PHP';
?>
<style>
/* -----------------------------
REQUIREMENTS*/
示例7: strlen
:</td>
<td><?php
echo strlen($package->Installer->OptsURLNew) ? $package->Installer->OptsURLNew : DUP_Util::__("- not set -");
?>
</td>
</tr>
</table>
</div>
</div>
<?php
if ($debug_on) {
?>
<div style="margin:0">
<a href="javascript:void(0)" onclick="jQuery(this).parent().find('.dup-pack-debug').toggle()">[<?php
DUP_Util::_e("View Package Object");
?>
]</a><br/>
<pre class="dup-pack-debug" style="display:none"><?php
@print_r($package);
?>
</pre>
</div>
<?php
}
?>
<script type="text/javascript">
jQuery(document).ready(function ($)
示例8: dirsToArray_New
private function dirsToArray_New($path)
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
$files = iterator_to_array($iterator);
$items = array();
foreach ($files as $file) {
if ($file->isDir()) {
$items[] = DUP_Util::SafePath($file->getRealPath());
}
}
return $items;
}
示例9: getFiles
private function getFiles()
{
foreach ($this->Dirs as $key => $val) {
$files = DUP_Util::ListFiles($val);
foreach ($files as $filePath) {
$fileName = basename($filePath);
if (!is_dir($filePath)) {
if (!in_array(@pathinfo($filePath, PATHINFO_EXTENSION), $this->FilterExtsAll)) {
//Unreadable
if (!is_readable($filePath)) {
$this->FilterInfo->Files->Unreadable[] = $filePath;
continue;
}
$fileSize = @filesize($filePath);
$fileSize = empty($fileSize) ? 0 : $fileSize;
$invalid_test = strlen($filePath) > 250 || preg_match('/(\\/|\\*|\\?|\\>|\\<|\\:|\\|\\|)/', $fileName) || trim($fileName) == "";
if ($invalid_test || preg_match('/[^\\x20-\\x7f]/', $fileName)) {
$this->FilterInfo->Files->Warning[] = DUP_Encoding::toUTF8($filePath);
} else {
$this->Size += $fileSize;
$this->Files[] = $filePath;
}
if ($fileSize > DUPLICATOR_SCAN_WARNFILESIZE) {
$this->FilterInfo->Files->Size[] = $filePath . ' [' . DUP_Util::ByteSize($fileSize) . ']';
}
}
}
}
}
}
示例10: isset
<?php
DUP_Util::CheckPermissions('manage_options');
global $wpdb;
//COMMON HEADER DISPLAY
require_once DUPLICATOR_PLUGIN_PATH . '/views/javascript.php';
require_once DUPLICATOR_PLUGIN_PATH . '/views/inc.header.php';
$current_tab = isset($_REQUEST['tab']) ? esc_html($_REQUEST['tab']) : 'general';
?>
<style>
</style>
<div class="wrap">
<?php
duplicator_header(__("Settings", 'wpduplicator'));
?>
<!--h2 class="nav-tab-wrapper">
<a href="?page=duplicator-settings&tab=general" class="nav-tab <?php
echo $current_tab == 'general' ? 'nav-tab-active' : '';
?>
"> <?php
_e('General', 'wpduplicator');
?>
</a>
</h2-->
<?php
示例11: _e
?>
</td>
</tr>
<tr valign="top">
<td><?php
_e('Free space', 'hyper-cache');
?>
</td>
<td><?php
echo $perc;
?>
% -- <?php
echo DUP_Util::ByteSize($space_free);
?>
from <?php
echo DUP_Util::ByteSize($space);
?>
<br/>
<small>
<?php
_e("Note: This value is the physical servers hard-drive allocation.", 'wpduplicator');
?>
<br/>
<?php
_e("On shared hosts check your control panel for the 'TRUE' disk space quota value.", 'wpduplicator');
?>
</small>
</td>
</tr>
</table><br/>
示例12: InitSnapshotDirectory
/**
* Creates the snapshot directory if it doesn't already exisit
*/
public static function InitSnapshotDirectory()
{
$path_wproot = DUP_Util::SafePath(DUPLICATOR_WPROOTPATH);
$path_ssdir = DUP_Util::SafePath(DUPLICATOR_SSDIR_PATH);
$path_plugin = DUP_Util::SafePath(DUPLICATOR_PLUGIN_PATH);
//--------------------------------
//CHMOD DIRECTORY ACCESS
//wordpress root directory
@chmod($path_wproot, 0755);
//snapshot directory
@mkdir($path_ssdir, 0755);
@chmod($path_ssdir, 0755);
//snapshot tmp directory
$path_ssdir_tmp = $path_ssdir . '/tmp';
@mkdir($path_ssdir_tmp, 0755);
@chmod($path_ssdir_tmp, 0755);
//plugins dir/files
@chmod($path_plugin . 'files', 0755);
//--------------------------------
//FILE CREATION
//SSDIR: Create Index File
$ssfile = @fopen($path_ssdir . '/index.php', 'w');
@fwrite($ssfile, '<?php error_reporting(0); if (stristr(php_sapi_name(), "fcgi")) { $url = "http://" . $_SERVER["HTTP_HOST"]; header("Location: {$url}/404.html");} else { header("HTTP/1.1 404 Not Found", true, 404);} exit(); ?>');
@fclose($ssfile);
//SSDIR: Create token file in snapshot
$tokenfile = @fopen($path_ssdir . '/dtoken.php', 'w');
@fwrite($tokenfile, '<?php error_reporting(0); if (stristr(php_sapi_name(), "fcgi")) { $url = "http://" . $_SERVER["HTTP_HOST"]; header("Location: {$url}/404.html");} else { header("HTTP/1.1 404 Not Found", true, 404);} exit(); ?>');
@fclose($tokenfile);
//SSDIR: Create .htaccess
$storage_htaccess_off = DUP_Settings::Get('storage_htaccess_off');
if ($storage_htaccess_off) {
@unlink($path_ssdir . '/.htaccess');
} else {
$htfile = @fopen($path_ssdir . '/.htaccess', 'w');
$htoutput = "Options -Indexes";
@fwrite($htfile, $htoutput);
@fclose($htfile);
}
//SSDIR: Robots.txt file
$robotfile = @fopen($path_ssdir . '/robots.txt', 'w');
@fwrite($robotfile, "User-agent: * \nDisallow: /" . DUPLICATOR_SSDIR_NAME . '/');
@fclose($robotfile);
//PLUG DIR: Create token file in plugin
$tokenfile2 = @fopen($path_plugin . 'installer/dtoken.php', 'w');
@fwrite($tokenfile2, '<?php @error_reporting(0); @require_once("../../../../wp-admin/admin.php"); global $wp_query; $wp_query->set_404(); header("HTTP/1.1 404 Not Found", true, 404); header("Status: 404 Not Found"); @include(get_template_directory () . "/404.php"); ?>');
@fclose($tokenfile2);
}
示例13: Create
/**
* CREATE
* Creates the zip file and adds the SQL file to the archive
*/
public static function Create(DUP_Archive $archive)
{
try {
$timerAllStart = DUP_Util::GetMicrotime();
$package_zip_flush = DUP_Settings::Get('package_zip_flush');
self::$compressDir = rtrim(DUP_Util::SafePath($archive->PackDir), '/');
self::$sqlPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->Package->Database->File}");
self::$zipPath = DUP_Util::SafePath("{$archive->Package->StorePath}/{$archive->File}");
self::$zipArchive = new ZipArchive();
self::$networkFlush = empty($package_zip_flush) ? false : $package_zip_flush;
$filterDirs = empty($archive->FilterDirs) ? 'not set' : $archive->FilterDirs;
$filterExts = empty($archive->FilterExts) ? 'not set' : $archive->FilterExts;
$filterOn = $archive->FilterOn ? 'ON' : 'OFF';
//LOAD SCAN REPORT
$json = file_get_contents(DUPLICATOR_SSDIR_PATH_TMP . "/{$archive->Package->NameHash}_scan.json");
self::$scanReport = json_decode($json);
DUP_Log::Info("\n********************************************************************************");
DUP_Log::Info("ARCHIVE (ZIP):");
DUP_Log::Info("********************************************************************************");
$isZipOpen = self::$zipArchive->open(self::$zipPath, ZIPARCHIVE::CREATE) === TRUE;
if (!$isZipOpen) {
DUP_Log::Error("Cannot open zip file with PHP ZipArchive.", "Path location [" . self::$zipPath . "]");
}
DUP_Log::Info("ARCHIVE DIR: " . self::$compressDir);
DUP_Log::Info("ARCHIVE FILE: " . basename(self::$zipPath));
DUP_Log::Info("FILTERS: *{$filterOn}*");
DUP_Log::Info("DIRS: {$filterDirs}");
DUP_Log::Info("EXTS: {$filterExts}");
DUP_Log::Info("----------------------------------------");
DUP_Log::Info("COMPRESSING");
DUP_Log::Info("SIZE:\t" . self::$scanReport->ARC->Size);
DUP_Log::Info("STATS:\tDirs " . self::$scanReport->ARC->DirCount . " | Files " . self::$scanReport->ARC->FileCount);
//ADD SQL
$isSQLInZip = self::$zipArchive->addFile(self::$sqlPath, "database.sql");
if ($isSQLInZip) {
DUP_Log::Info("SQL ADDED: " . basename(self::$sqlPath));
} else {
DUP_Log::Error("Unable to add database.sql to archive.", "SQL File Path [" . self::$sqlath . "]");
}
self::$zipArchive->close();
self::$zipArchive->open(self::$zipPath, ZipArchive::CREATE);
//ZIP DIRECTORIES
foreach (self::$scanReport->ARC->Dirs as $dir) {
if (self::$zipArchive->addEmptyDir(ltrim(str_replace(self::$compressDir, '', $dir), '/'))) {
self::$countDirs++;
} else {
//Don't warn when dirtory is the root path
if (strcmp($dir, rtrim(self::$compressDir, '/')) != 0) {
DUP_Log::Info("WARNING: Unable to zip directory: '{$dir}'" . rtrim(self::$compressDir, '/'));
}
}
}
/* ZIP FILES: Network Flush
* This allows the process to not timeout on fcgi
* setups that need a response every X seconds */
if (self::$networkFlush) {
foreach (self::$scanReport->ARC->Files as $file) {
if (self::$zipArchive->addFile($file, ltrim(str_replace(self::$compressDir, '', $file), '/'))) {
self::$limitItems++;
self::$countFiles++;
} else {
DUP_Log::Info("WARNING: Unable to zip file: {$file}");
}
//Trigger a flush to the web server after so many files have been loaded.
if (self::$limitItems > DUPLICATOR_ZIP_FLUSH_TRIGGER) {
$sumItems = self::$countDirs + self::$countFiles;
self::$zipArchive->close();
self::$zipArchive->open(self::$zipPath);
self::$limitItems = 0;
DUP_Util::FcgiFlush();
DUP_Log::Info("Items archived [{$sumItems}] flushing response.");
}
}
//Normal
} else {
foreach (self::$scanReport->ARC->Files as $file) {
if (self::$zipArchive->addFile($file, ltrim(str_replace(self::$compressDir, '', $file), '/'))) {
self::$countFiles++;
} else {
DUP_Log::Info("WARNING: Unable to zip file: {$file}");
}
}
}
DUP_Log::Info(print_r(self::$zipArchive, true));
//--------------------------------
//LOG FINAL RESULTS
DUP_Util::FcgiFlush();
$zipCloseResult = self::$zipArchive->close();
$zipCloseResult ? DUP_Log::Info("COMPRESSION RESULT: '{$zipCloseResult}'") : DUP_Log::Error("ZipArchive close failure.", "This hosted server may have a disk quota limit.\nCheck to make sure this archive file can be stored.");
$timerAllEnd = DUP_Util::GetMicrotime();
$timerAllSum = DUP_Util::ElapsedTime($timerAllEnd, $timerAllStart);
self::$zipFileSize = @filesize(self::$zipPath);
DUP_Log::Info("COMPRESSED SIZE: " . DUP_Util::ByteSize(self::$zipFileSize));
DUP_Log::Info("ARCHIVE RUNTIME: {$timerAllSum}");
DUP_Log::Info("MEMORY STACK: " . DUP_Server::GetPHPMemory());
} catch (Exception $e) {
//.........这里部分代码省略.........
示例14:
<?php
DUP_Util::CheckPermissions('read');
require_once DUPLICATOR_PLUGIN_PATH . '/assets/js/javascript.php';
require_once DUPLICATOR_PLUGIN_PATH . '/views/inc.header.php';
?>
<style>
div.dup-support-all {font-size:13px; line-height:20px}
div.dup-support-txts-links {width:100%;font-size:14px; font-weight:bold; line-height:26px; text-align:center}
div.dup-support-hlp-area {width:375px; height:160px; float:left; border:1px solid #dfdfdf; border-radius:4px; margin:10px; line-height:18px;box-shadow: 0 8px 6px -6px #ccc;}
table.dup-support-hlp-hdrs {border-collapse:collapse; width:100%; border-bottom:1px solid #dfdfdf}
table.dup-support-hlp-hdrs {background-color:#efefef;}
div.dup-support-hlp-hdrs {
font-weight:bold; font-size:17px; height: 35px; padding:5px 5px 5px 10px;
background-image:-ms-linear-gradient(top, #FFFFFF 0%, #DEDEDE 100%);
background-image:-moz-linear-gradient(top, #FFFFFF 0%, #DEDEDE 100%);
background-image:-o-linear-gradient(top, #FFFFFF 0%, #DEDEDE 100%);
background-image:-webkit-gradient(linear, left top, left bottom, color-stop(0, #FFFFFF), color-stop(1, #DEDEDE));
background-image:-webkit-linear-gradient(top, #FFFFFF 0%, #DEDEDE 100%);
background-image:linear-gradient(to bottom, #FFFFFF 0%, #DEDEDE 100%);
}
div.dup-support-hlp-hdrs div {padding:5px; margin:4px 20px 0px -20px; text-align: center;}
div.dup-support-hlp-txt{padding:10px 4px 4px 4px; text-align:center}
</style>
<div class="wrap dup-wrap dup-support-all">
<?php
duplicator_header(__("Help", 'duplicator'));
?>
示例15: phpDump
private function phpDump()
{
global $wpdb;
$wpdb->query("SET session wait_timeout = " . DUPLICATOR_DB_MAX_TIME);
$handle = fopen($this->dbStorePath, 'w+');
$tables = $wpdb->get_col('SHOW TABLES');
$filterTables = isset($this->FilterTables) ? explode(',', $this->FilterTables) : null;
$tblAllCount = count($tables);
$tblFilterOn = $this->FilterOn ? 'ON' : 'OFF';
$qryLimit = DUP_Settings::Get('package_phpdump_qrylimit');
if (is_array($filterTables) && $this->FilterOn) {
foreach ($tables as $key => $val) {
if (in_array($tables[$key], $filterTables)) {
unset($tables[$key]);
}
}
}
$tblCreateCount = count($tables);
$tblFilterCount = $tblAllCount - $tblCreateCount;
DUP_Log::Info("TABLES: total:{$tblAllCount} | filtered:{$tblFilterCount} | create:{$tblCreateCount}");
DUP_Log::Info("FILTERED: [{$this->FilterTables}]");
$sql_header = "/* DUPLICATOR MYSQL SCRIPT CREATED ON : " . @date("Y-m-d H:i:s") . " */\n\n";
$sql_header .= "SET FOREIGN_KEY_CHECKS = 0;\n\n";
fwrite($handle, $sql_header);
//BUILD CREATES:
//All creates must be created before inserts do to foreign key constraints
foreach ($tables as $table) {
//$sql_del = ($GLOBALS['duplicator_opts']['dbadd_drop']) ? "DROP TABLE IF EXISTS {$table};\n\n" : "";
//@fwrite($handle, $sql_del);
$create = $wpdb->get_row("SHOW CREATE TABLE `{$table}`", ARRAY_N);
@fwrite($handle, "{$create[1]};\n\n");
}
//BUILD INSERTS:
//Create Insert in 100 row increments to better handle memory
foreach ($tables as $table) {
$row_count = $wpdb->get_var("SELECT Count(*) FROM `{$table}`");
//DUP_Log::Info("{$table} ({$row_count})");
if ($row_count > $qryLimit) {
$row_count = ceil($row_count / $qryLimit);
} else {
if ($row_count > 0) {
$row_count = 1;
}
}
if ($row_count >= 1) {
fwrite($handle, "\n/* INSERT TABLE DATA: {$table} */\n");
}
for ($i = 0; $i < $row_count; $i++) {
$sql = "";
$limit = $i * $qryLimit;
$query = "SELECT * FROM `{$table}` LIMIT {$limit}, {$qryLimit}";
$rows = $wpdb->get_results($query, ARRAY_A);
if (is_array($rows)) {
foreach ($rows as $row) {
$sql .= "INSERT INTO `{$table}` VALUES(";
$num_values = count($row);
$num_counter = 1;
foreach ($row as $value) {
if (is_null($value) || !isset($value)) {
$num_values == $num_counter ? $sql .= 'NULL' : ($sql .= 'NULL, ');
} else {
$num_values == $num_counter ? $sql .= '"' . @esc_sql($value) . '"' : ($sql .= '"' . @esc_sql($value) . '", ');
}
$num_counter++;
}
$sql .= ");\n";
}
fwrite($handle, $sql);
}
}
//Flush buffer if enabled
if ($this->networkFlush) {
DUP_Util::FcgiFlush();
}
$sql = null;
$rows = null;
}
$sql_footer = "\nSET FOREIGN_KEY_CHECKS = 1; \n\n";
$sql_footer .= "/* Duplicator WordPress Timestamp: " . date("Y-m-d H:i:s") . "*/\n";
$sql_footer .= "/* " . DUPLICATOR_DB_EOF_MARKER . " */\n";
fwrite($handle, $sql_footer);
$wpdb->flush();
fclose($handle);
}