本文整理汇总了PHP中dol_delete_dir_recursive函数的典型用法代码示例。如果您正苦于以下问题:PHP dol_delete_dir_recursive函数的具体用法?PHP dol_delete_dir_recursive怎么用?PHP dol_delete_dir_recursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dol_delete_dir_recursive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDolCompressUnCompress
/**
* 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));
}
示例2: clear_attached_files
/**
* 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"]);
}
示例3: is_uploaded_file
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";
}
示例4: delete
/**
* 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();
//.........这里部分代码省略.........
示例5: delete
//.........这里部分代码省略.........
$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;
}
}
示例6: delete
/**
* 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;
//.........这里部分代码省略.........
示例7: delete
/**
* 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;
}
}
示例8: delete
//.........这里部分代码省略.........
// 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;
}
示例9: delete
/**
* 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;
}
}
示例10: migrate_delete_old_dir
/**
* 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;
}
示例11: dol_delete_dir_recursive
/**
* 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;
}
示例12: purgeFiles
/**
* 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
}
示例13: delete
/**
* 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;
}
}
示例14: delete
//.........这里部分代码省略.........
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;
}
示例15: delete
/**
* 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;
}
}