/** * testDolCompressUnCompress * * @return string */ public function testDolCompressUnCompress() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $format='zip'; $filein=dirname(__FILE__).'/Example_import_company_1.csv'; $fileout=$conf->admin->dir_temp.'/test.'.$format; $dirout=$conf->admin->dir_temp.'/test'; dol_delete_file($fileout); $count=0; dol_delete_dir_recursive($dirout,$count,1); $result=dol_compress_file($filein, $fileout, $format); print __METHOD__." result=".$result."\n"; $this->assertGreaterThanOrEqual(1,$result); $result=dol_uncompress($fileout, $dirout); print __METHOD__." result=".join(',',$result)."\n"; $this->assertEquals(0,count($result)); }
/** * Clear list of attached files in send mail form (stored in session) * * @return void */ function clear_attached_files() { global $conf, $user; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; // Set tmp user directory $vardir = $conf->user->dir_output . "/" . $user->id; $upload_dir = $vardir . '/temp/'; if (is_dir($upload_dir)) { dol_delete_dir_recursive($upload_dir); } unset($_SESSION["listofpaths"]); unset($_SESSION["listofnames"]); unset($_SESSION["listofmimes"]); }
if ($result <= 0) { $error = $object->error; $errors = $object->errors; } // Gestion du logo de la société $dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos"; $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); if ($file_OK) { if (GETPOST('deletephoto')) { $fileimg=$dir.'/'.$object->logo; $dirthumbs=$dir.'/thumbs'; dol_delete_file($fileimg); dol_delete_dir_recursive($dirthumbs); } if (image_format_supported($_FILES['photo']['name']) > 0) { dol_mkdir($dir); if (@is_dir($dir)) { $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1); if (! $result > 0) { $errors[] = "ErrorFailedToSaveFile"; }
/** * Delete invoice * * @param int $rowid Id of invoice to delete. If empty, we delete current instance of invoice * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ function delete($rowid = 0, $notrigger = 0) { global $user, $langs, $conf; require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; if (!$rowid) { $rowid = $this->id; } dol_syslog(get_class($this) . "::delete rowid=" . $rowid, LOG_DEBUG); // TODO Test if there is at least on payment. If yes, refuse to delete. $error = 0; $this->db->begin(); if (!$error && !$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('BILL_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } } if (!$error) { // If invoice was converted into a discount not yet consumed, we remove discount $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'societe_remise_except'; $sql .= ' WHERE fk_facture_source = ' . $rowid; $sql .= ' AND fk_facture_line IS NULL'; $resql = $this->db->query($sql); // If invoice has consumned discounts $this->fetch_lines(); $list_rowid_det = array(); foreach ($this->lines as $key => $invoiceline) { $list_rowid_det[] = $invoiceline->rowid; } // Consumned discounts are freed if (count($list_rowid_det)) { $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except'; $sql .= ' SET fk_facture = NULL, fk_facture_line = NULL'; $sql .= ' WHERE fk_facture_line IN (' . join(',', $list_rowid_det) . ')'; dol_syslog(get_class($this) . "::delete sql=" . $sql); if (!$this->db->query($sql)) { $this->error = $this->db->error() . " sql=" . $sql; dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -5; } } // Delete invoice line $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE fk_facture = ' . $rowid; if ($this->db->query($sql) && $this->delete_linked_contact()) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facture WHERE rowid = ' . $rowid; $resql = $this->db->query($sql); if ($resql) { // On efface le repertoire de pdf provisoire $ref = dol_sanitizeFileName($this->ref); if ($conf->facture->dir_output) { $dir = $conf->facture->dir_output . "/" . $ref; $file = $conf->facture->dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (file_exists($file)) { $ret = dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = $langs->trans("ErrorCanNotDeleteFile", $file); $this->db->rollback(); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); $this->db->rollback(); return 0; } } } $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror() . " sql=" . $sql; dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -6; } } else { $this->error = $this->db->lasterror() . " sql=" . $sql; dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -4; } } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -2; } }
/** * Delete invoice * * @param int $rowid Id of invoice to delete. If empty, we delete current instance of invoice * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @param int $idwarehouse Id warehouse to use for stock change. * @return int <0 if KO, >0 if OK */ function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1) { global $user, $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; if (empty($rowid)) { $rowid = $this->id; } dol_syslog(get_class($this) . "::delete rowid=" . $rowid, LOG_DEBUG); // TODO Test if there is at least one payment. If yes, refuse to delete. $error = 0; $this->db->begin(); if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('BILL_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } // Removed extrafields if (!$error) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this) . "::delete error deleteExtraFields " . $this->error, LOG_ERR); } } if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } } if (!$error) { // If invoice was converted into a discount not yet consumed, we remove discount $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'societe_remise_except'; $sql .= ' WHERE fk_facture_source = ' . $rowid; $sql .= ' AND fk_facture_line IS NULL'; $resql = $this->db->query($sql); // If invoice has consumned discounts $this->fetch_lines(); $list_rowid_det = array(); foreach ($this->lines as $key => $invoiceline) { $list_rowid_det[] = $invoiceline->rowid; } // Consumned discounts are freed if (count($list_rowid_det)) { $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except'; $sql .= ' SET fk_facture = NULL, fk_facture_line = NULL'; $sql .= ' WHERE fk_facture_line IN (' . join(',', $list_rowid_det) . ')'; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if (!$this->db->query($sql)) { $this->error = $this->db->error() . " sql=" . $sql; $this->db->rollback(); return -5; } } // If we decrement stock on invoice validation, we increment if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse != -1) { require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); $num = count($this->lines); for ($i = 0; $i < $num; $i++) { if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin =& $this; // We decrease stock for product if ($this->type == self::TYPE_CREDIT_NOTE) { $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr", $this->ref)); } else { $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr", $this->ref)); } // we use 0 for price, to not change the weighted average value } } } // Delete invoice line $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE fk_facture = ' . $rowid; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if ($this->db->query($sql) && $this->delete_linked_contact()) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facture WHERE rowid = ' . $rowid; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { // On efface le repertoire de pdf provisoire $ref = dol_sanitizeFileName($this->ref); if ($conf->facture->dir_output && !empty($this->ref)) { $dir = $conf->facture->dir_output . "/" . $ref; $file = $conf->facture->dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (file_exists($file)) { $ret = dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = $langs->trans("ErrorCanNotDeleteFile", $file); $this->db->rollback(); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); $this->db->rollback(); return 0; } } } $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror() . " sql=" . $sql; $this->db->rollback(); return -6; } } else { $this->error = $this->db->lasterror() . " sql=" . $sql; $this->db->rollback(); return -4; } } else { $this->db->rollback(); return -2; } }
/** * Delete a product from database (if not used) * * @param int $id Product id (usage of this is deprecated, delete should be called without parameters on a fetched object) * @return int < 0 if KO, 0 = Not possible, > 0 if OK */ function delete($id = 0) { // Deprecation warning if (0 == $id) { dol_syslog(__METHOD__ . " with parameter is deprecated", LOG_WARNING); } global $conf, $user, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; // Clean parameters if (empty($id)) { $id = $this->id; } else { $this->fetch($id); } // Check parameters if (empty($id)) { $this->error = "Object must be fetched before calling delete"; return -1; } if ($this->type == Product::TYPE_PRODUCT && empty($user->rights->produit->supprimer) || $this->type == Product::TYPE_SERVICE && empty($user->rights->service->supprimer)) { $this->error = "ErrorForbidden"; return 0; } $objectisused = $this->isObjectUsed($id); if (empty($objectisused)) { $this->db->begin(); if (!$error) { // Call trigger $result = $this->call_trigger('PRODUCT_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } // Delete all child tables if (!$error) { $elements = array('product_fournisseur_price', 'product_price', 'product_lang', 'categorie_product', 'product_stock'); foreach ($elements as $table) { if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . $table; $sql .= " WHERE fk_product = " . $id; dol_syslog(get_class($this) . '::delete', LOG_DEBUG); $result = $this->db->query($sql); if (!$result) { $error++; $this->errors[] = $this->db->lasterror(); } } } } // Delete product if (!$error) { $sqlz = "DELETE FROM " . MAIN_DB_PREFIX . "product"; $sqlz .= " WHERE rowid = " . $id; dol_syslog(get_class($this) . '::delete', LOG_DEBUG); $resultz = $this->db->query($sqlz); if (!$resultz) { $error++; $this->errors[] = $this->db->lasterror(); } } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->product->dir_output) { $dir = $conf->product->dir_output . "/" . $ref; if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->errors[] = 'ErrorFailToDeleteDir'; $error++; } } } } // Remove extrafields if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); } } if (!$error) { $this->db->commit(); return 1; } else { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -$error; } } else { $this->error = "ErrorRecordIsUsedCantDelete"; return 0; } }
/** * Delete an order * * @param User $user Object user * @return int <0 if KO, >0 if OK */ function delete($user = '') { global $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_DELETE', $user); if ($result < 0) { $this->errors[] = 'ErrorWhenRunningTrigger'; dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); return -1; } // End call triggers $this->db->begin(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet WHERE fk_commande =" . $this->id; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if (!$this->db->query($sql)) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE rowid =" . $this->id; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if ($resql = $this->db->query($sql)) { if ($this->db->affected_rows($resql) < 1) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; } } else { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; } // Remove extrafields if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $this->error = 'FailToDeleteExtraFields'; $this->errors[] = 'FailToDeleteExtraFields'; $error++; dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); } } // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $this->error = 'FailToDeleteObjectLinked'; $this->errors[] = 'FailToDeleteObjectLinked'; $error++; } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->fournisseur->commande->dir_output) { $dir = $conf->fournisseur->commande->dir_output . "/" . $ref; $file = $dir . "/" . $ref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = 'ErrorFailToDeleteFile'; $this->errors[] = 'ErrorFailToDeleteFile'; $error++; } } if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->errors[] = 'ErrorFailToDeleteDir'; $error++; } } } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -$error; } }
/** * Delete a third party from database and all its dependencies (contacts, rib...) * * @param int $id Id of third party to delete * @param User $fuser User who ask to delete thirparty * @param int $call_trigger 0=No, 1=yes * @return int <0 if KO, 0 if nothing done, >0 if OK */ function delete($id, User $fuser=null, $call_trigger=1) { global $langs, $conf, $user; if (empty($fuser)) $fuser=$user; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $entity=isset($this->entity)?$this->entity:$conf->entity; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $error = 0; // Test if child exists $objectisused = $this->isObjectUsed($id); if (empty($objectisused)) { $this->db->begin(); // User is mandatory for trigger call if ($call_trigger) { // Call trigger $result=$this->call_trigger('COMPANY_DELETE',$fuser); if ($result < 0) $error++; // End call triggers } if (! $error) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) if ($this->client || $this->prospect) { $toute_categs ['societe'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER); } if ($this->fournisseur) { $toute_categs ['fournisseur'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER); } // Remove each "Categorie" foreach ($toute_categs as $type => $categs_type) { foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } } // Remove contacts if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = " . $id; if (! $this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); } } // Update link in member table if (! $error) { $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id; if (! $this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); dol_syslog(get_class($this)."::delete erreur -1 ".$this->error, LOG_ERR); } } // Remove ban if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib"; $sql.= " WHERE fk_soc = " . $id; if (! $this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); } } // Remove societe_remise_except if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except"; $sql.= " WHERE fk_soc = " . $id; if (! $this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); } } // Remove associated users if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; $sql.= " WHERE fk_soc = " . $id; if (! $this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); } } // Removed extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { $result=$this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } // Remove third party if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE rowid = " . $id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); if (! $this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); } } if (! $error) { $this->db->commit(); // Delete directory if (! empty($conf->societe->multidir_output[$entity])) { $docdir = $conf->societe->multidir_output[$entity] . "/" . $id; if (dol_is_dir($docdir)) { dol_delete_dir_recursive($docdir); } } return 1; } else { dol_syslog($this->error, LOG_ERR); $this->db->rollback(); return -1; } } else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); return 0; }
/** * Delete invoice from database * * @param int $rowid Id of invoice to delete * @return int <0 if KO, >0 if OK */ function delete($rowid) { global $user, $langs, $conf; if (!$rowid) { $rowid = $this->id; } dol_syslog("FactureFournisseur::delete rowid=" . $rowid, LOG_DEBUG); // TODO Test if there is at least on payment. If yes, refuse to delete. $error = 0; $this->db->begin(); $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facture_fourn_det WHERE fk_facture_fourn = ' . $rowid . ';'; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facture_fourn WHERE rowid = ' . $rowid; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $resql2 = $this->db->query($sql); if (!$resql2) { $error++; } } else { $error++; } if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } } if (!$error) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_DELETE', $user); if ($result < 0) { $this->db->rollback(); return -1; } // Fin appel triggers } if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } } if (!$error) { // We remove directory if ($conf->fournisseur->facture->dir_output) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $ref = dol_sanitizeFileName($this->ref); $dir = $conf->fournisseur->facture->dir_output . '/' . get_exdir($this->id, 2, 0, 0, $this, 'invoive_supplier') . $ref; $file = $dir . "/" . $ref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = 'ErrorFailToDeleteFile'; $error++; } } if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $error++; } } } } // Remove extrafields if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -$error; } }
/** * Remove deprecated directories * * @param DoliDB $db Database handler * @param Translate $langs Object langs * @param Conf $conf Object conf * @return void */ function migrate_delete_old_dir($db, $langs, $conf) { $result = true; dolibarr_install_syslog("upgrade2::migrate_delete_old_dir"); // List of files to delete $filetodeletearray = array(DOL_DOCUMENT_ROOT . '/core/modules/facture/terre', DOL_DOCUMENT_ROOT . '/core/modules/facture/mercure'); foreach ($filetodeletearray as $filetodelete) { //print '<b>'.$filetodelete."</b><br>\n"; if (file_exists($filetodelete)) { $result = dol_delete_dir_recursive($filetodelete); } if (!$result) { $langs->load("errors"); print '<div class="error">' . $langs->trans("Error") . ': ' . $langs->trans("ErrorFailToDeleteDir", $filetodelete); print ' ' . $langs->trans("RemoveItManuallyAndPressF5ToContinue") . '</div>'; } } return $result; }
/** * Remove a directory $dir and its subdirectories (or only files and subdirectories) * * @param string $dir Dir to delete * @param int $count Counter to count nb of deleted elements * @param int $nophperrors Disable all PHP output errors * @param int $onlysub Delete only files and subdir, not main directory * @return int Number of files and directory removed */ function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0) { dol_syslog("functions.lib:dol_delete_dir_recursive " . $dir, LOG_DEBUG); if (dol_is_dir($dir)) { $dir_osencoded = dol_osencode($dir); if ($handle = opendir("{$dir_osencoded}")) { while (false !== ($item = readdir($handle))) { if (!utf8_check($item)) { $item = utf8_encode($item); } // should be useless if ($item != "." && $item != "..") { if (is_dir(dol_osencode("{$dir}/{$item}"))) { $count = dol_delete_dir_recursive("{$dir}/{$item}", $count, $nophperrors); } else { dol_delete_file("{$dir}/{$item}", 1, $nophperrors); $count++; //echo " removing $dir/$item<br>\n"; } } } closedir($handle); if (empty($onlysub)) { dol_delete_dir($dir, $nophperrors); $count++; //echo "removing $dir<br>\n"; } } } //echo "return=".$count; return $count; }
/** * Purge files into directory of data files. * * @param string $choice Choice of purge mode ('tempfiles', 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfiles') * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) */ function purgeFiles($choice = 'tempfilesold') { global $conf, $langs, $dolibarr_main_data_root; dol_syslog("Utils::purgeFiles choice=" . $choice, LOG_DEBUG); require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $filesarray = array(); if (empty($choice)) { $choice = 'tempfilesold'; } if ($choice == 'tempfiles' || $choice == 'tempfilesold') { // Delete temporary files if ($dolibarr_main_data_root) { $filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', '', '', 2); if ($choice == 'tempfilesold') { $now = dol_now(); foreach ($filesarray as $key => $val) { if ($val['date'] > $now - 24 * 3600) { unset($filesarray[$key]); } // Discard files not older than 24h } } } } if ($choice == 'allfiles') { // Delete all files if ($dolibarr_main_data_root) { $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\\.lock$'); } } if ($choice == 'logfile') { // Define filelog to discard it from purge $filelog = ''; if (!empty($conf->syslog->enabled)) { $filelog = SYSLOG_FILE; $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog); } $filesarray[] = array('fullname' => $filelog, 'type' => 'file'); } $count = 0; if (count($filesarray)) { foreach ($filesarray as $key => $value) { //print "x ".$filesarray[$key]['fullname']."<br>\n"; if ($filesarray[$key]['type'] == 'dir') { $count += dol_delete_dir_recursive($filesarray[$key]['fullname']); } elseif ($filesarray[$key]['type'] == 'file') { // If (file that is not logfile) or (if logfile with option logfile) if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') { $count += dol_delete_file($filesarray[$key]['fullname']) ? 1 : 0; } } } // Update cachenbofdoc if (!empty($conf->ecm->enabled) && $choice == 'allfiles') { require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php'; $ecmdirstatic = new EcmDirectory($this->db); $result = $ecmdirstatic->refreshcachenboffile(1); } } if ($count > 0) { $this->output = $langs->trans("PurgeNDirectoriesDeleted", $count); } else { $this->output = $langs->trans("PurgeNothingToDelete"); } //return $count; return 0; // This function can be called by cron so must return 0 if OK }
/** * Delete an order * * @param User $user Object user * @return int <0 if KO, >0 if OK */ function delete($user = '') { global $langs, $conf; require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; $error = 0; $this->db->begin(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet WHERE fk_commande =" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE rowid =" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if ($resql = $this->db->query($sql)) { if ($this->db->affected_rows($resql) < 1) { $error++; } } else { $error++; } if (!$error) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('ORDER_SUPPLIER_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->fournisseur->commande->dir_output) { $dir = $conf->fournisseur->commande->dir_output . "/" . $ref; $file = $dir . "/" . $ref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = 'ErrorFailToDeleteFile'; $error++; } } if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $error++; } } } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -$error; } }
/** * Delete a third party from database and all its dependencies (contacts, rib...) * * @param int $id Id of third party to delete * @return int <0 if KO, 0 if nothing done, >0 if OK */ function delete($id) { global $user, $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $entity = isset($this->entity) ? $this->entity : $conf->entity; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $error = 0; // Test if child exists $objectisused = $this->isObjectUsed($id); if (empty($objectisused)) { $this->db->begin(); if (!$error) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('COMPANY_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) if ($this->client || $this->prospect) { $toute_categs['societe'] = $static_cat->containing($this->id, 2); } if ($this->fournisseur) { $toute_categs['fournisseur'] = $static_cat->containing($this->id, 1); } // Remove each "Categorie" foreach ($toute_categs as $type => $categs_type) { foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } } // Remove contacts if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "socpeople"; $sql .= " WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR); } } // Update link in member table if (!$error) { $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent"; $sql .= " SET fk_soc = NULL WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR); } } // Remove ban if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib"; $sql .= " WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::Delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -2 " . $this->error, LOG_ERR); } } // Removed extrafields if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this) . "::delete error -3 " . $this->error, LOG_ERR); } } // Remove third party if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe"; $sql .= " WHERE rowid = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); } } if (!$error) { $this->db->commit(); // Delete directory if (!empty($conf->societe->multidir_output[$entity])) { $docdir = $conf->societe->multidir_output[$entity] . "/" . $id; if (dol_is_dir($docdir)) { dol_delete_dir_recursive($docdir); } } return 1; } else { $this->db->rollback(); return -1; } } else { dol_syslog("Can't remove thirdparty with id " . $id . ". There is " . $objectisused . " childs", LOG_WARNING); } return 0; }
/** * Delete proposal * * @param User $user Object user that delete * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int 1 if ok, otherwise if error */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; $error = 0; $this->db->begin(); if (!$error && !$notrigger) { // Call triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('PROPAL_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // End call triggers } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE fk_propal = " . $this->id; if ($this->db->query($sql)) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propal WHERE rowid = " . $this->id; if ($this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $error++; } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->propal->dir_output) { $dir = $conf->propal->dir_output . "/" . $ref; $file = $dir . "/" . $ref . ".pdf"; if (file_exists($file)) { dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = 'ErrorFailToDeleteFile'; $this->db->rollback(); return 0; } } if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->db->rollback(); return 0; } } } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return 0; } } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -3; } } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -2; } } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -1; } }
/** * Delete intervetnion * * @param User $user Object user who delete * @param int $notrigger Disable trigger * @return int <0 if KO, >0 if OK */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error = 'ErrorFailToDeleteLinkedContact'; $error++; } if ($error) { $this->db->rollback(); return -1; } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "fichinterdet"; $sql .= " WHERE fk_fichinter = " . $this->id; dol_syslog("Fichinter::delete", LOG_DEBUG); if ($this->db->query($sql)) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "fichinter"; $sql .= " WHERE rowid = " . $this->id; $sql .= " AND entity = " . $conf->entity; dol_syslog("Fichinter::delete", LOG_DEBUG); if ($this->db->query($sql)) { // Remove directory with files $fichinterref = dol_sanitizeFileName($this->ref); if ($conf->ficheinter->dir_output) { $dir = $conf->ficheinter->dir_output . "/" . $fichinterref; $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; if (file_exists($file)) { dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = $langs->trans("ErrorCanNotDeleteFile", $file); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); return 0; } } } if (!$notrigger) { // Call trigger $result = $this->call_trigger('FICHINTER_DELETE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } }
{ $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("File")); $error++; } else { if (! preg_match('/\.tgz/i',$original_file)) { $mesg=$langs->trans("ErrorFileMustBeADolibarrPackage"); $error++; } } if (! $error) { @dol_delete_dir_recursive($conf->admin->dir_temp.'/'.$original_file); create_exdir($conf->admin->dir_temp.'/'.$original_file); $result=dol_move_uploaded_file($_FILES["fileinstall"]["tmp_name"],$newfile,1,0,$_FILES['fileinstall']['error']); if ($result > 0) { //dol_uncompress($newfile); } } } /* * View */
/** * Delete a project from database * * @param User $user User * @param int $notrigger Disable triggers * @return int <0 if KO, 0 if not possible, >0 if OK */ function delete($user, $notrigger = 0) { global $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error = 'ErrorFailToDeleteLinkedContact'; //$error++; $this->db->rollback(); return 0; } } // Set fk_projet into elements to null $listoftables = array('facture' => 'fk_projet', 'propal' => 'fk_projet', 'commande' => 'fk_projet', 'facture_fourn' => 'fk_projet', 'commande_fournisseur' => 'fk_projet', 'expensereport_det' => 'fk_projet', 'contrat' => 'fk_projet', 'fichinter' => 'fk_projet', 'don' => 'fk_projet'); foreach ($listoftables as $key => $value) { $sql = "UPDATE " . MAIN_DB_PREFIX . $key . " SET " . $value . " = NULL where " . $value . " = " . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; break; } } // Delete tasks if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_time"; $sql .= " WHERE fk_task IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "projet_task WHERE fk_projet=" . $this->id . ")"; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_extrafields"; $sql .= " WHERE fk_object IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "projet_task WHERE fk_projet=" . $this->id . ")"; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task"; $sql .= " WHERE fk_projet=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } // Delete project if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet"; $sql .= " WHERE rowid=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $langs->trans("CantRemoveProject"); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_extrafields"; $sql .= " WHERE fk_object=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (empty($error)) { // We remove directory $projectref = dol_sanitizeFileName($this->ref); if ($conf->projet->dir_output) { $dir = $conf->projet->dir_output . "/" . $projectref; if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->errors[] = 'ErrorFailToDeleteDir'; $error++; } } } if (!$notrigger) { // Call trigger $result = $this->call_trigger('PROJECT_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } } if (empty($error)) { $this->db->commit(); return 1; } else { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -1; } }
/** * Delete shipment. * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) * * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ function delete() { global $conf, $langs, $user; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; if ($conf->productbatch->enabled) { require_once DOL_DOCUMENT_ROOT . '/expedition/class/expeditionbatch.class.php'; } $error = 0; $this->error = ''; // Add a protection to refuse deleting if shipment has at least one delivery $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment if (count($this->linkedObjectsIds) > 0) { $this->error = 'ErrorThereIsSomeDeliveries'; return -1; } $this->db->begin(); // Stock control if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) { require_once DOL_DOCUMENT_ROOT . "/product/stock/class/mouvementstock.class.php"; $langs->load("agenda"); // Loop on each product line to add a stock movement $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id"; $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet as cd,"; $sql .= " " . MAIN_DB_PREFIX . "expeditiondet as ed"; $sql .= " WHERE ed.fk_expedition = " . $this->id; $sql .= " AND cd.rowid = ed.fk_origin_line"; dol_syslog(get_class($this) . "::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $cpt = $this->db->num_rows($resql); for ($i = 0; $i < $cpt; $i++) { dol_syslog(get_class($this) . "::delete movement index " . $i); $obj = $this->db->fetch_object($resql); $mouvS = new MouvementStock($this->db); // we do not log origin because it will be deleted $mouvS->origin = null; // get lot/serial $lotArray = null; if ($conf->productbatch->enabled) { $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); if (!is_array($lotArray)) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (empty($lotArray)) { // no lot/serial // We increment stock of product (and sub-products) // We use warehouse selected for each line $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref)); // Price is set to 0, because we don't want to see WAP changed if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } else { // We increment stock of batches // We use warehouse selected for each line foreach ($lotArray as $lot) { $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->dluo_qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } if ($error) { break; } // break for loop incase of error } } } else { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } // delete batch expedition line if (!$error && $conf->productbatch->enabled) { if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "expeditiondet"; $sql .= " WHERE fk_expedition = " . $this->id; if ($this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "expedition"; $sql .= " WHERE rowid = " . $this->id; if ($this->db->query($sql)) { // Call trigger $result = $this->call_trigger('SHIPPING_DELETE', $user); if ($result < 0) { $error++; } // End call triggers if (!$error) { $this->db->commit(); // We delete PDFs $ref = dol_sanitizeFileName($this->ref); if (!empty($conf->expedition->dir_output)) { $dir = $conf->expedition->dir_output . '/sending/' . $ref; $file = $dir . '/' . $ref . '.pdf'; if (file_exists($file)) { if (!dol_delete_file($file)) { return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); return 0; } } } return 1; } else { $this->db->rollback(); return -1; } } else { $this->error = $this->db->lasterror() . " - sql={$sql}"; $this->db->rollback(); return -3; } } else { $this->error = $this->db->lasterror() . " - sql={$sql}"; $this->db->rollback(); return -2; } } else { $this->error = $this->db->lasterror() . " - sql={$sql}"; $this->db->rollback(); return -1; } } else { $this->db->rollback(); return -1; } }
} if ($choice == 'allfiles') { // Delete all files if ($dolibarr_main_data_root) { $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\\.lock$'); } } if ($choice == 'logfile') { $filesarray[] = array('fullname' => $filelog, 'type' => 'file'); } $count = 0; if (count($filesarray)) { foreach ($filesarray as $key => $value) { //print "x ".$filesarray[$key]['fullname']."<br>\n"; if ($filesarray[$key]['type'] == 'dir') { $count += dol_delete_dir_recursive($filesarray[$key]['fullname']); } elseif ($filesarray[$key]['type'] == 'file') { // If (file that is not logfile) or (if logfile with option logfile) if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') { $count += dol_delete_file($filesarray[$key]['fullname']); } } } // Update cachenbofdoc if (!empty($conf->ecm->enabled) && $choice == 'allfiles') { require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php'; $ecmdirstatic = new EcmDirectory($db); $result = $ecmdirstatic->refreshcachenboffile(1); } } if ($count) {
/** * Delete proposal * * @param User $user Object user that delete * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int 1 if ok, otherwise if error */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); if (!$notrigger) { // Call trigger $result = $this->call_trigger('PROPAL_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE fk_propal = " . $this->id; if ($this->db->query($sql)) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propal WHERE rowid = " . $this->id; if ($this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $error++; } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->propal->dir_output && !empty($this->ref)) { $dir = $conf->propal->dir_output . "/" . $ref; $file = $dir . "/" . $ref . ".pdf"; if (file_exists($file)) { dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = 'ErrorFailToDeleteFile'; $this->errors = array('ErrorFailToDeleteFile'); $this->db->rollback(); return 0; } } if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->errors = array('ErrorFailToDeleteDir'); $this->db->rollback(); return 0; } } } } // Removed extrafields if (!$error) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; $errorflag = -4; dol_syslog(get_class($this) . "::delete erreur " . $errorflag . " " . $this->error, LOG_ERR); } } } if (!$error) { dol_syslog(get_class($this) . "::delete " . $this->id . " by " . $user->id, LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return 0; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -3; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } else { $this->db->rollback(); return -1; } }
$modulename = preg_replace('/module_/', '', $original_file); $modulename = preg_replace('/\\-[\\d]+\\.[\\d]+.*$/', '', $modulename); // Search dir $modulename $modulenamedir = $conf->admin->dir_temp . '/' . $tmpdir . '/' . $modulename; //var_dump($modulenamedir); if (!dol_is_dir($modulenamedir)) { $modulenamedir = $conf->admin->dir_temp . '/' . $tmpdir . '/htdocs/' . $modulename; //var_dump($modulenamedir); if (!dol_is_dir($modulenamedir)) { setEventMessage($langs->trans("ErrorModuleFileSeemsToHaveAWrongFormat"), 'errors'); $error++; } } if (!$error) { //var_dump($dirins); @dol_delete_dir_recursive($dirins . '/' . $modulename); $result = dolCopyDir($modulenamedir, $dirins . '/' . $modulename, '0444', 1); if ($result <= 0) { setEventMessage($langs->trans("ErrorFailedToCopy"), 'errors'); $error++; } } } } else { $error++; } } if (!$error) { setEventMessage($langs->trans("SetupIsReadyForUse")); } }
/** * Supprime l'objet de la base * * @param User $user Utilisateur qui supprime * @return int < 0 si erreur, > 0 si ok */ function delete($user) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); // Call trigger $result = $this->call_trigger('CONTRACT_DELETE', $user); if ($result < 0) { $error++; } // End call triggers if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { dol_syslog(get_class($this) . "::delete error", LOG_ERR); $error++; } } if (!$error) { // Delete contratdet_log /* $sql = "DELETE cdl"; $sql.= " FROM ".MAIN_DB_PREFIX."contratdet_log as cdl, ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=".$this->id; */ $sql = "SELECT cdl.rowid as cdlrowid "; $sql .= " FROM " . MAIN_DB_PREFIX . "contratdet_log as cdl, " . MAIN_DB_PREFIX . "contratdet as cd"; $sql .= " WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=" . $this->id; dol_syslog(get_class($this) . "::delete contratdet_log", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->error(); $error++; } $numressql = $this->db->num_rows($resql); if (!$error && $numressql) { $tab_resql = array(); for ($i = 0; $i < $numressql; $i++) { $objresql = $this->db->fetch_object($resql); $tab_resql[] = $objresql->cdlrowid; } $this->db->free($resql); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "contratdet_log "; $sql .= " WHERE " . MAIN_DB_PREFIX . "contratdet_log.rowid IN (" . implode(",", $tab_resql) . ")"; dol_syslog(get_class($this) . "::delete contratdet_log", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->error(); $error++; } } } if (!$error) { // Delete contratdet $sql = "DELETE FROM " . MAIN_DB_PREFIX . "contratdet"; $sql .= " WHERE fk_contrat=" . $this->id; dol_syslog(get_class($this) . "::delete contratdet", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->error(); $error++; } } if (!$error) { // Delete contrat $sql = "DELETE FROM " . MAIN_DB_PREFIX . "contrat"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete contrat", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->error(); $error++; } } if (!$error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->contrat->dir_output) { $dir = $conf->contrat->dir_output . "/" . $ref; if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $error++; } } } } if (!$error) { $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } }
/** * Delete the customer order * * @param User $user User object * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <=0 if KO, >0 if OK */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('ORDER_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail if (!$error) { // Delete order details $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE fk_commande = " . $this->id; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } // Delete order $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commande WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::delete", LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $error++; } // Remove extrafields if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->deleteExtraFields(); if ($result < 0) { $error++; dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); } } // On efface le repertoire de pdf provisoire $comref = dol_sanitizeFileName($this->ref); if ($conf->commande->dir_output && !empty($this->ref)) { $dir = $conf->commande->dir_output . "/" . $comref; $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) { dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->db->rollback(); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); $this->db->rollback(); return 0; } } } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -1 * $error; } }
/** * Delete a third party from database and all its dependencies (contacts, rib...) * * @param int $id Id of third party to delete * @return int <0 if KO, 0 if nothing done, >0 if OK */ function delete($id) { global $user, $langs, $conf; require_once(DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"); dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $error = 0; // Test if child exists //$objectisused = $this->isObjectUsed($this->rowid); // TODO A reactivier if (empty($objectisused)) { require_once(DOL_DOCUMENT_ROOT . "/categories/class/categorie.class.php"); $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) if ($this->client || $this->prospect) { $toute_categs ['societe'] = $static_cat->containing($this->id, 2); } if ($this->fournisseur) { $toute_categs ['fournisseur'] = $static_cat->containing($this->id, 1); } // Remove each "Categorie" foreach ($toute_categs as $type => $categs_type) { foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } return parent::delete(); // TODO Supprimer les contacts // Remove contacts if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "socpeople"; $sql.= " WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR); } } // Update link in member table if (!$error) { $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent"; $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error .= $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR); } } // Remove ban if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib"; $sql.= " WHERE fk_soc = " . $id; dol_syslog(get_class($this) . "::Delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::Delete erreur -2 " . $this->error, LOG_ERR); } } // Removed extrafields //$result=$this->deleteExtraFields($this); //if ($result < 0) $error++; if (!$error) { // Additionnal action by hooks include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'); $hookmanager = new HookManager($this->db); $hookmanager->initHooks(array('thirdparty_extrafields')); $parameters = array(); $action = 'delete'; $reshook = $hookmanager->executeHooks('deleteThirdparty', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($hookmanager->error)) { $error++; $this->error = $hookmanager->error; } } // Remove third party if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe"; $sql.= " WHERE rowid = " . $id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete erreur -3 " . $this->error, LOG_ERR); } } if (!$error) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface = new Interfaces($this->db); $result = $interface->run_triggers('COMPANY_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { $this->db->commit(); // Delete directory $docdir = $conf->societe->multidir_output[$this->entity] . "/" . $id; if (file_exists($docdir)) { dol_delete_dir_recursive($docdir); } return 1; } else { $this->db->rollback(); return -1; } } }
/** * Delete a project from database * * @param User $user User * @param int $notrigger Disable triggers * @return int <0 if KO, 0 if not possible, >0 if OK */ function delete($user, $notrigger = 0) { global $langs, $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error = 'ErrorFailToDeleteLinkedContact'; //$error++; $this->db->rollback(); return 0; } } // Delete tasks if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_time"; $sql .= " WHERE fk_task IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "projet_task WHERE fk_projet=" . $this->id . ")"; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_extrafields"; $sql .= " WHERE fk_object IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "projet_task WHERE fk_projet=" . $this->id . ")"; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task"; $sql .= " WHERE fk_projet=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } // Delete project if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet"; $sql .= " WHERE rowid=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_extrafields"; $sql .= " WHERE fk_object=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $this->errors[] = $this->db->lasterror(); $error++; } } if (empty($error)) { // We remove directory $projectref = dol_sanitizeFileName($this->ref); if ($conf->projet->dir_output) { $dir = $conf->projet->dir_output . "/" . $projectref; if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->errors[] = 'ErrorFailToDeleteDir'; $error++; } } } if (!$notrigger) { // Call trigger $result = $this->call_trigger('PROJECT_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } } if (empty($error)) { $this->db->commit(); return 1; } else { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -1; } }
/** * Delete a third party from database and all its dependencies (contacts, rib...) * @param id id of third party to delete */ function delete($id) { global $user,$langs,$conf; require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); dol_syslog("Societe::Delete", LOG_DEBUG); $sqr = 0; // Test if child exists $listtable=array("propal","commande","facture","contrat","facture_fourn","commande_fournisseur"); $haschild=0; foreach($listtable as $table) { // Check if third party can be deleted $nb=0; $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; $sql.= " WHERE fk_soc = " . $id; $resql=$this->db->query($sql); if ($resql) { $obj=$this->db->fetch_object($resql); if ($obj->nb > 0) { $haschild+=$obj->nb; } } else { $this->error .= $this->db->lasterror(); dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR); return -1; } } if ($haschild > 0) { $this->error="ErrorRecordHasChildren"; return -1; } if ($this->db->begin()) { // Added by Matelli (see http://matelli.fr/showcases/patchs-dolibarr/fix-third-party-deleting.html) // Removing every "categorie" link with this company require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) if ($this->client || $this->prospect) { $toute_categs ['societe'] = $static_cat->containing($this->id,2); } if ($this->fournisseur) { $toute_categs ['fournisseur'] = $static_cat->containing($this->id,1); } // Remove each "Categorie" foreach ($toute_categs as $type => $categs_type) { foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } // Remove contacts $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = " . $id; dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; } else { $this->error .= $this->db->lasterror(); dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR); } // Update link in member table $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id; dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; } else { $this->error .= $this->db->lasterror(); dol_syslog("Societe::Delete erreur -1 ".$this->error, LOG_ERR); } // Remove ban $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib"; $sql.= " WHERE fk_soc = " . $id; dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; } else { $this->error = $this->db->lasterror(); dol_syslog("Societe::Delete erreur -2 ".$this->error, LOG_ERR); } // Remove third party $sql = "DELETE from ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE rowid = " . $id; dol_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; } else { $this->error = $this->db->lasterror(); dol_syslog("Societe::Delete erreur -3 ".$this->error, LOG_ERR); } if ($sqr == 4) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('COMPANY_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers $this->db->commit(); // Suppression du repertoire document $docdir = $conf->societe->dir_output . "/" . $id; if (file_exists ($docdir)) { dol_delete_dir_recursive($docdir); } return 1; } else { $this->db->rollback(); return -1; } } }
/** * Delete a product from database (if not used) * * @param int $id Product id * @return int < 0 if KO, 0 = Not possible, > 0 if OK */ function delete($id) { global $conf,$user,$langs; $error=0; if ($user->rights->produit->supprimer) { $objectisused = $this->isObjectUsed($id); if (empty($objectisused)) { $this->db->begin(); if (! $error) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PRODUCT_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } // Delete all child tables $elements = array('product_fournisseur_price','product_price','product_lang','categorie_product'); foreach($elements as $table) { if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; $sql.= " WHERE fk_product = ".$id; dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG); $result = $this->db->query($sql); if (! $result) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); } } } // Delete product if (! $error) { $sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product"; $sqlz.= " WHERE rowid = ".$id; dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG); $resultz = $this->db->query($sqlz); if ( ! $resultz ) { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); } } if (! $error) { // We remove directory $ref = dol_sanitizeFileName($this->ref); if ($conf->product->dir_output) { $dir = $conf->product->dir_output . "/" . $ref; if (file_exists($dir)) { $res=@dol_delete_dir_recursive($dir); if (! $res) { $this->error='ErrorFailToDeleteDir'; $error++; } } } } if (! $error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { $this->error = "ErrorRecordHasChildren"; return 0; } } return 0; }
/** * Delete task from database * * @param User $user User that delete * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $this->db->begin(); if ($this->hasChildren() > 0) { dol_syslog(get_class($this) . "::delete Can't delete record as it has some child", LOG_WARNING); $this->error = 'ErrorRecordHasChildren'; $this->db->rollback(); return 0; } if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error = 'ErrorFailToDeleteLinkedContact'; //$error++; $this->db->rollback(); return 0; } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_time"; $sql .= " WHERE fk_task=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task_extrafields"; $sql .= " WHERE fk_object=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (!$error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task"; $sql .= " WHERE rowid=" . $this->id; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } if (!$error) { if (!$notrigger) { // Call trigger $result = $this->call_trigger('TASK_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } } // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); $this->error .= $this->error ? ', ' . $errmsg : $errmsg; } $this->db->rollback(); return -1 * $error; } else { //Delete associated link file if ($conf->projet->dir_output) { $projectstatic = new Project($this->db); $projectstatic->fetch($this->fk_project); $dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($projectstatic->ref) . '/' . dol_sanitizeFileName($this->id); dol_syslog(get_class($this) . "::delete dir=" . $dir, LOG_DEBUG); if (file_exists($dir)) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $res = @dol_delete_dir_recursive($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->db->rollback(); return 0; } } } $this->db->commit(); return 1; } }
/** * Delete the customer order * * @param User $user User object * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <=0 if KO, >0 if OK */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; $error = 0; $this->db->begin(); if (!$error && !$notrigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"; $interface = new Interfaces($this->db); $result = $interface->run_triggers('ORDER_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { // Delete order details $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE fk_commande = " . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql); if (!$this->db->query($sql)) { dol_syslog(get_class($this) . "::delete error", LOG_ERR); $error++; } // Delete order $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commande WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); if (!$this->db->query($sql)) { dol_syslog(get_class($this) . "::delete error", LOG_ERR); $error++; } // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) { $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $error++; } // On efface le repertoire de pdf provisoire $comref = dol_sanitizeFileName($this->ref); if ($conf->commande->dir_output) { $dir = $conf->commande->dir_output . "/" . $comref; $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) { dol_delete_preview($this); if (!dol_delete_file($file, 0, 0, 0, $this)) { $this->error = $langs->trans("ErrorCanNotDeleteFile", $file); $this->db->rollback(); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); $this->db->rollback(); return 0; } } } } if (!$error) { dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -1; } }