Browse Source

implement hostPageDom delete action

main
ghost 1 year ago
parent
commit
3a9d78b7c4
  1. 56
      src/cli/yggo.php
  2. 6
      src/library/mysql.php

56
src/cli/yggo.php

@ -582,6 +582,61 @@ if (!empty($argv[1])) { @@ -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 @@ -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();

6
src/library/mysql.php

@ -629,13 +629,13 @@ class MySQL { @@ -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();
}

Loading…
Cancel
Save