17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
18 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
53 public static function execute($settings, &$state)
56 if (empty($settings[
'file_path']))
return FALSE;
57 if (!is_readable($settings[
'file_path'])) {
58 trigger_localised_error(
'CORE0276', E_USER_WARNING, htmlentities($settings[
'file_path'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
62 if (empty($state[
'asset'])) {
64 if (empty($state[
'assetid'])) {
67 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
71 if (is_null($state[
'asset']))
return FALSE;
72 if (!($state[
'asset'] instanceof
File)) {
73 trigger_error(
'Unable to replace file content for a '.$state[
'asset']->
type().
' asset', E_USER_NOTICE);
77 $edit_fns = $state[
'asset']->getEditFns();
78 $lock_acquired = ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($state[
'asset']->
id,
'attributes') == 1);
81 'name' => basename($settings[
'file_path']),
82 'tmp_name' => $settings[
'file_path'],
83 'non_uploaded_file' => TRUE,
86 $res = $edit_fns->processFileUpload($state[
'asset'], $o,
'', $info, FALSE);
88 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($state[
'asset']->
id,
'attributes');
90 return $res ? $info : FALSE;
105 public static function getInterface($settings, $prefix, $write_access=FALSE)
107 $file_path = array_get_index($settings,
'file_path',
'');
110 text_box($prefix.
'[file_path]', $file_path, 40);
112 echo
'<b>'.$file_path.
'</b>';
114 $value = ob_get_clean();
115 $res = translate(
'trigger_replace_file', $value);
117 $res .=
'<p class="sq-backend-warning"><b>'.translate(
'trigger_replace_file_type_warning').
'</b></p>';
137 if (!empty($request_data[
'file_path'])) {
138 $settings[
'file_path'] = $request_data[
'file_path'];