cmdbobject.class.inc.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Class cmdbObject
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. /**
  25. * cmdbObjectClass
  26. * the file to include, then the core is yours
  27. *
  28. * @package iTopORM
  29. */
  30. require_once('coreexception.class.inc.php');
  31. require_once('config.class.inc.php');
  32. require_once('log.class.inc.php');
  33. require_once('kpi.class.inc.php');
  34. require_once('dict.class.inc.php');
  35. require_once('attributedef.class.inc.php');
  36. require_once('filterdef.class.inc.php');
  37. require_once('stimulus.class.inc.php');
  38. require_once('valuesetdef.class.inc.php');
  39. require_once('MyHelpers.class.inc.php');
  40. require_once('expression.class.inc.php');
  41. require_once('cmdbsource.class.inc.php');
  42. require_once('sqlquery.class.inc.php');
  43. require_once('oql/oqlquery.class.inc.php');
  44. require_once('oql/oqlexception.class.inc.php');
  45. require_once('oql/oql-parser.php');
  46. require_once('oql/oql-lexer.php');
  47. require_once('oql/oqlinterpreter.class.inc.php');
  48. require_once('dbobject.class.php');
  49. require_once('dbobjectsearch.class.php');
  50. require_once('dbobjectset.class.php');
  51. require_once('backgroundprocess.inc.php');
  52. require_once('asynctask.class.inc.php');
  53. require_once('dbproperty.class.inc.php');
  54. // db change tracking data model
  55. require_once('cmdbchange.class.inc.php');
  56. require_once('cmdbchangeop.class.inc.php');
  57. // customization data model
  58. // Romain: temporary moved into application.inc.php (see explanations there)
  59. //require_once('trigger.class.inc.php');
  60. //require_once('action.class.inc.php');
  61. // application log
  62. // Romain: temporary moved into application.inc.php (see explanations there)
  63. //require_once('event.class.inc.php');
  64. require_once('templatestring.class.inc.php');
  65. require_once('csvparser.class.inc.php');
  66. require_once('bulkchange.class.inc.php');
  67. /**
  68. * A persistent object, which changes are accurately recorded
  69. *
  70. * @package iTopORM
  71. */
  72. abstract class CMDBObject extends DBObject
  73. {
  74. protected $m_datCreated;
  75. protected $m_datUpdated;
  76. // Note: this value is static, but that could be changed because it is sometimes a real issue (see update of interfaces / connected_to
  77. protected static $m_oCurrChange = null;
  78. protected static $m_sInfo = null; // null => the information is built in a standard way
  79. protected static $m_sOrigin = null; // null => the origin is 'interactive'
  80. /**
  81. * Specify another change (this is mainly for backward compatibility)
  82. */
  83. public static function SetCurrentChange(CMDBChange $oChange)
  84. {
  85. self::$m_oCurrChange = $oChange;
  86. }
  87. //
  88. // Todo: simplify the APIs and do not pass the current change as an argument anymore
  89. // SetTrackInfo to be invoked in very few cases (UI.php, CSV import, Data synchro)
  90. // SetCurrentChange is an alternative to SetTrackInfo (csv ?)
  91. // GetCurrentChange to be called ONCE (!) by CMDBChangeOp::OnInsert ($this->Set('change', ..GetCurrentChange())
  92. // GetCurrentChange to create a default change if not already done in the current context
  93. //
  94. /**
  95. * Get a change record (create it if not existing)
  96. */
  97. public static function GetCurrentChange($bAutoCreate = true)
  98. {
  99. if ($bAutoCreate && is_null(self::$m_oCurrChange))
  100. {
  101. self::CreateChange();
  102. }
  103. return self::$m_oCurrChange;
  104. }
  105. /**
  106. * Override the additional information (defaulting to user name)
  107. * A call to this verb should replace every occurence of
  108. * $oMyChange = MetaModel::NewObject("CMDBChange");
  109. * $oMyChange->Set("date", time());
  110. * $oMyChange->Set("userinfo", 'this is done by ... for ...');
  111. * $iChangeId = $oMyChange->DBInsert();
  112. */
  113. public static function SetTrackInfo($sInfo)
  114. {
  115. self::$m_sInfo = $sInfo;
  116. }
  117. /**
  118. * Provides information about the origin of the change
  119. * @param $sOrigin String: one of: interactive, csv-interactive, csv-import.php, webservice-soap, webservice-rest, syncho-data-source, email-processing, custom-extension
  120. */
  121. public static function SetTrackOrigin($sOrigin)
  122. {
  123. self::$m_sOrigin = $sOrigin;
  124. }
  125. /**
  126. * Get the additional information (defaulting to user name)
  127. */
  128. protected static function GetTrackInfo()
  129. {
  130. if (is_null(self::$m_sInfo))
  131. {
  132. return CMDBChange::GetCurrentUserName();
  133. }
  134. else
  135. {
  136. return self::$m_sInfo;
  137. }
  138. }
  139. /**
  140. * Get the 'origin' information (defaulting to 'interactive')
  141. */
  142. protected static function GetTrackOrigin()
  143. {
  144. if (is_null(self::$m_sOrigin))
  145. {
  146. return 'interactive';
  147. }
  148. else
  149. {
  150. return self::$m_sOrigin;
  151. }
  152. }
  153. /**
  154. * Create a standard change record (done here 99% of the time, and nearly once per page)
  155. */
  156. protected static function CreateChange()
  157. {
  158. self::$m_oCurrChange = MetaModel::NewObject("CMDBChange");
  159. self::$m_oCurrChange->Set("date", time());
  160. self::$m_oCurrChange->Set("userinfo", self::GetTrackInfo());
  161. self::$m_oCurrChange->Set("origin", self::GetTrackOrigin());
  162. self::$m_oCurrChange->DBInsert();
  163. }
  164. protected function RecordObjCreation()
  165. {
  166. // Delete any existing change tracking about the current object (IDs can be reused due to InnoDb bug; see TRAC #886)
  167. //
  168. // 1 - remove the deletion record(s)
  169. // Note that objclass contain the ROOT class
  170. $oFilter = new DBObjectSearch('CMDBChangeOpDelete');
  171. $oFilter->AddCondition('objclass', MetaModel::GetRootClass(get_class($this)), '=');
  172. $oFilter->AddCondition('objkey', $this->GetKey(), '=');
  173. MetaModel::PurgeData($oFilter);
  174. // 2 - any other change tracking information left prior to 2.0.3 (when the purge of the history has been implemented in RecordObjDeletion
  175. // In that case, objclass is the final class of the object
  176. $oFilter = new DBObjectSearch('CMDBChangeOp');
  177. $oFilter->AddCondition('objclass', get_class($this), '=');
  178. $oFilter->AddCondition('objkey', $this->GetKey(), '=');
  179. MetaModel::PurgeData($oFilter);
  180. parent::RecordObjCreation();
  181. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpCreate");
  182. $oMyChangeOp->Set("objclass", get_class($this));
  183. $oMyChangeOp->Set("objkey", $this->GetKey());
  184. $iId = $oMyChangeOp->DBInsertNoReload();
  185. }
  186. protected function RecordObjDeletion($objkey)
  187. {
  188. $sRootClass = MetaModel::GetRootClass(get_class($this));
  189. // Delete any existing change tracking about the current object
  190. $oFilter = new DBObjectSearch('CMDBChangeOp');
  191. $oFilter->AddCondition('objclass', get_class($this), '=');
  192. $oFilter->AddCondition('objkey', $objkey, '=');
  193. MetaModel::PurgeData($oFilter);
  194. parent::RecordObjDeletion($objkey);
  195. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpDelete");
  196. $oMyChangeOp->Set("objclass", MetaModel::GetRootClass(get_class($this)));
  197. $oMyChangeOp->Set("objkey", $objkey);
  198. $oMyChangeOp->Set("fclass", get_class($this));
  199. $oMyChangeOp->Set("fname", substr($this->GetRawName(), 0, 255)); // Protect against very long friendly names
  200. $iId = $oMyChangeOp->DBInsertNoReload();
  201. }
  202. protected function RecordAttChanges(array $aValues, array $aOrigValues)
  203. {
  204. parent::RecordAttChanges($aValues, $aOrigValues);
  205. // $aValues is an array of $sAttCode => $value
  206. //
  207. foreach ($aValues as $sAttCode=> $value)
  208. {
  209. $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
  210. if ($oAttDef->IsExternalField()) continue;
  211. if ($oAttDef->IsLinkSet()) continue;
  212. if ($oAttDef->GetTrackingLevel() == ATTRIBUTE_TRACKING_NONE) continue;
  213. if (array_key_exists($sAttCode, $aOrigValues))
  214. {
  215. $original = $aOrigValues[$sAttCode];
  216. }
  217. else
  218. {
  219. $original = null;
  220. }
  221. if ($oAttDef instanceOf AttributeOneWayPassword)
  222. {
  223. // One Way encrypted passwords' history is stored -one way- encrypted
  224. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeOneWayPassword");
  225. $oMyChangeOp->Set("objclass", get_class($this));
  226. $oMyChangeOp->Set("objkey", $this->GetKey());
  227. $oMyChangeOp->Set("attcode", $sAttCode);
  228. if (is_null($original))
  229. {
  230. $original = '';
  231. }
  232. $oMyChangeOp->Set("prev_pwd", $original);
  233. $iId = $oMyChangeOp->DBInsertNoReload();
  234. }
  235. elseif ($oAttDef instanceOf AttributeEncryptedString)
  236. {
  237. // Encrypted string history is stored encrypted
  238. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeEncrypted");
  239. $oMyChangeOp->Set("objclass", get_class($this));
  240. $oMyChangeOp->Set("objkey", $this->GetKey());
  241. $oMyChangeOp->Set("attcode", $sAttCode);
  242. if (is_null($original))
  243. {
  244. $original = '';
  245. }
  246. $oMyChangeOp->Set("prevstring", $original);
  247. $iId = $oMyChangeOp->DBInsertNoReload();
  248. }
  249. elseif ($oAttDef instanceOf AttributeBlob)
  250. {
  251. // Data blobs
  252. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeBlob");
  253. $oMyChangeOp->Set("objclass", get_class($this));
  254. $oMyChangeOp->Set("objkey", $this->GetKey());
  255. $oMyChangeOp->Set("attcode", $sAttCode);
  256. if (is_null($original))
  257. {
  258. $original = new ormDocument();
  259. }
  260. $oMyChangeOp->Set("prevdata", $original);
  261. $iId = $oMyChangeOp->DBInsertNoReload();
  262. }
  263. elseif ($oAttDef instanceOf AttributeStopWatch)
  264. {
  265. // Stop watches - record changes for sub items only (they are visible, the rest is not visible)
  266. //
  267. if (is_null($original))
  268. {
  269. $original = new OrmStopWatch();
  270. }
  271. foreach ($oAttDef->ListSubItems() as $sSubItemAttCode => $oSubItemAttDef)
  272. {
  273. $item_value = $oSubItemAttDef->GetValue($value);
  274. $item_original = $oSubItemAttDef->GetValue($original);
  275. if ($item_value != $item_original)
  276. {
  277. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar");
  278. $oMyChangeOp->Set("objclass", get_class($this));
  279. $oMyChangeOp->Set("objkey", $this->GetKey());
  280. $oMyChangeOp->Set("attcode", $sSubItemAttCode);
  281. $oMyChangeOp->Set("oldvalue", $item_original);
  282. $oMyChangeOp->Set("newvalue", $item_value);
  283. $iId = $oMyChangeOp->DBInsertNoReload();
  284. }
  285. }
  286. }
  287. elseif ($oAttDef instanceOf AttributeCaseLog)
  288. {
  289. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeCaseLog");
  290. $oMyChangeOp->Set("objclass", get_class($this));
  291. $oMyChangeOp->Set("objkey", $this->GetKey());
  292. $oMyChangeOp->Set("attcode", $sAttCode);
  293. $oMyChangeOp->Set("lastentry", $value->GetLatestEntryIndex());
  294. $iId = $oMyChangeOp->DBInsertNoReload();
  295. }
  296. elseif ($oAttDef instanceOf AttributeLongText)
  297. {
  298. // Data blobs
  299. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeLongText");
  300. $oMyChangeOp->Set("objclass", get_class($this));
  301. $oMyChangeOp->Set("objkey", $this->GetKey());
  302. $oMyChangeOp->Set("attcode", $sAttCode);
  303. if (!is_null($original) && ($original instanceof ormCaseLog))
  304. {
  305. $original = $original->GetText();
  306. }
  307. $oMyChangeOp->Set("prevdata", $original);
  308. $iId = $oMyChangeOp->DBInsertNoReload();
  309. }
  310. elseif ($oAttDef instanceOf AttributeText)
  311. {
  312. // Data blobs
  313. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeText");
  314. $oMyChangeOp->Set("objclass", get_class($this));
  315. $oMyChangeOp->Set("objkey", $this->GetKey());
  316. $oMyChangeOp->Set("attcode", $sAttCode);
  317. if (!is_null($original) && ($original instanceof ormCaseLog))
  318. {
  319. $original = $original->GetText();
  320. }
  321. $oMyChangeOp->Set("prevdata", $original);
  322. $iId = $oMyChangeOp->DBInsertNoReload();
  323. }
  324. elseif ($oAttDef instanceOf AttributeBoolean)
  325. {
  326. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar");
  327. $oMyChangeOp->Set("objclass", get_class($this));
  328. $oMyChangeOp->Set("objkey", $this->GetKey());
  329. $oMyChangeOp->Set("attcode", $sAttCode);
  330. $oMyChangeOp->Set("oldvalue", $original ? 1 : 0);
  331. $oMyChangeOp->Set("newvalue", $value ? 1 : 0);
  332. $iId = $oMyChangeOp->DBInsertNoReload();
  333. }
  334. elseif ($oAttDef instanceOf AttributeHierarchicalKey)
  335. {
  336. // Hierarchical keys
  337. //
  338. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar");
  339. $oMyChangeOp->Set("objclass", get_class($this));
  340. $oMyChangeOp->Set("objkey", $this->GetKey());
  341. $oMyChangeOp->Set("attcode", $sAttCode);
  342. $oMyChangeOp->Set("oldvalue", $original);
  343. $oMyChangeOp->Set("newvalue", $value[$sAttCode]);
  344. $iId = $oMyChangeOp->DBInsertNoReload();
  345. }
  346. else
  347. {
  348. // Scalars
  349. //
  350. $oMyChangeOp = MetaModel::NewObject("CMDBChangeOpSetAttributeScalar");
  351. $oMyChangeOp->Set("objclass", get_class($this));
  352. $oMyChangeOp->Set("objkey", $this->GetKey());
  353. $oMyChangeOp->Set("attcode", $sAttCode);
  354. $oMyChangeOp->Set("oldvalue", $original);
  355. $oMyChangeOp->Set("newvalue", $value);
  356. $iId = $oMyChangeOp->DBInsertNoReload();
  357. }
  358. }
  359. }
  360. /**
  361. * Helper to ultimately check user rights before writing (Insert, Update or Delete)
  362. * The check should never fail, because the UI should prevent from such a usage
  363. * Anyhow, if the user has found a workaround... the security gets enforced here
  364. */
  365. protected function CheckUserRights($bSkipStrongSecurity, $iActionCode)
  366. {
  367. if (is_null($bSkipStrongSecurity))
  368. {
  369. // This is temporary
  370. // We have implemented this safety net right before releasing iTop 1.0
  371. // and we decided that it was too risky to activate it
  372. // Anyhow, users willing to have a very strong security could set
  373. // skip_strong_security = 0, in the config file
  374. $bSkipStrongSecurity = MetaModel::GetConfig()->Get('skip_strong_security');
  375. }
  376. if (!$bSkipStrongSecurity)
  377. {
  378. $sClass = get_class($this);
  379. $oSet = DBObjectSet::FromObject($this);
  380. if (!UserRights::IsActionAllowed($sClass, $iActionCode, $oSet))
  381. {
  382. // Intrusion detected
  383. throw new SecurityException('You are not allowed to modify objects of class: '.$sClass);
  384. }
  385. }
  386. }
  387. public function DBInsert()
  388. {
  389. return $this->DBInsertTracked_Internal();
  390. }
  391. public function DBInsertTracked(CMDBChange $oChange, $bSkipStrongSecurity = null)
  392. {
  393. self::SetCurrentChange($oChange);
  394. $this->CheckUserRights($bSkipStrongSecurity, UR_ACTION_MODIFY);
  395. $ret = $this->DBInsertTracked_Internal();
  396. return $ret;
  397. }
  398. public function DBInsertTrackedNoReload(CMDBChange $oChange, $bSkipStrongSecurity = null)
  399. {
  400. self::SetCurrentChange($oChange);
  401. $this->CheckUserRights($bSkipStrongSecurity, UR_ACTION_MODIFY);
  402. $ret = $this->DBInsertTracked_Internal(true);
  403. return $ret;
  404. }
  405. protected function DBInsertTracked_Internal($bDoNotReload = false)
  406. {
  407. if ($bDoNotReload)
  408. {
  409. $ret = parent::DBInsertNoReload();
  410. }
  411. else
  412. {
  413. $ret = parent::DBInsert();
  414. }
  415. return $ret;
  416. }
  417. public function DBClone($newKey = null)
  418. {
  419. return $this->DBCloneTracked_Internal();
  420. }
  421. public function DBCloneTracked(CMDBChange $oChange, $newKey = null)
  422. {
  423. self::SetCurrentChange($oChange);
  424. $this->DBCloneTracked_Internal($newKey);
  425. }
  426. protected function DBCloneTracked_Internal($newKey = null)
  427. {
  428. $newKey = parent::DBClone($newKey);
  429. $oClone = MetaModel::GetObject(get_class($this), $newKey);
  430. return $newKey;
  431. }
  432. public function DBUpdate()
  433. {
  434. // Copy the changes list before the update (the list should be reset afterwards)
  435. $aChanges = $this->ListChanges();
  436. if (count($aChanges) == 0)
  437. {
  438. return;
  439. }
  440. $ret = parent::DBUpdate();
  441. return $ret;
  442. }
  443. public function DBUpdateTracked(CMDBChange $oChange, $bSkipStrongSecurity = null)
  444. {
  445. self::SetCurrentChange($oChange);
  446. $this->CheckUserRights($bSkipStrongSecurity, UR_ACTION_MODIFY);
  447. $this->DBUpdate();
  448. }
  449. public function DBDelete(&$oDeletionPlan = null)
  450. {
  451. return $this->DBDeleteTracked_Internal($oDeletionPlan);
  452. }
  453. public function DBDeleteTracked(CMDBChange $oChange, $bSkipStrongSecurity = null, &$oDeletionPlan = null)
  454. {
  455. self::SetCurrentChange($oChange);
  456. $this->CheckUserRights($bSkipStrongSecurity, UR_ACTION_DELETE);
  457. $this->DBDeleteTracked_Internal($oDeletionPlan);
  458. }
  459. protected function DBDeleteTracked_Internal(&$oDeletionPlan = null)
  460. {
  461. $prevkey = $this->GetKey();
  462. $ret = parent::DBDelete($oDeletionPlan);
  463. return $ret;
  464. }
  465. public static function BulkUpdate(DBObjectSearch $oFilter, array $aValues)
  466. {
  467. return $this->BulkUpdateTracked_Internal($oFilter, $aValues);
  468. }
  469. public static function BulkUpdateTracked(CMDBChange $oChange, DBObjectSearch $oFilter, array $aValues)
  470. {
  471. self::SetCurrentChange($oChange);
  472. $this->BulkUpdateTracked_Internal($oFilter, $aValues);
  473. }
  474. protected static function BulkUpdateTracked_Internal(DBObjectSearch $oFilter, array $aValues)
  475. {
  476. // $aValues is an array of $sAttCode => $value
  477. // Get the list of objects to update (and load it before doing the change)
  478. $oObjSet = new CMDBObjectSet($oFilter);
  479. $oObjSet->Load();
  480. // Keep track of the previous values (will be overwritten when the objects are synchronized with the DB)
  481. $aOriginalValues = array();
  482. $oObjSet->Rewind();
  483. while ($oItem = $oObjSet->Fetch())
  484. {
  485. $aOriginalValues[$oItem->GetKey()] = $oItem->m_aOrigValues;
  486. }
  487. // Update in one single efficient query
  488. $ret = parent::BulkUpdate($oFilter, $aValues);
  489. // Record... in many queries !!!
  490. $oObjSet->Rewind();
  491. while ($oItem = $oObjSet->Fetch())
  492. {
  493. $aChangedValues = $oItem->ListChangedValues($aValues);
  494. $oItem->RecordAttChanges($aChangedValues, $aOriginalValues[$oItem->GetKey()]);
  495. }
  496. return $ret;
  497. }
  498. }
  499. /**
  500. * TODO: investigate how to get rid of this class that was made to workaround some language limitation... or a poor design!
  501. *
  502. * @package iTopORM
  503. */
  504. class CMDBObjectSet extends DBObjectSet
  505. {
  506. // this is the public interface (?)
  507. // I have to define those constructors here... :-(
  508. // just to get the right object class in return.
  509. // I have to think again to those things: maybe it will work fine if a have a constructor define here (?)
  510. static public function FromScratch($sClass)
  511. {
  512. $oFilter = new CMDBSearchFilter($sClass);
  513. $oFilter->AddConditionExpression(new FalseExpression());
  514. $oRetSet = new self($oFilter);
  515. // NOTE: THIS DOES NOT WORK IF m_bLoaded is private in the base class (and you will not get any error message)
  516. $oRetSet->m_bLoaded = true; // no DB load
  517. return $oRetSet;
  518. }
  519. // create an object set ex nihilo
  520. // input = array of objects
  521. static public function FromArray($sClass, $aObjects)
  522. {
  523. $oRetSet = self::FromScratch($sClass);
  524. $oRetSet->AddObjectArray($aObjects, $sClass);
  525. return $oRetSet;
  526. }
  527. static public function FromArrayAssoc($aClasses, $aObjects)
  528. {
  529. // In a perfect world, we should create a complete tree of DBObjectSearch,
  530. // but as we lack most of the information related to the objects,
  531. // let's create one search definition
  532. $sClass = reset($aClasses);
  533. $sAlias = key($aClasses);
  534. $oFilter = new CMDBSearchFilter($sClass, $sAlias);
  535. $oRetSet = new CMDBObjectSet($oFilter);
  536. $oRetSet->m_bLoaded = true; // no DB load
  537. foreach($aObjects as $rowIndex => $aObjectsByClassAlias)
  538. {
  539. $oRetSet->AddObjectExtended($aObjectsByClassAlias);
  540. }
  541. return $oRetSet;
  542. }
  543. }
  544. /**
  545. * TODO: investigate how to get rid of this class that was made to workaround some language limitation... or a poor design!
  546. *
  547. * @package iTopORM
  548. */
  549. class CMDBSearchFilter extends DBObjectSearch
  550. {
  551. // this is the public interface (?)
  552. }
  553. ?>