Commit 2ac00ac7 authored by jaapjansma's avatar jaapjansma
Browse files

Added form processor action to delete attachments.

parent c8cc21b0
Version 1.0.11
--------------
* Added form processor action to delete attachments.
Version 1.0.10
--------------
......
......@@ -217,15 +217,6 @@ class CRM_Expenses_Form_Expense extends CRM_Core_Form {
);
}
}
else {
/**
* No point looping 100 times if there aren't any more.
* This assumes the array is continuous and doesn't skip array keys,
* but (a) where would it be doing that, and (b) it would have caused
* problems before anyway if there were skipped keys.
*/
break;
}
}
}
......
......@@ -66,7 +66,9 @@ class CRM_Expenses_Utils_File {
$sql = "DELETE FROM civicrm_file where id IN ( $deleteFiles )";
CRM_Core_DAO::executeQuery($sql);
rmdir($config->customFileUploadDir .$entitySubtype .DIRECTORY_SEPARATOR . $entityID);
if ($fileID === null) {
rmdir($config->customFileUploadDir . $entitySubtype . DIRECTORY_SEPARATOR . $entityID);
}
}
$isDeleted = TRUE;
}
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Expenses;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\OptionGroupByNameSpecification;
use Civi\ActionProvider\Parameter\OptionGroupSpecification;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use Civi\ActionProvider\Utils\CustomField;
use CRM_Expenses_ExtensionUtil as E;
class DeleteExpenseAttachment extends AbstractAction {
/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
*
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$id = $parameters->getParameter('id');
$file_id = $parameters->getParameter('file_id');
\CRM_Expenses_Utils_File::deleteEntityFile(\CRM_Expenses_DAO_Expense::$_tableName, $id, 'Expense', null, $file_id);
}
/**
* Returns the specification of the configuration options for the actual
* action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag([]);
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag([
new Specification('id', 'Integer', E::ts("Expense ID"), true),
new Specification('file_id', 'Integer', E::ts("Attachment ID (File ID)"), true),
]);
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag([]);
}
}
......@@ -98,6 +98,12 @@ class Expenses implements CompilerPassInterface {
E::ts('Expense: Delete expense line'),
[AbstractAction::DATA_MANIPULATION_TAG],
]);
$actionTypeFactoryDefinition->addMethodCall('addAction', [
'expense_delete_attachment',
'Civi\ActionProvider\Action\Expenses\DeleteExpenseAttachment',
E::ts('Expense: Delete Attachment'),
[AbstractAction::DATA_MANIPULATION_TAG],
]);
}
}
......
......@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/extensions/expenses/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-11-19</releaseDate>
<version>1.0.10</version>
<releaseDate>2020-11-27</releaseDate>
<version>1.0.11</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.0</ver>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment