Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
shahed Posted December 2, 2022 Posted December 2, 2022 I'm working on a plugin that use upload form field in two areas. first there is a plugin setting and with this plugin also comes widget feature that also uses upload form. both works, but in time of uninstall the plugin, the stored files must also be removed from server. now for upload form with plugin setting, I created an uninstall.php with this code: if ( isset( \IPS\Settings::i()->plugin_uploadForm ) ) { \IPS\File::get( 'core_Theme', \IPS\Settings::i()->plugin_uploadForm )->delete(); } this code works and stored file in plugin setting will delete after uninstall. however how can i do the same for widgets? I use this for upload form itself in widgets: if ( ! empty( $this->out['widget_uploadForm'] ) ) { $image = \IPS\File::get( 'core_Theme', $this->out['widget_uploadForm'] ); } $form->add( new \IPS\Helpers\Form\Upload('widget_uploadForm', $image, FALSE, array( 'multiple' => false, 'storageExtension' => 'core_Theme', 'image' => true ), null, null, null, 'widget_uploadForm_toggle' ) ); Â
Adriano Faria Posted December 2, 2022 Posted December 2, 2022 You should be using your own file storage extension to point to the right files. Stuart Silvester 1
shahed Posted December 2, 2022 Author Posted December 2, 2022 (edited) 44 minutes ago, Adriano Faria said: You should be using your own file storage extension to point to the right files. Not sure can be done in plugins. not sure even it is a right approach but I tried to extend \IPS\core\extensions\core\FileStorage\Theme with hook and add the delete code but didn't work. /** * Delete all stored files * * @return void */ public function delete() { \IPS\File::get( 'core_Theme', $this->configuration['widget_uploadForm'] )->delete(); return parent::delete(); }  36 minutes ago, DawPi said: So you must convert it into an app. 🙂 Yes that would be ideal, but it is also time consuming to start over 🙃 Edited December 2, 2022 by shahed
Adriano Faria Posted December 2, 2022 Posted December 2, 2022 Just now, shahed said: Not sure can be done in plugins. 👇 34 minutes ago, DawPi said: So you must convert it into an app. 🙂 Â
shahed Posted December 2, 2022 Author Posted December 2, 2022 2 minutes ago, Adriano Faria said: 👇 So you must convert it into an app. 🙂 So there is no way to do this in plugins?
Stuart Silvester Posted December 2, 2022 Posted December 2, 2022 1 hour ago, shahed said: So there is no way to do this in plugins? No, you must use your own storage handler if you're uploading files. A plugin using another storage handler for files would cause it to be rejected if it were submitted to the Marketplace.
Daniel F Posted December 2, 2022 Posted December 2, 2022 Stu is correct, in 99,9999% we'll reject it, BUT it's also OK to use an existing storage handler like core_Theme in few cases like uploading a watermark image, logo or any other use cases where it's not worth to have an own file storage extension and database table and all the other logic, as long as you take care of ALL the logic like removing the file when the plugin is removed, updating the path when the files were moved or the storage handler was changed. We have also logic in place ( see Application::uploadSettings() ) to register the settings so that the framework takes care of everything. shahed 1
Recommended Posts