XOOPS  2.6.0
Sync.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Core\Kernel\Model;
13 
15 
41 class Sync extends XoopsModelAbstract
42 {
52  public function cleanOrphan($table_link = '', $field_link = '', $field_object = '')
53  {
54  if (!empty($table_link)) {
55  $this->handler->table_link = $table_link;
56  }
57  if (!empty($field_link)) {
58  $this->handler->field_link = $field_link;
59  }
60  if (!empty($field_object)) {
61  $this->handler->field_object = $field_object;
62  }
63 
64  if (empty($this->handler->field_object)
65  || empty($this->handler->table_link)
66  || empty($this->handler->field_link)
67  ) {
68  trigger_error(
69  "The link information is not set for '" . get_class($this->handler) . "' yet.",
70  E_USER_WARNING
71  );
72  return false;
73  }
74 
75  // there were two versions of this sql, first for mysql 4.1+ and
76  // the second for earlier versions.
77  // TODO: Need to analyse and find the most portable query to use here
78  /*
79  $sql = "DELETE FROM `{$this->handler->table}`"
80  . " WHERE (`{$this->handler->field_object}` NOT IN "
81  . "( SELECT DISTINCT `{$this->handler->field_link}` FROM `{$this->handler->table_link}`) )";
82  */
83  $sql = "DELETE `{$this->handler->table}` FROM `{$this->handler->table}`"
84  . " LEFT JOIN `{$this->handler->table_link}` AS aa "
85  . " ON `{$this->handler->table}`.`{$this->handler->field_object}` = aa.`{$this->handler->field_link}`"
86  . " WHERE (aa.`{$this->handler->field_link}` IS NULL)";
87 
88  return $this->handler->db2->executeUpdate($sql);
89  }
90 }
cleanOrphan($table_link= '', $field_link= '', $field_object= '')
Definition: Sync.php:52
$sql
Definition: pda.php:32