Пример #1
0
 private static function removeFile($imageFileId, $moduleName, $fieldName)
 {
     $file = $imageFileId ? file_load($imageFileId) : FALSE;
     if ($file) {
         file_usage_delete($file, $moduleName, $fieldName, $file->fid);
         file_delete($file);
     }
     return $file;
 }
Пример #2
0
function removePicture($FID, $moduleName)
{
    $f = file_load($FID);
    if ($f != null) {
        file_usage_delete($f, "CROMA - {$moduleName}");
        file_delete($f);
    } else {
        drupal_set_message('File does not exist!', 'error');
    }
}
Пример #3
0
/**
 * Delete operation for a component or submission.
 *
 * @param $component
 *   A Webform component array.
 * @param $value
 *   An array of information containing the submission result, directly
 *   correlating to the webform_submitted_data database schema.
 */
function _webform_delete_component($component, $value)
{
    // Delete corresponding files when a submission is deleted.
    if (!empty($value[0]) && ($file = webform_get_file($value[0]))) {
        file_usage_delete($file, 'webform');
        file_delete($file);
    }
}
Пример #4
0
 public function approveFileSubmission($id)
 {
     $nexcloud = filedepot_nexcloud();
     $query = db_query("SELECT * FROM {filedepot_filesubmissions} WHERE id=:fid", array('fid' => $id));
     $rec = $query->fetchObject();
     $newfid = 0;
     // @TODO: Check if there have been multiple submission requests for the same file and thus have same new version #
     if ($rec->version == 1) {
         $private_destination = "private://filedepot/{$rec->cid}/";
         // Best to call file_prepare_directory() - even if you believe directory exists
         file_prepare_directory($private_destination, FILE_CREATE_DIRECTORY);
         $file = file_load($rec->drupal_fid);
         $private_uri = $private_destination . $rec->fname;
         $file = file_move($file, $private_uri, FILE_EXISTS_RENAME);
         // Get name of new file in case it was renamed after the file_move()
         list($scheme, $target) = explode('://', $file->uri, 2);
         $filename = str_replace("filedepot/{$rec->cid}/", '', $target);
         if (isset($rec->title) and !empty($rec->title)) {
             $filetitle = $rec->title;
         } else {
             $filetitle = $rec->fname;
         }
         // Load the node for the folder and then update the file usage table
         $nid = db_query("SELECT nid FROM {filedepot_categories} WHERE cid=:cid", array(':cid' => $rec->cid))->fetchField();
         $node = node_load($nid);
         file_usage_add($file, 'filedepot', 'node', $node->nid);
         // Remove the record for the core file module from the file usage table
         file_usage_delete($file, 'file');
         $query = db_insert('filedepot_files');
         $query->fields(array('cid', 'fname', 'title', 'description', 'version', 'drupal_fid', 'size', 'mimetype', 'submitter', 'status', 'date', 'version_ctl', 'extension'));
         $query->values(array('cid' => $rec->cid, 'fname' => $filename, 'title' => $filetitle, 'description' => $rec->description, 'version' => $rec->version, 'drupal_fid' => $file->fid, 'size' => $file->filesize, 'mimetype' => $file->filemime, 'submitter' => $rec->submitter, 'status' => 1, 'date' => $rec->date, 'version_ctl' => $rec->version_ctl, 'extension' => $rec->extension));
         $query->execute();
         // Get fileid for the new file record
         $newfid = db_query_range("SELECT fid FROM {filedepot_files} WHERE cid=:cid AND submitter=:uid ORDER BY fid DESC", 0, 1, array(':cid' => $rec->cid, ':uid' => $rec->submitter))->fetchField();
         $query = db_insert('filedepot_fileversions');
         $query->fields(array('fid', 'fname', 'drupal_fid', 'version', 'notes', 'size', 'date', 'uid', 'status'));
         $query->values(array('fid' => $newfid, 'fname' => $filename, 'drupal_fid' => $file->fid, 'version' => 1, 'notes' => $rec->version_note, 'size' => $file->filesize, 'date' => time(), 'uid' => $rec->submitter, 'status' => 1));
         $query->execute();
         if (!empty($rec->tags) and $this->checkPermission($rec->cid, 'view', 0, FALSE)) {
             $nexcloud->update_tags($newfid, $rec->tags);
         }
     }
     if ($newfid > 0) {
         if ($rec->notify == 1) {
             filedepot_sendNotification($newfid, FILEDEPOT_NOTIFY_APPROVED);
         }
         db_delete('filedepot_filesubmissions')->condition('id', $id)->execute();
         // Send out notifications of update to all subscribed users
         filedepot_sendNotification($newfid, FILEDEPOT_NOTIFY_NEWFILE);
         // Update related folders last_modified_date
         $workspaceParentFolder = filedepot_getTopLevelParent($rec->cid);
         filedepot_updateFolderLastModified($workspaceParentFolder);
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $package = Package::load($form_state->getValue('package_id'));
     $shipment = Shipment::load($package->sid);
     $methods = \Drupal::moduleHandler()->invokeAll('uc_fulfillment_method');
     if (isset($methods[$shipment->shipping_method]['cancel']) && function_exists($methods[$shipment->shipping_method]['cancel'])) {
         $result = call_user_func($methods[$shipment->shipping_method]['cancel'], $shipment->tracking_number, array($package->tracking_number));
         if ($result) {
             db_update('uc_packages')->fields(array('sid' => NULL, 'label_image' => NULL, 'tracking_number' => NULL))->condition('package_id', $package->package_id)->execute();
             if (isset($package->label_image)) {
                 file_usage_delete($package->label_image, 'uc_fulfillment', 'package', $package->package_id);
                 file_delete($package->label_image);
                 unset($package->label_image);
             }
             unset($shipment->packages[$package->package_id]);
             if (!count($shipment->packages)) {
                 $shipment->delete();
             }
         }
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Пример #6
0
 /**
  * Deletes this package.
  */
 public function delete()
 {
     db_delete('uc_packages')->condition('package_id', $this->package_id)->execute();
     db_delete('uc_packaged_products')->condition('package_id', $this->package_id)->execute();
     if (isset($this->label_image)) {
         file_usage_delete($this->label_image, 'uc_fulfillment', 'package', $this->package_id);
         file_delete($this->label_image);
     }
     drupal_set_message(t('Package @id has been deleted.', ['@id' => $this->package_id]));
 }