PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

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