die('The default template id must be set. Check that $default_template_id is set and is an integer.'); } // Include the xpdo and modx classes include '../../xpdo/xpdo.class.php'; include '../../model/modx/modx.class.php'; // Instantiate a new modx object. MODx inherits from xpdo so we can use it // like an xpdo object, but it has the extra functions needed for saving content. // Thanks to Shaun McCormick for writing docs on this. $modx = new modX(); $modx->initialize('web'); // Add the Quip package $can_migrate_comments = $modx->addPackage('quip', '../../components/quip/model/', $modx->db->config['table_prefix']); // Now instantiate a new xpdo object and add our wordpress package. This gives // us the ability to make queries on the wordpress database as an xpdo object. $wp = new xPDO('mysql:host=' . $wp_database_host . ';dbname=' . $wp_database_name . ';charset=' . $wp_database_charset, $wp_database_username, $wp_database_password); $can_migrate_wp = $wp->addPackage('wordpress', '../', $wp_database_prefix); if (!$can_migrate_wp) { die('Wordpress Package could not be loaded.'); } /** * during migrations where you need to try, try and try again to get it right, * it's easier to truncate the tables here instead of doing it manually. * setting $empty_tables to true will delete data from the following tables. */ if ($empty_tables) { if ($can_migrate_comments) { $modx->db->query('TRUNCATE ' . $modx->getFullTableName('quip_comments')); $modx->db->query('TRUNCATE ' . $modx->getFullTableName('quip_comments_closure')); } $modx->db->query('TRUNCATE ' . $modx->getFullTableName('site_content')); $modx->db->query('TRUNCATE ' . $modx->getFullTableName('site_templates') . 'WHERE id != 1');
public function getXpdoInstanceAndAddPackage($scriptProperties) { $modx =& $this->modx; $prefix = isset($scriptProperties['prefix']) ? $scriptProperties['prefix'] : ''; $usecustomprefix = $modx->getOption('useCustomPrefix', $scriptProperties, ''); $usecustomprefix = empty($usecustomprefix) ? $modx->getOption('usecustomprefix', $scriptProperties, '') : $usecustomprefix; $usecustomprefix = empty($usecustomprefix) ? $modx->getOption('use_custom_prefix', $scriptProperties, '') : $usecustomprefix; if (empty($prefix)) { $prefix = !empty($usecustomprefix) ? $prefix : null; } $packageName = $modx->getOption('packageName', $scriptProperties, ''); if (!empty($packageName)) { $packagepath = $this->modx->getOption('core_path') . 'components/' . $packageName . '/'; $modelpath = $packagepath . 'model/'; $xpdo_name = $packageName . '_xpdo'; if (isset($this->modx->{$xpdo_name})) { //create xpdo-instance for that package only once $xpdo =& $this->modx->{$xpdo_name}; } elseif (file_exists($packagepath . 'config/config.inc.php')) { include $packagepath . 'config/config.inc.php'; if (is_null($prefix) && isset($table_prefix)) { $prefix = $table_prefix; } $charset = ''; if (!empty($database_connection_charset)) { $charset = ';charset=' . $database_connection_charset; } $dsn = $database_type . ':host=' . $database_server . ';dbname=' . $dbase . $charset; $xpdo = new xPDO($dsn, $database_user, $database_password); //echo $o=($xpdo->connect()) ? 'Connected' : 'Not Connected'; $this->modx->{$xpdo_name} =& $xpdo; } else { $xpdo =& $this->modx; } $xpdo->addPackage($packageName, $modelpath, $prefix); } else { $xpdo =& $this->modx; } return $xpdo; }
print_msg(sprintf('<br/><strong>Ok:</strong> Using existing XML schema file:<br/><code>%s</code>', $xml_schema_file)); } $xpdo = new xPDO("mysql:host={$database_server};dbname={$dbase}", $database_user, $database_password); $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $manager = $xpdo->getManager(); $generator = $manager->getGenerator(); // Use this to generate classes and maps from your schema if ($regenerate_classes) { print_msg('<br/>Attempting to remove/regenerate class files...'); delete_class_files($class_dir); delete_class_files($mysql_class_dir); } print "<br/>Parsing schema {$xml_schema_file} <br/>"; $generator->parseSchema($xml_schema_file, $model_dir); $generator->parseSchema($adjusted_core_path . "components/{$package_name}/model/schema/foxycart.mysql.schema.xml", $model_dir); if (!$xpdo->addPackage('survey', $adjusted_core_path . 'components/survey/model/', 'survey_')) { return 'Package Error.'; } // Clear out Tables print '<h3>Dropping Tables...</h3>'; //$xpdo->setLogLevel(xPDO::LOG_LEVEL_FATAL); // keep it quiet $manager->removeObjectContainer('Survey'); $manager->removeObjectContainer('Question'); $manager->removeObjectContainer('Response'); $manager->removeObjectContainer('Data'); print '<code>Done.</code>'; /* print '<h3>Removing Taxonomy and Term Records on modx_site_content Tables...</h3>'; //Removing Taxonomies $taxonomies = $modx->getCollection('Taxonomy',array('class_key'=>'Taxonomy')); if($taxonomies) {