wordpress_import.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. /**
  3. * WordPress Database Import Tool
  4. * Imports posts, categories, users, and comments from WordPress to the publication system
  5. */
  6. class WordPressImport {
  7. private $wpDb;
  8. private $targetDb;
  9. private $wpConfig;
  10. private $importLog = [];
  11. private $errors = [];
  12. public function __construct($wpConfig) {
  13. error_log('WordPressImport constructor called');
  14. $this->wpConfig = $wpConfig;
  15. $this->targetDb = Database::getInstance();
  16. error_log('WordPressImport constructor completed');
  17. // Don't connect in constructor - connect on demand to avoid hanging
  18. }
  19. /**
  20. * Connect to WordPress database
  21. */
  22. private function connectWordPress() {
  23. try {
  24. // Set timeout options
  25. $options = [
  26. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  27. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  28. PDO::ATTR_TIMEOUT => 10, // 10 second timeout
  29. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
  30. ];
  31. $dsn = "mysql:host={$this->wpConfig['host']};dbname={$this->wpConfig['database']};charset=utf8mb4";
  32. $this->wpDb = new PDO($dsn, $this->wpConfig['username'], $this->wpConfig['password'], $options);
  33. // Test connection with a simple query
  34. $this->wpDb->query("SELECT 1");
  35. $this->log('Connected to WordPress database successfully');
  36. } catch (PDOException $e) {
  37. throw new Exception("Failed to connect to WordPress database: " . $e->getMessage());
  38. } catch (Exception $e) {
  39. throw new Exception("WordPress database connection error: " . $e->getMessage());
  40. }
  41. }
  42. /**
  43. * Test WordPress connection and verify structure
  44. */
  45. public function testConnection() {
  46. try {
  47. // Connect first
  48. $this->connectWordPress();
  49. // Simple connection test
  50. $stmt = $this->wpDb->query("SELECT 1 as test");
  51. $test = $stmt->fetch();
  52. if (!$test || $test['test'] != 1) {
  53. throw new Exception("WordPress database connection test failed");
  54. }
  55. // Check if WordPress tables exist (simplified)
  56. $tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
  57. $existingTables = [];
  58. foreach ($tables as $table) {
  59. $stmt = $this->wpDb->query("SHOW TABLES LIKE '{$table}'");
  60. if ($stmt->rowCount() > 0) {
  61. $existingTables[] = $table;
  62. }
  63. }
  64. if (count($existingTables) < 6) {
  65. throw new Exception("WordPress database structure incomplete. Missing tables: " . implode(', ', array_diff($tables, $existingTables)));
  66. }
  67. // Get basic stats with simple queries (avoid hanging)
  68. $stats = [];
  69. try {
  70. $stats['posts'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
  71. } catch (Exception $e) {
  72. $stats['posts'] = 0;
  73. }
  74. try {
  75. $stats['categories'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
  76. } catch (Exception $e) {
  77. $stats['categories'] = 0;
  78. }
  79. try {
  80. $stats['users'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
  81. } catch (Exception $e) {
  82. $stats['users'] = 0;
  83. }
  84. try {
  85. $stats['comments'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
  86. } catch (Exception $e) {
  87. $stats['comments'] = 0;
  88. }
  89. return ['success' => true, 'stats' => $stats, 'tables' => $existingTables];
  90. } catch (Exception $e) {
  91. return ['success' => false, 'error' => $e->getMessage()];
  92. }
  93. }
  94. /**
  95. * Import all WordPress data
  96. */
  97. public function importAll($options = []) {
  98. error_log('importAll() called with options: ' . print_r($options, true));
  99. $results = [];
  100. try {
  101. // Connect to WordPress database first
  102. error_log('About to call connectWordPress()');
  103. $this->connectWordPress();
  104. error_log('connectWordPress() completed');
  105. // Start transaction
  106. error_log('About to start transaction');
  107. $this->targetDb->beginTransaction();
  108. error_log('Transaction started');
  109. // Import categories first (posts depend on them)
  110. if ($options['import_categories'] ?? true) {
  111. $results['categories'] = $this->importCategories();
  112. }
  113. // Import users
  114. if ($options['import_users'] ?? true) {
  115. $results['users'] = $this->importUsers();
  116. }
  117. // Import posts
  118. if ($options['import_posts'] ?? true) {
  119. $results['posts'] = $this->importPosts();
  120. }
  121. // Import comments
  122. if ($options['import_comments'] ?? true) {
  123. $results['comments'] = $this->importComments();
  124. }
  125. // Commit transaction
  126. $this->targetDb->commit();
  127. $this->log('Import completed successfully');
  128. return ['success' => true, 'results' => $results, 'log' => $this->importLog];
  129. } catch (Exception $e) {
  130. $this->targetDb->rollBack();
  131. $this->errors[] = $e->getMessage();
  132. $this->log('Import failed: ' . $e->getMessage(), 'error');
  133. return ['success' => false, 'error' => $e->getMessage(), 'log' => $this->importLog, 'errors' => $this->errors];
  134. }
  135. }
  136. /**
  137. * Import WordPress categories
  138. */
  139. public function importCategories() {
  140. $this->log('Starting categories import');
  141. $imported = 0;
  142. $skipped = 0;
  143. // Connect to WordPress database if not already connected
  144. if ($this->wpDb === null) {
  145. $this->connectWordPress();
  146. }
  147. // Get WordPress categories
  148. $stmt = $this->wpDb->query("
  149. SELECT t.name, tt.description, tt.term_id
  150. FROM wp_terms t
  151. JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
  152. WHERE tt.taxonomy = 'category'
  153. ORDER BY t.name
  154. ");
  155. $categories = $stmt->fetchAll();
  156. foreach ($categories as $wpCategory) {
  157. try {
  158. // Check if category already exists
  159. $existing = $this->targetDb->fetch(
  160. "SELECT id FROM categories WHERE name = ?",
  161. [$wpCategory['name']]
  162. );
  163. if ($existing) {
  164. $skipped++;
  165. $this->log("Category '{$wpCategory['name']}' already exists, skipping");
  166. continue;
  167. }
  168. // Insert new category
  169. $this->targetDb->query(
  170. "INSERT INTO categories (name, description, created_at) VALUES (?, ?, NOW())",
  171. [$wpCategory['name'], $wpCategory['description'] ?? '']
  172. );
  173. $imported++;
  174. $this->log("Imported category: {$wpCategory['name']}");
  175. } catch (Exception $e) {
  176. $this->errors[] = "Error importing category '{$wpCategory['name']}': " . $e->getMessage();
  177. $this->log("Error importing category '{$wpCategory['name']}': " . $e->getMessage(), 'error');
  178. }
  179. }
  180. $this->log("Categories import completed: {$imported} imported, {$skipped} skipped");
  181. return ['imported' => $imported, 'skipped' => $skipped];
  182. }
  183. /**
  184. * Import WordPress users
  185. */
  186. public function importUsers() {
  187. $this->log('Starting users import');
  188. $imported = 0;
  189. $skipped = 0;
  190. // Connect to WordPress database if not already connected
  191. if ($this->wpDb === null) {
  192. $this->connectWordPress();
  193. }
  194. // Get WordPress users
  195. $stmt = $this->wpDb->query("
  196. SELECT ID, user_login, user_email, user_nicename, user_registered, display_name
  197. FROM wp_users
  198. WHERE user_status = 0
  199. ORDER BY ID
  200. ");
  201. $users = $stmt->fetchAll();
  202. foreach ($users as $wpUser) {
  203. try {
  204. // Check if user already exists
  205. $existing = $this->targetDb->fetch(
  206. "SELECT id FROM users WHERE username = ?",
  207. [$wpUser['user_login']]
  208. );
  209. if ($existing) {
  210. $skipped++;
  211. $this->log("User '{$wpUser['user_login']}' already exists, skipping");
  212. continue;
  213. }
  214. // Determine user role (WordPress usermeta table)
  215. $role = $this->getUserRole($wpUser['ID']);
  216. // Insert new user
  217. $this->targetDb->query(
  218. "INSERT INTO users (username, email, role, auth_type, created_at) VALUES (?, ?, ?, 'wordpress', ?)",
  219. [
  220. $wpUser['user_login'],
  221. $wpUser['user_email'],
  222. $role,
  223. $wpUser['user_registered']
  224. ]
  225. );
  226. $imported++;
  227. $this->log("Imported user: {$wpUser['user_login']} (role: {$role})");
  228. } catch (Exception $e) {
  229. $this->errors[] = "Error importing user '{$wpUser['user_login']}': " . $e->getMessage();
  230. $this->log("Error importing user '{$wpUser['user_login']}': " . $e->getMessage(), 'error');
  231. }
  232. }
  233. $this->log("Users import completed: {$imported} imported, {$skipped} skipped");
  234. return ['imported' => $imported, 'skipped' => $skipped];
  235. }
  236. /**
  237. * Import WordPress posts
  238. */
  239. public function importPosts() {
  240. $this->log('Starting posts import');
  241. $imported = 0;
  242. $skipped = 0;
  243. try {
  244. // Connect to WordPress database if not already connected
  245. if ($this->wpDb === null) {
  246. $this->connectWordPress();
  247. }
  248. // Get WordPress posts with author info in one query
  249. $stmt = $this->wpDb->query("
  250. SELECT p.ID, p.post_title, p.post_content, p.post_excerpt, p.post_date,
  251. p.post_modified, p.post_status, p.post_author, p.post_name,
  252. u.display_name as author_name
  253. FROM wp_posts p
  254. LEFT JOIN wp_users u ON p.post_author = u.ID
  255. WHERE p.post_type = 'post' AND p.post_status IN ('publish', 'draft')
  256. ORDER BY p.post_date
  257. LIMIT 1000
  258. ");
  259. $posts = $stmt->fetchAll();
  260. $this->log("Found " . count($posts) . " WordPress posts to import");
  261. // Get all categories for all posts in one query
  262. $postIds = array_column($posts, 'ID');
  263. $categoriesMap = [];
  264. if (!empty($postIds)) {
  265. $placeholders = str_repeat('?,', count($postIds) - 1) . '?';
  266. $categoriesStmt = $this->wpDb->prepare("
  267. SELECT tr.object_id as post_id, t.name as category_name
  268. FROM wp_term_relationships tr
  269. JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
  270. JOIN wp_terms t ON tt.term_id = t.term_id
  271. WHERE tt.taxonomy = 'category' AND tr.object_id IN ($placeholders)
  272. ");
  273. $categoriesStmt->execute($postIds);
  274. foreach ($categoriesStmt->fetchAll() as $cat) {
  275. $categoriesMap[$cat['post_id']][] = $cat['category_name'];
  276. }
  277. }
  278. foreach ($posts as $index => $wpPost) {
  279. try {
  280. $this->log("Processing post {$index}: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
  281. // Generate slug from post_name or title
  282. $slug = !empty($wpPost['post_name']) ? $wpPost['post_name'] : $this->generateSlug($wpPost['post_title']);
  283. // Map WordPress status to our status
  284. $status = ($wpPost['post_status'] === 'publish') ? 'published' : 'draft';
  285. // Use author name from query or fallback
  286. $author = $wpPost['author_name'] ?: 'Unknown Author';
  287. // Get categories from preloaded map
  288. $categories = $categoriesMap[$wpPost['ID']] ?? [];
  289. // Insert post
  290. $this->targetDb->query(
  291. "INSERT INTO publications (title, slug, content, summary, author, status, created_at, updated_at, published_at, wp_post_id)
  292. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  293. [
  294. $wpPost['post_title'],
  295. $slug,
  296. $this->processContent($wpPost['post_content']),
  297. $wpPost['post_excerpt'] ?? '',
  298. $author,
  299. $status,
  300. $wpPost['post_date'],
  301. $wpPost['post_modified'],
  302. ($status === 'published') ? $wpPost['post_date'] : null,
  303. $wpPost['ID']
  304. ]
  305. );
  306. $publicationId = $this->targetDb->lastInsertId();
  307. // Link categories
  308. if (!empty($categories)) {
  309. $placeholders = str_repeat('?,', count($categories) - 1) . '?';
  310. $this->targetDb->query("
  311. INSERT INTO publication_categories (publication_id, category_id)
  312. SELECT ?, c.id FROM categories c
  313. WHERE c.name IN ($placeholders)
  314. ", array_merge([$publicationId], $categories));
  315. }
  316. $imported++;
  317. $this->log("Successfully imported post: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
  318. } catch (Exception $e) {
  319. $skipped++;
  320. $this->log("Skipped post '{$wpPost['post_title']}' (ID: {$wpPost['ID']}): " . $e->getMessage(), 'error');
  321. }
  322. }
  323. } catch (Exception $e) {
  324. $this->errors[] = "Error in posts import: " . $e->getMessage();
  325. $this->log("Error in posts import: " . $e->getMessage(), 'error');
  326. }
  327. $this->log("Posts import completed: {$imported} imported, {$skipped} skipped");
  328. return ['imported' => $imported, 'skipped' => $skipped];
  329. }
  330. /**
  331. * Import WordPress comments
  332. */
  333. public function importComments() {
  334. $this->log('Starting comments import');
  335. $imported = 0;
  336. $skipped = 0;
  337. try {
  338. // Connect to WordPress database if not already connected
  339. if ($this->wpDb === null) {
  340. $this->connectWordPress();
  341. }
  342. // Test basic WordPress comments query first
  343. $testStmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_comments");
  344. $commentCount = $testStmt->fetchColumn();
  345. $this->log("WordPress comments table has {$commentCount} total comments");
  346. // Get WordPress comments with post info in one query
  347. $stmt = $this->wpDb->query("
  348. SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_author_email,
  349. c.comment_content, c.comment_date, c.comment_approved, c.comment_parent,
  350. p.post_name, p.post_title
  351. FROM wp_comments c
  352. JOIN wp_posts p ON c.comment_post_ID = p.ID
  353. WHERE p.post_type = 'post'
  354. ORDER BY c.comment_date
  355. LIMIT 2000
  356. ");
  357. $comments = $stmt->fetchAll();
  358. $this->log("Found " . count($comments) . " WordPress comments to import");
  359. // Build a map of WordPress post IDs to publication IDs using wp_post_id field
  360. $postIds = array_unique(array_column($comments, 'comment_post_ID'));
  361. $publicationMap = [];
  362. if (!empty($postIds)) {
  363. // Test if wp_post_id column exists and has values
  364. try {
  365. $testStmt = $this->targetDb->query("SELECT wp_post_id FROM publications LIMIT 1");
  366. $this->log("wp_post_id column exists in publications table");
  367. // Check if any publications have wp_post_id values
  368. $countStmt = $this->targetDb->query("SELECT COUNT(*) FROM publications WHERE wp_post_id IS NOT NULL");
  369. $wpPostIdCount = $countStmt->fetchColumn();
  370. $this->log("Found {$wpPostIdCount} publications with wp_post_id values");
  371. if ($wpPostIdCount == 0) {
  372. $this->log("No publications have wp_post_id values - comments cannot be mapped", 'error');
  373. return ['imported' => 0, 'skipped' => count($comments)];
  374. }
  375. } catch (Exception $e) {
  376. $this->log("Error: wp_post_id column does not exist in publications table: " . $e->getMessage(), 'error');
  377. $this->log("Skipping comments import - publications table needs wp_post_id column", 'error');
  378. return ['imported' => 0, 'skipped' => count($comments)];
  379. }
  380. // Try a simpler approach - query each post ID individually
  381. $this->log("Building publication map using individual queries");
  382. foreach ($postIds as $postId) {
  383. try {
  384. $pubStmt = $this->targetDb->query("SELECT id FROM publications WHERE wp_post_id = ?", [$postId]);
  385. $pub = $pubStmt->fetch();
  386. if ($pub) {
  387. $publicationMap[$postId] = $pub['id'];
  388. $this->log("Mapped WordPress post ID {$postId} to publication ID {$pub['id']}");
  389. }
  390. } catch (Exception $e) {
  391. $this->log("Error mapping post ID {$postId}: " . $e->getMessage(), 'error');
  392. }
  393. }
  394. $this->log("Found " . count($publicationMap) . " publication mappings for comments");
  395. }
  396. foreach ($comments as $index => $wpComment) {
  397. try {
  398. $this->log("Processing comment {$index}: '{$wpComment['comment_content']}' (Post ID: {$wpComment['comment_post_ID']})");
  399. // Find corresponding publication using wp_post_id mapping
  400. $publicationId = null;
  401. $wpPostId = $wpComment['comment_post_ID'];
  402. if (isset($publicationMap[$wpPostId])) {
  403. $publicationId = $publicationMap[$wpPostId];
  404. }
  405. if (!$publicationId) {
  406. $skipped++;
  407. $this->log("Comment skipped - no matching publication found for post ID {$wpComment['comment_post_ID']}");
  408. continue;
  409. }
  410. // Map comment status
  411. $status = ($wpComment['comment_approved'] === '1') ? 'approved' : 'pending';
  412. // Handle parent comment (skip for now to avoid complexity)
  413. $parentId = null;
  414. // Insert comment
  415. $this->log("Executing INSERT for comment: '{$wpComment['comment_content']}' (Post ID: {$wpPostId})");
  416. $pdo = $this->targetDb->getConnection();
  417. $commentStmt = $pdo->prepare("
  418. INSERT INTO comments (publication_id, parent_id, name, email, content, status, created_at, admin_reply, wp_comment_id)
  419. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
  420. ");
  421. $commentStmt->execute([
  422. $publicationId,
  423. $parentId,
  424. $wpComment['comment_author'],
  425. $wpComment['comment_author_email'],
  426. $wpComment['comment_content'],
  427. $status,
  428. $wpComment['comment_date'],
  429. 0, // Use integer 0 for admin_reply instead of boolean false
  430. $wpComment['comment_ID']
  431. ]);
  432. $commentId = $this->targetDb->getConnection()->lastInsertId();
  433. $imported++;
  434. $this->log("Successfully imported comment: '{$wpComment['comment_content']}' (ID: {$wpComment['comment_ID']})");
  435. } catch (Exception $e) {
  436. $skipped++;
  437. $this->log("Skipped comment '{$wpComment['comment_content']}' (ID: {$wpComment['comment_ID']}): " . $e->getMessage(), 'error');
  438. }
  439. }
  440. } catch (Exception $e) {
  441. $this->errors[] = "Error in comments import: " . $e->getMessage();
  442. $this->log("Error in comments import: " . $e->getMessage(), 'error');
  443. }
  444. $this->log("Comments import completed: {$imported} imported, {$skipped} skipped");
  445. return ['imported' => $imported, 'skipped' => $skipped];
  446. }
  447. /**
  448. * Helper methods
  449. */
  450. private function getUserRole($userId) {
  451. $stmt = $this->wpDb->prepare("
  452. SELECT meta_value FROM wp_usermeta
  453. WHERE user_id = ? AND meta_key = 'wp_capabilities'
  454. ");
  455. $stmt->execute([$userId]);
  456. $capabilities = $stmt->fetchColumn();
  457. if ($capabilities && strpos($capabilities, 'administrator') !== false) {
  458. return 'admin';
  459. }
  460. return 'editor'; // Default role
  461. }
  462. private function getAuthorName($authorId) {
  463. $stmt = $this->wpDb->prepare("SELECT display_name FROM wp_users WHERE ID = ?");
  464. $stmt->execute([$authorId]);
  465. $name = $stmt->fetchColumn();
  466. return $name ?: 'Unknown Author';
  467. }
  468. private function getPostCategories($postId) {
  469. $stmt = $this->wpDb->prepare("
  470. SELECT t.name FROM wp_terms t
  471. JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
  472. JOIN wp_term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
  473. WHERE tr.object_id = ? AND tt.taxonomy = 'category'
  474. ");
  475. $stmt->execute([$postId]);
  476. return $stmt->fetchAll(PDO::FETCH_COLUMN);
  477. }
  478. private function getPostSlugById($postId) {
  479. $stmt = $this->wpDb->prepare("SELECT post_name FROM wp_posts WHERE ID = ?");
  480. $stmt->execute([$postId]);
  481. return $stmt->fetchColumn() ?: '';
  482. }
  483. private function getPostTitleById($postId) {
  484. $stmt = $this->wpDb->prepare("SELECT post_title FROM wp_posts WHERE ID = ?");
  485. $stmt->execute([$postId]);
  486. return $stmt->fetchColumn() ?: '';
  487. }
  488. private function linkPostCategories($publicationId, $categories) {
  489. foreach ($categories as $categoryName) {
  490. $category = $this->targetDb->fetch(
  491. "SELECT id FROM categories WHERE name = ?",
  492. [$categoryName]
  493. );
  494. if ($category) {
  495. $this->targetDb->query(
  496. "INSERT IGNORE INTO publication_categories (publication_id, category_id) VALUES (?, ?)",
  497. [$publicationId, $category['id']]
  498. );
  499. }
  500. }
  501. }
  502. private function processContent($content) {
  503. // Basic WordPress content processing
  504. // You can extend this to handle shortcodes, etc.
  505. $content = str_replace('[caption]', '', $content);
  506. $content = str_replace('[/caption]', '', $content);
  507. $content = preg_replace('/\[gallery.*?\]/', '', $content);
  508. return $content;
  509. }
  510. private function generateSlug($title) {
  511. $slug = strtolower($title);
  512. $slug = preg_replace('/[^a-z0-9]+/', '-', $slug);
  513. $slug = trim($slug, '-');
  514. return $slug;
  515. }
  516. private function log($message, $level = 'info') {
  517. $this->importLog[] = [
  518. 'timestamp' => date('Y-m-d H:i:s'),
  519. 'level' => $level,
  520. 'message' => $message
  521. ];
  522. }
  523. public function getImportLog() {
  524. return $this->importLog;
  525. }
  526. /**
  527. * Get statistics methods
  528. */
  529. public function getPostCount() {
  530. $stmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'");
  531. return $stmt->fetchColumn();
  532. }
  533. public function getPageCount() {
  534. $stmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'page'");
  535. return $stmt->fetchColumn();
  536. }
  537. public function getCategoryCount() {
  538. $stmt = $this->wpDb->query("
  539. SELECT COUNT(*) FROM wp_term_taxonomy
  540. WHERE taxonomy = 'category'
  541. ");
  542. return $stmt->fetchColumn();
  543. }
  544. public function getUserCount() {
  545. $stmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_users");
  546. return $stmt->fetchColumn();
  547. }
  548. public function getCommentCount() {
  549. $stmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_comments");
  550. return $stmt->fetchColumn();
  551. }
  552. /**
  553. * Get import log
  554. */
  555. public function getLog() {
  556. return $this->importLog;
  557. }
  558. /**
  559. * Get errors
  560. */
  561. public function getErrors() {
  562. return $this->errors;
  563. }
  564. }