PageRenderTime 81ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/ecm/class/ecmdirectory.class.php

https://github.com/zeert/dolibarr
PHP | 697 lines | 628 code | 20 blank | 49 comment | 7 complexity | a6065cfb8e83186963773877fc648525 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2012 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/ecm/class/ecmdirectory.class.php
  20. * \ingroup ecm
  21. * \brief This file is an example for a class file
  22. * \author Laurent Destailleur
  23. */
  24. /**
  25. * \class EcmDirectory
  26. * \brief Class to manage ECM directories
  27. * \remarks Initialy built by build_class_from_table on 2008-02-24 19:24
  28. */
  29. class EcmDirectory // extends CommonObject
  30. {
  31. //public $element='ecm_directories'; //!< Id that identify managed objects
  32. //public $table_element='ecm_directories'; //!< Name of table without prefix where object is stored
  33. var $id;
  34. var $label;
  35. var $fk_parent;
  36. var $description;
  37. var $cachenbofdoc;
  38. var $date_c;
  39. var $date_m;
  40. var $cats=array();
  41. var $motherof=array();
  42. var $forbiddenchars = array('<','>',':','/','\\','?','*','|','"');
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. */
  48. function __construct($db)
  49. {
  50. $this->db = $db;
  51. return 1;
  52. }
  53. /**
  54. * Create record into database
  55. *
  56. * @param User $user User that create
  57. * @return int <0 if KO, >0 if OK
  58. */
  59. function create($user)
  60. {
  61. global $conf, $langs;
  62. $error=0;
  63. $now=dol_now();
  64. // Clean parameters
  65. $this->label=dol_sanitizeFileName(trim($this->label));
  66. $this->fk_parent=trim($this->fk_parent);
  67. $this->description=trim($this->description);
  68. if (! $this->cachenbofdoc) $this->cachenbofdoc=0;
  69. $this->date_c=$now;
  70. $this->fk_user_c=$user->id;
  71. if ($this->fk_parent <= 0) $this->fk_parent=0;
  72. // Check if same directory does not exists with this name
  73. $relativepath=$this->label;
  74. if ($this->fk_parent)
  75. {
  76. $parent = new EcmDirectory($this->db);
  77. $parent->fetch($this->fk_parent);
  78. $relativepath=$parent->getRelativePath().$relativepath;
  79. }
  80. $relativepath=preg_replace('/([\/])+/i','/',$relativepath); // Avoid duplicate / or \
  81. //print $relativepath.'<br>';
  82. $cat = new EcmDirectory($this->db);
  83. $cate_arbo = $cat->get_full_arbo(1);
  84. $pathfound=0;
  85. foreach ($cate_arbo as $key => $categ)
  86. {
  87. $path=str_replace($this->forbiddenchars,'_',$categ['fulllabel']);
  88. //print $path.'<br>';
  89. if ($path == $relativepath)
  90. {
  91. $pathfound=1;
  92. break;
  93. }
  94. }
  95. if ($pathfound)
  96. {
  97. $this->error="ErrorDirAlreadyExists";
  98. dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
  99. return -1;
  100. }
  101. else
  102. {
  103. $this->db->begin();
  104. // Insert request
  105. $sql = "INSERT INTO ".MAIN_DB_PREFIX."ecm_directories(";
  106. $sql.= "label,";
  107. $sql.= "entity,";
  108. $sql.= "fk_parent,";
  109. $sql.= "description,";
  110. $sql.= "cachenbofdoc,";
  111. $sql.= "date_c,";
  112. $sql.= "fk_user_c";
  113. $sql.= ") VALUES (";
  114. $sql.= " '".$this->db->escape($this->label)."',";
  115. $sql.= " '".$conf->entity."',";
  116. $sql.= " '".$this->fk_parent."',";
  117. $sql.= " '".$this->db->escape($this->description)."',";
  118. $sql.= " ".($this->cachenbofdoc).",";
  119. $sql.= " '".$this->db->idate($this->date_c)."',";
  120. $sql.= " '".$this->fk_user_c."'";
  121. $sql.= ")";
  122. dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
  123. $resql=$this->db->query($sql);
  124. if ($resql)
  125. {
  126. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ecm_directories");
  127. $dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
  128. $result=dol_mkdir($dir);
  129. // Appel des triggers
  130. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  131. $interface=new Interfaces($this->db);
  132. $result=$interface->run_triggers('MYECMDIR_CREATE',$this,$user,$langs,$conf);
  133. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  134. // Fin appel triggers
  135. if (! $error)
  136. {
  137. $this->db->commit();
  138. return $this->id;
  139. }
  140. else
  141. {
  142. $this->db->rollback();
  143. return -1;
  144. }
  145. }
  146. else
  147. {
  148. $this->error="Error ".$this->db->lasterror();
  149. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  150. $this->db->rollback();
  151. return -1;
  152. }
  153. }
  154. }
  155. /**
  156. * Update database
  157. *
  158. * @param User $user User that modify
  159. * @param int $notrigger 0=no, 1=yes (no update trigger)
  160. * @return int <0 if KO, >0 if OK
  161. */
  162. function update($user=0, $notrigger=0)
  163. {
  164. global $conf, $langs;
  165. $error=0;
  166. // Clean parameters
  167. $this->label=trim($this->label);
  168. $this->fk_parent=trim($this->fk_parent);
  169. $this->description=trim($this->description);
  170. // Check parameters
  171. // Put here code to add control on parameters values
  172. $this->db->begin();
  173. // Update request
  174. $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
  175. $sql.= " label='".$this->db->escape($this->label)."',";
  176. $sql.= " fk_parent='".$this->fk_parent."',";
  177. $sql.= " description='".$this->db->escape($this->description)."'";
  178. $sql.= " WHERE rowid=".$this->id;
  179. dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
  180. $resql = $this->db->query($sql);
  181. if (! $resql)
  182. {
  183. $error++;
  184. $this->error="Error ".$this->db->lasterror();
  185. dol_syslog("EcmDirectories::update ".$this->error, LOG_ERR);
  186. }
  187. if (! $error && ! $notrigger)
  188. {
  189. // Appel des triggers
  190. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  191. $interface=new Interfaces($this->db);
  192. $result=$interface->run_triggers('MYECMDIR_MODIFY',$this,$user,$langs,$conf);
  193. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  194. // Fin appel triggers
  195. }
  196. if (! $error)
  197. {
  198. $this->db->commit();
  199. return 1;
  200. }
  201. else
  202. {
  203. $this->db->rollback();
  204. return -1;
  205. }
  206. }
  207. /**
  208. * Update cache of nb of documents into database
  209. *
  210. * @param string $sign '+' or '-'
  211. * @return int <0 if KO, >0 if OK
  212. */
  213. function changeNbOfFiles($sign)
  214. {
  215. global $conf, $langs;
  216. // Update request
  217. $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
  218. $sql.= " cachenbofdoc = cachenbofdoc ".$sign." 1";
  219. $sql.= " WHERE rowid = ".$this->id;
  220. dol_syslog(get_class($this)."::changeNbOfFiles sql=".$sql, LOG_DEBUG);
  221. $resql = $this->db->query($sql);
  222. if (! $resql)
  223. {
  224. $this->error="Error ".$this->db->lasterror();
  225. dol_syslog(get_class($this)."::changeNbOfFiles ".$this->error, LOG_ERR);
  226. return -1;
  227. }
  228. return 1;
  229. }
  230. /**
  231. * Load object in memory from database
  232. *
  233. * @param int $id Id of object
  234. * @return int <0 if KO, 0 if not found, >0 if OK
  235. */
  236. function fetch($id)
  237. {
  238. $sql = "SELECT";
  239. $sql.= " t.rowid,";
  240. $sql.= " t.label,";
  241. $sql.= " t.fk_parent,";
  242. $sql.= " t.description,";
  243. $sql.= " t.cachenbofdoc,";
  244. $sql.= " t.fk_user_c,";
  245. $sql.= " t.fk_user_m,";
  246. $sql.= " t.date_c as date_c,";
  247. $sql.= " t.date_m as date_m";
  248. $sql.= " FROM ".MAIN_DB_PREFIX."ecm_directories as t";
  249. $sql.= " WHERE t.rowid = ".$id;
  250. dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
  251. $resql=$this->db->query($sql);
  252. if ($resql)
  253. {
  254. $obj = $this->db->fetch_object($resql);
  255. if ($obj)
  256. {
  257. $this->id = $obj->rowid;
  258. $this->ref = $obj->rowid;
  259. $this->label = $obj->label;
  260. $this->fk_parent = $obj->fk_parent;
  261. $this->description = $obj->description;
  262. $this->cachenbofdoc = $obj->cachenbofdoc;
  263. $this->fk_user_m = $obj->fk_user_m;
  264. $this->fk_user_c = $obj->fk_user_c;
  265. $this->date_c = $this->db->jdate($obj->date_c);
  266. $this->date_m = $this->db->jdate($obj->date_m);
  267. }
  268. $this->db->free($resql);
  269. return $obj?1:0;
  270. }
  271. else
  272. {
  273. $this->error="Error ".$this->db->lasterror();
  274. dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
  275. return -1;
  276. }
  277. }
  278. /**
  279. * Delete object on database and on disk
  280. *
  281. * @param User $user User that delete
  282. * @return int <0 if KO, >0 if OK
  283. */
  284. function delete($user)
  285. {
  286. global $conf, $langs;
  287. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  288. $error=0;
  289. $relativepath=$this->getRelativePath(1); // Ex: dir1/dir2/dir3
  290. dol_syslog(get_class($this)."::delete remove directory ".$relativepath);
  291. $this->db->begin();
  292. $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_directories";
  293. $sql.= " WHERE rowid=".$this->id;
  294. dol_syslog(get_class($this)."::delete sql=".$sql);
  295. $resql = $this->db->query($sql);
  296. if (! $resql)
  297. {
  298. $this->db->rollback();
  299. $this->error="Error ".$this->db->lasterror();
  300. dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
  301. return -2;
  302. }
  303. $file = $conf->ecm->dir_output . "/" . $relativepath;
  304. $result=@dol_delete_dir($file);
  305. if ($result || ! @is_dir(dol_osencode($file)))
  306. {
  307. $this->db->commit();
  308. }
  309. else
  310. {
  311. $this->error='ErrorFailToDeleteDir';
  312. dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
  313. $this->db->rollback();
  314. $error++;
  315. }
  316. if (! $error)
  317. {
  318. // Appel des triggers
  319. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  320. $interface=new Interfaces($this->db);
  321. $result=$interface->run_triggers('MYECMDIR_DELETE',$this,$user,$langs,$conf);
  322. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  323. // Fin appel triggers
  324. }
  325. if (! $error) return 1;
  326. else return -1;
  327. }
  328. /**
  329. * Initialise an instance with random values.
  330. * Used to build previews or test instances.
  331. * id must be 0 if object instance is a specimen.
  332. *
  333. * @return void
  334. */
  335. function initAsSpecimen()
  336. {
  337. $this->id=0;
  338. $this->label='MyDirectory';
  339. $this->fk_parent='0';
  340. $this->description='This is a directory';
  341. }
  342. /**
  343. * Return directory name you can click (and picto)
  344. *
  345. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  346. * @param string $option Sur quoi pointe le lien
  347. * @param int $max Max length
  348. * @param string $more Add more param on a link
  349. * @return string Chaine avec URL
  350. */
  351. function getNomUrl($withpicto=0,$option='',$max=0,$more='')
  352. {
  353. global $langs;
  354. $result='';
  355. $lien = '<a href="'.DOL_URL_ROOT.'/ecm/docmine.php?section='.$this->id.'"'.($more?' '.$more:'').'>';
  356. if ($option == 'index') $lien = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=true"'.($more?' '.$more:'').'>';
  357. if ($option == 'indexexpanded') $lien = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=false"'.($more?' '.$more:'').'>';
  358. if ($option == 'indexnotexpanded') $lien = '<a href="'.DOL_URL_ROOT.'/ecm/index.php?section='.$this->id.'&amp;sectionexpand=true"'.($more?' '.$more:'').'>';
  359. $lienfin='</a>';
  360. //$picto=DOL_URL_ROOT.'/theme/common/treemenu/folder.gif';
  361. $picto='dir';
  362. //$newref=str_replace('_',' ',$this->ref);
  363. $newref=$this->ref;
  364. $newlabel=$langs->trans("ShowECMSection").': '.$newref;
  365. if ($withpicto) $result.=($lien.img_object($newlabel,$picto).$lienfin);
  366. if ($withpicto && $withpicto != 2) $result.=' ';
  367. if ($withpicto != 2) $result.=$lien.($max?dol_trunc($newref,$max,'middle'):$newref).$lienfin;
  368. return $result;
  369. }
  370. /**
  371. * Return relative path of a directory on disk
  372. *
  373. * @param int $force Force reload of full arbo even if already loaded
  374. * @return string Relative physical path
  375. */
  376. function getRelativePath($force=0)
  377. {
  378. $this->get_full_arbo($force);
  379. $ret='';
  380. $idtosearch=$this->id;
  381. $i=0;
  382. do {
  383. // Get index cursor in this->cats for id_mere
  384. $cursorindex=-1;
  385. foreach ($this->cats as $key => $val)
  386. {
  387. if ($this->cats[$key]['id'] == $idtosearch)
  388. {
  389. $cursorindex=$key;
  390. break;
  391. }
  392. }
  393. //print "c=".$idtosearch."-".$cursorindex;
  394. if ($cursorindex >= 0)
  395. {
  396. // Path is label sanitized (no space and no special char) and concatenated
  397. $ret=dol_sanitizeFileName($this->cats[$cursorindex]['label']).'/'.$ret;
  398. $idtosearch=$this->cats[$cursorindex]['id_mere'];
  399. $i++;
  400. }
  401. }
  402. while ($cursorindex >= 0 && ! empty($idtosearch) && $i < 100); // i avoid infinite loop
  403. return $ret;
  404. }
  405. /**
  406. * Load this->motherof that is array(id_son=>id_parent, ...)
  407. *
  408. * @return int <0 if KO, >0 if OK
  409. */
  410. function load_motherof()
  411. {
  412. global $conf;
  413. $this->motherof=array();
  414. // Charge tableau des meres
  415. $sql = "SELECT fk_parent as id_parent, rowid as id_son";
  416. $sql.= " FROM ".MAIN_DB_PREFIX."ecm_directories";
  417. $sql.= " WHERE fk_parent != 0";
  418. $sql.= " AND entity = ".$conf->entity;
  419. dol_syslog(get_class($this)."::get_full_arbo sql=".$sql);
  420. $resql = $this->db->query($sql);
  421. if ($resql)
  422. {
  423. while ($obj= $this->db->fetch_object($resql))
  424. {
  425. $this->motherof[$obj->id_son]=$obj->id_parent;
  426. }
  427. return 1;
  428. }
  429. else
  430. {
  431. dol_print_error($this->db);
  432. return -1;
  433. }
  434. }
  435. /**
  436. * Reconstruit l'arborescence des categories sous la forme d'un tableau
  437. * Renvoi un tableau de tableau('id','id_mere',...) trie selon arbre et avec:
  438. * id Id de la categorie
  439. * id_mere Id de la categorie mere
  440. * id_children Tableau des id enfant
  441. * label Name of directory
  442. * cachenbofdoc Nb of documents
  443. * date_c Date creation
  444. * fk_user_c User creation
  445. * login_c Login creation
  446. * fullpath Full path of id (Added by build_path_from_id_categ call)
  447. * fullrelativename Full path name (Added by build_path_from_id_categ call)
  448. * fulllabel Full label (Added by build_path_from_id_categ call)
  449. * level Level of line (Added by build_path_from_id_categ call)
  450. *
  451. * @param int $force Force reload of full arbo even if already loaded in cache $this->cats
  452. * @return array Tableau de array
  453. */
  454. function get_full_arbo($force=0)
  455. {
  456. global $conf;
  457. if (empty($force) && ! empty($this->full_arbo_loaded))
  458. {
  459. return $this->cats;
  460. }
  461. // Init this->motherof that is array(id_son=>id_parent, ...)
  462. $this->load_motherof();
  463. // Charge tableau des categories
  464. $sql = "SELECT c.rowid as rowid, c.label as label,";
  465. $sql.= " c.description as description, c.cachenbofdoc,";
  466. $sql.= " c.fk_user_c,";
  467. $sql.= " c.date_c,";
  468. $sql.= " u.login as login_c,";
  469. $sql.= " ca.rowid as rowid_fille";
  470. $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
  471. $sql.= ", ".MAIN_DB_PREFIX."ecm_directories as c";
  472. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ecm_directories as ca";
  473. $sql.= " ON c.rowid = ca.fk_parent";
  474. $sql.= " WHERE c.fk_user_c = u.rowid";
  475. $sql.= " AND c.entity = ".$conf->entity;
  476. $sql.= " ORDER BY c.label, c.rowid";
  477. dol_syslog(get_class($this)."::get_full_arbo sql=".$sql);
  478. $resql = $this->db->query($sql);
  479. if ($resql)
  480. {
  481. $this->cats = array();
  482. $i=0;
  483. while ($obj = $this->db->fetch_object($resql))
  484. {
  485. $this->cats[$obj->rowid]['id'] = $obj->rowid;
  486. $this->cats[$obj->rowid]['id_mere'] = (isset($this->motherof[$obj->rowid])?$this->motherof[$obj->rowid]:'');
  487. $this->cats[$obj->rowid]['label'] = $obj->label;
  488. $this->cats[$obj->rowid]['description'] = $obj->description;
  489. $this->cats[$obj->rowid]['cachenbofdoc'] = $obj->cachenbofdoc;
  490. $this->cats[$obj->rowid]['date_c'] = $this->db->jdate($obj->date_c);
  491. $this->cats[$obj->rowid]['fk_user_c'] = $obj->fk_user_c;
  492. $this->cats[$obj->rowid]['login_c'] = $obj->login_c;
  493. if ($obj->rowid_fille)
  494. {
  495. if (is_array($this->cats[$obj->rowid]['id_children']))
  496. {
  497. $newelempos=count($this->cats[$obj->rowid]['id_children']);
  498. //print "this->cats[$i]['id_children'] est deja un tableau de $newelem elements<br>";
  499. $this->cats[$obj->rowid]['id_children'][$newelempos]=$obj->rowid_fille;
  500. }
  501. else
  502. {
  503. //print "this->cats[".$obj->rowid."]['id_children'] n'est pas encore un tableau<br>";
  504. $this->cats[$obj->rowid]['id_children']=array($obj->rowid_fille);
  505. }
  506. }
  507. $i++;
  508. }
  509. }
  510. else
  511. {
  512. dol_print_error($this->db);
  513. return -1;
  514. }
  515. // We add properties fullxxx to all elements
  516. foreach($this->cats as $key => $val)
  517. {
  518. if (isset($motherof[$key])) continue;
  519. $this->build_path_from_id_categ($key,0);
  520. }
  521. $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false);
  522. $this->full_arbo_loaded=1;
  523. return $this->cats;
  524. }
  525. /**
  526. * Define properties fullpath, fullrelativename, fulllabel of a directory of array this->cats and all its childs.
  527. * Separator between directories is always '/', whatever is OS.
  528. *
  529. * @param int $id_categ id_categ entry to update
  530. * @param int $protection Deep counter to avoid infinite loop
  531. * @return void
  532. */
  533. function build_path_from_id_categ($id_categ,$protection=0)
  534. {
  535. // Define fullpath
  536. if (! empty($this->cats[$id_categ]['id_mere']))
  537. {
  538. $this->cats[$id_categ]['fullpath'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fullpath'];
  539. $this->cats[$id_categ]['fullpath'].='_'.$id_categ;
  540. $this->cats[$id_categ]['fullrelativename'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fullrelativename'];
  541. $this->cats[$id_categ]['fullrelativename'].='/'.$this->cats[$id_categ]['label'];
  542. $this->cats[$id_categ]['fulllabel'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fulllabel'];
  543. $this->cats[$id_categ]['fulllabel'].=' >> '.$this->cats[$id_categ]['label'];
  544. }
  545. else
  546. {
  547. $this->cats[$id_categ]['fullpath']='_'.$id_categ;
  548. $this->cats[$id_categ]['fullrelativename']=$this->cats[$id_categ]['label'];
  549. $this->cats[$id_categ]['fulllabel']=$this->cats[$id_categ]['label'];
  550. }
  551. // We count number of _ to have level (we use strlen that is faster than dol_strlen)
  552. $this->cats[$id_categ]['level']=strlen(preg_replace('/([^_])/i','',$this->cats[$id_categ]['fullpath']));
  553. // Traite ces enfants
  554. $protection++;
  555. if ($protection > 20) return; // On ne traite pas plus de 20 niveaux
  556. if (isset($this->cats[$id_categ]['id_children']) && is_array($this->cats[$id_categ]['id_children']))
  557. {
  558. foreach($this->cats[$id_categ]['id_children'] as $key => $val)
  559. {
  560. $this->build_path_from_id_categ($val,$protection);
  561. }
  562. }
  563. return 1;
  564. }
  565. /**
  566. * Refresh value for cachenboffile
  567. *
  568. * @param int $all 0=refresh this id , 1=refresh this entity
  569. * @return int <0 if KO, Nb of files in directory if OK
  570. */
  571. function refreshcachenboffile($all=0)
  572. {
  573. global $conf;
  574. include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
  575. $dir=$conf->ecm->dir_output.'/'.$this->getRelativePath();
  576. $filelist=dol_dir_list($dir,'files',0,'','\.meta$');
  577. // Test if filelist is in database
  578. // Update request
  579. $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
  580. $sql.= " cachenbofdoc = '".count($filelist)."'";
  581. if (empty($all)) // By default
  582. {
  583. $sql.= " WHERE rowid = ".$this->id;
  584. }
  585. else
  586. {
  587. $sql.= " WHERE entity = ".$conf->entity;
  588. }
  589. dol_syslog(get_class($this)."::refreshcachenboffile sql=".$sql, LOG_DEBUG);
  590. $resql = $this->db->query($sql);
  591. if ($resql)
  592. {
  593. $this->cachenbofdoc=count($filelist);
  594. return $this->cachenbofdoc;
  595. }
  596. else
  597. {
  598. $this->error="Error ".$this->db->lasterror();
  599. dol_syslog(get_class($this)."::refreshcachenboffile ".$this->error, LOG_ERR);
  600. return -1;
  601. }
  602. }
  603. }
  604. ?>