public static function deleteByLexemId($lexemId) { $ldms = LexemDefinitionMap::get_all_by_lexemId($lexemId); foreach ($ldms as $ldm) { Definition::updateModDate($ldm->definitionId); $ldm->delete(); } }
public function cloneLexem() { $clone = $this->parisClone(); $clone->description = $this->description ? "CLONĂ {$this->description}" : "CLONĂ"; $clone->verifSp = false; $clone->structStatus = self::STRUCT_STATUS_NEW; $lm = Model::factory('LexemModel')->create(); $lm->displayOrder = 1; $lm->modelType = 'T'; $lm->modelNumber = '1'; $lm->restriction = ''; $lm->tags = ''; $lm->isLoc = false; $lm->setLexem($clone); $clone->setLexemModels(array($lm)); $clone->deepSave(); // Clone the definition list $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id); foreach ($ldms as $ldm) { LexemDefinitionMap::associate($clone->id, $ldm->definitionId); } // Clone the root meanings $meanings = Model::factory('Meaning')->where('lexemId', $this->id)->where('parentId', 0)->find_many(); foreach ($meanings as $m) { $m->cloneMeaning($clone->id, 0); } return $clone; }
<?php /** * This script deletes spammy definitions sent in bulk **/ require_once __DIR__ . '/../phplib/util.php'; $defs = Model::factory('Definition')->where('userId', 0)->where('status', ST_PENDING)->where_like('internalRep', '%[url=%')->find_many(); foreach ($defs as $def) { print sprintf("Deleting ID = %d, rep = %s\n", $def->id, StringUtil::shortenString($def->internalRep, 100)); $defId = $def->id; $def->delete(); db_execute("delete from Typo where definitionId = {$defId}"); // TODO: This code replicates code in definitionEdit.php // If by deleting this definition, any associated lexems become unassociated, delete them $ldms = LexemDefinitionMap::get_all_by_definitionId($defId); db_execute("delete from LexemDefinitionMap where definitionId = {$defId}"); foreach ($ldms as $ldm) { $l = Lexem::get_by_id($ldm->lexemId); $otherLdms = LexemDefinitionMap::get_all_by_lexemId($l->id); if (!$l->isLoc && !count($otherLdms)) { $l->delete(); } } } print sprintf("Deleted %d definitions\n", count($defs));
function _cloneLexem($lexem) { $clone = Lexem::create($lexem->form, 'T', 1, ''); $clone->comment = $lexem->comment; $clone->description = $lexem->description ? "CLONĂ {$lexem->description}" : "CLONĂ"; $clone->noAccent = $lexem->noAccent; $clone->save(); // Clone the definition list $ldms = LexemDefinitionMap::get_all_by_lexemId($lexem->id); foreach ($ldms as $ldm) { LexemDefinitionMap::associate($clone->id, $ldm->definitionId); } $clone->regenerateParadigm(); return $clone; }
/** * Delete lexems that do not have their own definitions. * Arguments for participles: 'A', ($adjectiveModel). * Arguments for long infinitives: 'F', ('107', '113'). */ private function _deleteDependentModels($inflId, $modelType, $modelNumbers) { $ifs = Model::factory('InflectedForm')->where('lexemId', $this->id)->where('inflectionId', $inflId)->find_many(); $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id); $defHash = array(); foreach ($ldms as $ldm) { $defHash[$ldm->definitionId] = true; } foreach ($ifs as $if) { $lexems = Lexem::get_all_by_formNoAccent($if->formNoAccent); foreach ($lexems as $l) { if ($l->modelType == 'T' || $l->modelType == $modelType && in_array($l->modelNumber, $modelNumbers)) { $ownDefinitions = false; $ldms = LexemDefinitionMap::get_all_by_lexemId($l->id); foreach ($ldms as $ldm) { if (!array_key_exists($ldm->definitionId, $defHash)) { $ownDefinitions = true; } } if (!$ownDefinitions) { $l->delete(); } } } } }
$dryrun = false; if (isset($options['d'])) { $dryrun = true; } $allowInflected = false; if (isset($options['i'])) { $allowInflected = true; } /*** Get lexems ***/ $modlexems = Model::factory('Lexem')->raw_query("select distinct l.* from Lexem l, LexemDefinitionMap m, Definition d where l.id = m.lexemId and m.definitionId = d.id and d.sourceId = 28 and l.form like '% %'")->find_many(); /*** main loop ***/ if ($verbose) { echo "Everything OK, start processing...\n"; } foreach ($modlexems as $modlexem) { $ldms = LexemDefinitionMap::get_all_by_lexemId($modlexem->id); $names = explode(" ", str_replace(array(",", "~"), "", $modlexem->form)); if ($verbose) { echo sprintf("Found %d definitions corresponding to this lexem ({$modlexem->form})\n", count($ldms)); } if ($verbose) { echo "Deleting {$modlexem->form}...\n"; } if (!$dryrun) { $modlexem->delete(); } foreach ($names as $name) { // dacă nu începe cu literă mare sau nu se termină cu punct sau paranteză închisă { if (preg_match("/^[A-Z]/", $name) or preg_match("/[\\.\\)]\$/", $name)) { continue; }