/** * Delete the customer order * @param user User object * @return int <=0 if KO, >0 if OK */ function delete($user) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php"; $err = 0; $this->db->begin(); // Delete order details $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE fk_commande = " . $this->id; dol_syslog("Commande::delete sql=" . $sql); if (!$this->db->query($sql)) { dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } // Delete order $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commande WHERE rowid = " . $this->id; dol_syslog("Commande::delete sql=" . $sql); if (!$this->db->query($sql)) { dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } // Delete linked object // TODO deplacer dans le common $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element"; $sql .= " WHERE fk_target = " . $this->id; $sql .= " AND targettype = '" . $this->element . "'"; dol_syslog("Commande::delete sql=" . $sql); if (!$this->db->query($sql)) { dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { dol_syslog("CustomerOrder::delete error", LOG_ERR); $err++; } // 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)) { commande_delete_preview($this->db, $this->id, $this->ref); if (!dol_delete_file($file)) { $this->error = $langs->trans("ErrorCanNotDeleteFile", $file); $this->db->rollback(); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); $this->db->rollback(); return 0; } } } if ($err == 0) { // 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 $this->db->commit(); return 1; } else { $this->db->rollback(); return -1; } }
} if ($id || $ref) { //print 'Fetch '.$id.' or '.$ref.'<br>'; $result=$object_instance->fetch($id,$ref); //print $result.'<br>'; if ($result == 0) // Not found but no error { // Clean of orphelins directories are done into repair.php print '<tr><td colspan="2">'; print 'Delete orphelins file '.$file['fullname'].'<br>'; if (GETPOST('purge') == 2) { dol_delete_file($file['fullname'],1,1,1); dol_delete_dir(dirname($file['fullname']),1); } print "</td></tr>"; } else if ($result < 0) print 'Error in '.get_class($object_instance).'.fetch of id'.$id.' ref='.$ref.', result='.$result.'<br>'; } } } } } print '</table>'; if (empty($actiondone))
/** * Delete a project from database * @param user User * @param 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."/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; } } $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task"; $sql.= " WHERE fk_projet=".$this->id; dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet"; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { // We remove directory $projectref = dol_sanitizeFileName($this->ref); if ($conf->projet->dir_output) { $dir = $conf->projet->dir_output . "/" . $projectref ; $file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf"; if (file_exists($file)) { //project_delete_preview($this->db, $this->id, $this->ref); if (!dol_delete_file($file)) { $this->error='ErrorFailToDeleteFile'; $this->db->rollback(); return 0; } } if (file_exists($dir)) { $res=@dol_delete_dir($dir); if (! $res) { $this->error='ErrorFailToDeleteDir'; $this->db->rollback(); return 0; } } } if (! $notrigger) { // Call triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PROJECT_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // End call triggers } dol_syslog("Project::delete sql=".$sql, LOG_DEBUG); $this->db->commit(); return 1; } else { $this->error=$this->db->lasterror(); dol_syslog("Project::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } }
/** * Delete object on database and/or on disk * * @param User $user User that delete * @param int $mode 'all'=delete all, 'databaseonly'=only database entry, 'fileonly' (not implemented) * @return int <0 if KO, >0 if OK */ function delete($user, $mode = 'all') { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $error = 0; $result = 0; if ($mode != 'databaseonly') { $relativepath = $this->getRelativePath(1); } // Ex: dir1/dir2/dir3 dol_syslog(get_class($this) . "::delete remove directory id=" . $this->id . " mode=" . $mode . ($mode == 'databaseonly' ? '' : ' relativepath=' . $relativepath)); $this->db->begin(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "ecm_directories"; $sql .= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql); $resql = $this->db->query($sql); if (!$resql) { $this->db->rollback(); $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); return -2; } if ($mode != 'databaseonly') { $file = $conf->ecm->dir_output . "/" . $relativepath; $result = @dol_delete_dir($file); } if ($result || !@is_dir(dol_osencode($file))) { $this->db->commit(); } else { $this->error = 'ErrorFailToDeleteDir'; dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); $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('MYECMDIR_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } if (!$error) { return 1; } else { return -1; } }
/** * Delete object * * @return void */ function delete() { global $conf, $langs, $user; require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $this->db->begin(); $error = 0; $sql = "DELETE FROM " . MAIN_DB_PREFIX . "livraisondet"; $sql .= " WHERE fk_livraison = " . $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 . "livraison"; $sql .= " WHERE rowid = " . $this->id; if ($this->db->query($sql)) { $this->db->commit(); // On efface le repertoire de pdf provisoire $ref = dol_sanitizeFileName($this->ref); if (!empty($conf->expedition->dir_output)) { $dir = $conf->expedition->dir_output . '/receipt/' . $ref; $file = $dir . '/' . $ref . '.pdf'; if (file_exists($file)) { if (!dol_delete_file($file)) { return 0; } } if (file_exists($dir)) { if (!dol_delete_dir($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); return 0; } } } // Call triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('DELIVERY_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // End call triggers 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; } }
/** * Delete intervetnion * @param user Object user who deletes */ function delete($user) { global $conf; require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); $error=0; $this->db->begin(); // Delete linked object $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; $sql.= " WHERE fk_target = ".$this->id; $sql.= " AND targettype = '".$this->element."'"; dol_syslog("Fichinter::delete sql=".$sql); if (! $this->db->query($sql) ) { dol_syslog("Fichinter::delete error", LOG_ERR); $error++; } // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error='ErrorFailToDeleteLinkedContact'; $error++; } if ($err > 0) { $this->db->rollback(); return -1; } $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; $sql.= " WHERE fk_fichinter = ".$this->id; dol_syslog("Fichinter::delete sql=".$sql); 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 sql=".$sql); 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)) { fichinter_delete_preview($this->db, $this->id, $this->ref); if (!dol_delete_file($file)) { $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir($dir)) { $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); return 0; } } } $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; } }
/** * Delete shipping */ function delete() { global $conf, $langs, $user; require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql.= " WHERE fk_expedition = ".$this->id; if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; $sql.= " WHERE fk_target = ".$this->id; $sql.= " AND targettype = '".$this->element."'"; if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition"; $sql.= " WHERE rowid = ".$this->id; if ( $this->db->query($sql) ) { $this->db->commit(); // On efface le repertoire de pdf provisoire $expref = dol_sanitizeFileName($this->ref); if ($conf->expedition->dir_output) { $dir = $conf->expedition->dir_output . "/" . $expref ; $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file)) { $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir($dir)) { $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); return 0; } } } // Call triggers include_once(DOL_DOCUMENT_ROOT."/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('SHIPPING_DELETE',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // End call triggers // TODO il faut incrementer le stock si on supprime une expedition validee 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; } }
/** * 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; }
/** * Supprime la fiche */ function delete() { require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet"; $sql.= " WHERE fk_livraison = ".$this->id; if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; $sql.= " WHERE fk_target = ".$this->id; $sql.= " AND targettype = '".$this->element."'"; if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; $sql.= " WHERE rowid = ".$this->id; if ( $this->db->query($sql) ) { $this->db->commit(); // On efface le repertoire de pdf provisoire $livref = dol_sanitizeFileName($this->ref); if ($conf->livraison->dir_output) { $dir = $conf->livraison->dir_output . "/" . $livref ; $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; if (file_exists($file)) { if (!dol_delete_file($file)) { $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); return 0; } } if (file_exists($dir)) { if (!dol_delete_dir($dir)) { $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); return 0; } } } 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; } }
/** * \brief Efface propal * \param user Objet du user qui efface */ function delete($user, $notrigger = 0) { global $conf, $langs; require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php"; $error = 0; $this->db->begin(); $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 contacts $res = $this->delete_linked_contact(); if ($res < 0) { $this->error = 'ErrorFailToDeleteLinkedContact'; $this->db->rollback(); return 0; } // We remove directory $propalref = dol_sanitizeFileName($this->ref); if ($conf->propale->dir_output) { $dir = $conf->propale->dir_output . "/" . $propalref; $file = $conf->propale->dir_output . "/" . $propalref . "/" . $propalref . ".pdf"; if (file_exists($file)) { propale_delete_preview($this->db, $this->id, $this->ref); if (!dol_delete_file($file)) { $this->error = 'ErrorFailToDeleteFile'; $this->db->rollback(); return 0; } } if (file_exists($dir)) { $res = @dol_delete_dir($dir); if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->db->rollback(); return 0; } } } if (!$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) { dol_syslog("Suppression de la proposition {$this->id} par {$user->id}", LOG_DEBUG); $this->db->commit(); return 1; } else { $this->db->rollback(); return 0; } } else { $this->db->rollback(); return -2; } } else { $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'; $error = 0; // 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(); if ($conf->productbatch->enabled) { require_once DOL_DOCUMENT_ROOT . '/expedition/class/expeditionbatch.class.php'; if (ExpeditionLigneBatch::deletefromexp($this->db, $this->id) < 0) { $error++; $this->errors[] = "Error " . $this->db->lasterror(); } } // 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"; $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 sql=" . $sql); $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); //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin =& $this; // We decrement 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, $obj->subprice, $langs->trans("ShipmentDeletedInDolibarr", $this->ref)); if ($result < 0) { $error++; break; } } } else { $error++; } } 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 triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('SHIPPING_DELETE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // 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($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; } }