mirror of
https://github.com/YGGverse/YGGo.git
synced 2025-09-11 13:51:49 +00:00
implement hostPageDom delete action
This commit is contained in:
parent
0f127ddb91
commit
3a9d78b7c4
@ -582,6 +582,61 @@ if (!empty($argv[1])) {
|
|||||||
exit;
|
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;
|
break;
|
||||||
case 'truncate':
|
case 'truncate':
|
||||||
|
|
||||||
@ -635,6 +690,7 @@ CLI::default(' reindex - search for host pages without s
|
|||||||
CLI::break();
|
CLI::break();
|
||||||
CLI::default(' hostPageDom ');
|
CLI::default(' hostPageDom ');
|
||||||
CLI::default(' parse [hostId] [selector source] [selector target] - parse new hostPageDom.selector target based on hostPageDom.selector source');
|
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::default(' truncate - flush hostPageDom table');
|
||||||
|
|
||||||
CLI::break();
|
CLI::break();
|
||||||
|
@ -629,13 +629,13 @@ class MySQL {
|
|||||||
$query->execute([$hostPageId, $timeAdded, $selector, $value]);
|
$query->execute([$hostPageId, $timeAdded, $selector, $value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteHostPageDoms(int $hostPageId) {
|
public function deleteHostPageDomBySelector(int $hostPageId, string $selector) {
|
||||||
|
|
||||||
$this->_debug->query->delete->total++;
|
$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();
|
return $query->rowCount();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user