diff --git a/src/cli/yggo.php b/src/cli/yggo.php index 792e07f..23928cb 100644 --- a/src/cli/yggo.php +++ b/src/cli/yggo.php @@ -582,6 +582,61 @@ if (!empty($argv[1])) { exit; } + break; + case 'delete': + + // Validate hostId + if (empty($argv[3])) { + + CLI::danger(_('hostId required')); + exit; + } + + if (!$db->getHost($argv[3])) { + + CLI::danger(_('hostId not found')); + exit; + } + + // Validate selector source + if (empty($argv[4])) { + + CLI::danger(_('CSS selector required')); + exit; + } + + // Init variables + $hostPagesProcessedTotal = 0; + $hostPageDomDeletedTotal = 0; + + try { + + $db->beginTransaction(); + + // Begin selectors values processing by hostId + foreach ($db->getHostPages($argv[3]) as $hostPage) { + + $hostPagesProcessedTotal++; + + $hostPageDomDeletedTotal += $db->deleteHostPageDomBySelector($hostPage->hostPageId, $argv[4]); + } + + $db->commit(); + + CLI::success(sprintf(_('Host pages processed: %s'), $hostPagesProcessedTotal)); + CLI::success(sprintf(_('Host page DOM elements deleted: %s'), $hostPageDomDeletedTotal)); + + exit; + + } catch(Exception $e) { + + $db->rollBack(); + + var_dump($e); + + exit; + } + break; case 'truncate': @@ -635,6 +690,7 @@ CLI::default(' reindex - search for host pages without s CLI::break(); CLI::default(' hostPageDom '); CLI::default(' parse [hostId] [selector source] [selector target] - parse new hostPageDom.selector target based on hostPageDom.selector source'); +CLI::default(' delete [hostId] [selector] - delete DOM records from hostPageDom table by hostId and selector name'); CLI::default(' truncate - flush hostPageDom table'); CLI::break(); diff --git a/src/library/mysql.php b/src/library/mysql.php index 2ac2654..e2d26ea 100644 --- a/src/library/mysql.php +++ b/src/library/mysql.php @@ -629,13 +629,13 @@ class MySQL { $query->execute([$hostPageId, $timeAdded, $selector, $value]); } - public function deleteHostPageDoms(int $hostPageId) { + public function deleteHostPageDomBySelector(int $hostPageId, string $selector) { $this->_debug->query->delete->total++; - $query = $this->_db->prepare('DELETE FROM `hostPageDom` WHERE `hostPageId` = ?'); + $query = $this->_db->prepare('DELETE FROM `hostPageDom` WHERE `hostPageId` = ? AND `selector` = ?'); - $query->execute([$hostPageId]); + $query->execute([$hostPageId, $selector]); return $query->rowCount(); }