Question about deleting or renaming file
#1
Question 
Hi,

as I'm developing the plugin I've got a question. The plugin will create an empty file (with touch) and I want to remove it when the plugin is deactived or uninstalled.

But, it's safe to delete any file inside a plugin? Is it better to rename it and let the user delete the file? None of both?

What would be the best way (& safe) to delete it? unlink or any other MyBB's funtion?

Thanks for your time
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply
#2
We do not know your plugin and we do not know the content of the file you're writing. So how should anyone be able to decide whether to delete or rename your file!? Smile

Why using a flat file at all? Is it possible to save this content in the database instead away from filesystem?

In general, a plugin being uninstalled must absolutely recover the original state!
Uninstallation means there is nothing kept at all (neither DB records or files) and the forum and filesystem is in state as of never seen this plugin before.


[ExiTuS]
[Image: logo_wernicke_8040.png]
MyBB Forum + innovative full-responsive Theme
Live-Escape-Game-Forum
Reply
#3
in practice, uninstalling doesn't remove files. using unlink could be dangerous
users should be informed about the files & their locations (can be through readme.txt file)
Reply
#4
Exitus said it. Plugins that uninstall should remove all traces of themselves EXCEPT for the files that were uploaded with it when the plugin was first uploaded into the server.

I would absolutely have it remove that file upon uninstallation. It will work perfectly fine on most servers, but there will be some where the chmod settings are odd and won't allow the file to be deleted from PHP. In which case, a simple notice of "hey, we tried to remove XYZ file, but the chmod settings are incorrect. Please remove this manually if you wish."

But as said above, using the database is a good idea if you can. You can do it easily in the settings table if you're okay with it being accessible in the admin CP (and it sounds like you're just creating a blank file for some sort of flag). You could also create a new table and add your flag there, although that's somewhat of a tacky solution. Smile

Also, I'll add real quick, what exactly is this touch file being used for?
Reply
#5
Hi,

answers following:
(2020-04-03, 07:29 PM)[ExiTuS] Wrote: So how should anyone be able to decide whether to delete or rename your file!? Smile

No, the plugins creates it and deletes/renames it at uninstalling.

(2020-04-03, 07:29 PM)[ExiTuS] Wrote: Why using a flat file at all? Is it possible to save this content in the database instead away from filesystem?
Let me explain it a little more, the plugin shows a modal window when you activate it, and to be sure that the modal window doesn't show up more than once, the plugin creates an empty file in activation, and check for it afterwards. If is present, modal window is hidden.

My plugin doesn't create any table in the DB, and create one only to this I thought it was too much work for a simple modal window.

(2020-04-03, 07:29 PM)[ExiTuS] Wrote: In general, a plugin being uninstalled must absolutely recover the original state!
Uninstallation means there is nothing kept at all (neither DB records or files) and the forum and filesystem is in state as of never seen this plugin before.

[ExiTuS]
Yeah, was aware of that, thanks.

(2020-04-04, 05:28 AM).m. Wrote: in practice, uninstalling doesn't remove files. using unlink could be dangerous
users should be informed about the files & their locations (can be through readme.txt file)
That's the point of my question, to be sure I could use it or not. Any other way I could do it or I should ask the installer of the plugin to manual delete it?

(2020-04-04, 05:53 AM)Darth Apple Wrote: But as said above, using the database is a good idea if you can. You can do it easily in the settings table if you're okay with it being accessible in the admin CP (and it sounds like you're just creating a blank file for some sort of flag). You could also create a new table and add your flag there, although that's somewhat of a tacky solution. Smile

Also, I'll add real quick, what exactly is this touch file being used for?

As I said to ExiTuS: "the plugin shows a modal window when you activate it, and to be sure that the modal window doesn't show up more than once, the plugin creates an empty file in activation, and check for it afterwards. If is present, modal window is hidden.

My plugin doesn't create any table in the DB, and create one only to this I thought it was too much work for a simple modal window."

I know maybe it's not the best solution, but this is why I'm asking for advice Wink

	global $mybb;
	$warnfile = MYBB_ROOT . 'cache/modal_once.txt';
	if (!file_exists($warnfile)){
		touch(MYBB_ROOT . 'cache/modal_once.txt');
		chmod(MYBB_ROOT . 'cache/modal_once.txt', 0444);
		echo '<style>/* The Modal (background) */
(...)
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply
#6
using unlink is not suggested. personally I prefer informing user about the files.
Reply
#7
Hi,

thanks again .m., now I could do what I wanted without creating any file. It was a bad idea I had... Undecided
I don't answer questions about localhost forums or forums without URL, I'm not a seer.  Cool
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)