Magento 2 How to remove custom attribute at time of uninstalling the module using data patch? - magento2

Using data patch, created one product attribute. I wants to remove that attribute when extension is unstalled. Generally we are using Uninstall.php but my question was that, how can we uninstall it by using data patch?
Thanks in advance.

Create Uninstall. php inside setup directory from module directory.
write your logic over there to remove the attribute.
so when you will run
bin/ magento module:uninstall [MODULE NAME]
then your Uninstall script will run and code will be executed.

Related

Magento 2 cannot delete module bceause ClassReader.php class not found

Magento 2.3.3
I have the module Swissup/Core installed. I had some problems and removed it. After I removed the module, (deleted from composer directory) I can no longer use Magento 2. I get the following when trying to run any commands.
Updating modules:
Class Swissup\Core\Console\Command\ModuleCommand does not exist
In ClassReader.php line 19:
Class Swissup\Core\Console\Command\ModuleCommand does not exist
I checked and there is no attribute created by this module. I checked source_model, frontend_model, backend_model.
I removed all references to the module in composer.json, composer.lock.
I removed all references to it in composer files in vendor directory.
I removed cache, pub/static, generated, and var/cache.
I also did a recursive search across the entire site for any file containing the word swissup or Swissup. None were found.
I also removed the module from the setup table.
I also checked/removed any reference in core_config_data
Still, I cannot use the system and this error persists.
I cleared all composer cache
I also as a test, put invalid credentials in app/etc/env.php to see if the database would cause an issue, but it didn't, I still get this error.
I don't understand, how, if i'm sure by doing a grep in every file a part of Magento and no such reference exists, that this error is raised. There must be some file stored outside of the Magento filesystem. It cannot be a database issue, because the database cannot connect due to me inputting invalid values.
I highly recommend you delete Modules by first running bin/magento module:disable Vendor_Namespace followed by composer remove vendor/package instead of deleting it in the file system.
Do you have a git repository on which you can reset? Does composer install generate any errors?
This can happen if there is the module entry in the setup_module table.
If the module you want to delete is Vendor_Module, then search for the module in setup_module table:
SELECT * FROM setup_module WHERE module = "Vendor_Module";
If you find the module in setup_module table, then you need to remove that from the table:
DELETE FROM setup_module WHERE module = "Vendor_Module";

PowerShell : How to Get Indentity information from .appx package path?

I'm trying to write a powershell script where
A- Try to install the package from the Path.
B- If the package is already installed, try to uninstall the old version
C- ReTry Step A.
To do the step B, I've tried to get AppxPackageManifest with
$Manifests = Get-AppxPackageManifest -Package $DeveloperPackagePath.Name
(where DeveloperPackagePath is the full path to the package file.)
Because I need the Identity information to remove the application.
But $Manifests is empty.
Path is valid, and App package is valid too.
Is there a way to get the Identity information with the path to the package?
From what I see in the MS docs the cmdlet that gets the manifests works only for installed packages, not for their source.
What you want can be done, but you need to work more the get the identity. First you need to use makeappx.exe to extract the package in a temporary location and then you can parse the XML file to get the identiy.

php auto update script files

How can I create script version update function like in datalife engine cms ? For example customer has version 1.0 and I have created version 1.5. And I want the user to be able to update the script version directly from admin panel. How can I do it ?
Notice: This is my own solution.
#Guilherme Soster has provided the basics on how to do it. However if you do not want to do it yourself you can check my php-updater solution. You can define what you want to add (overwrite or add) and delete as well as scripts you want to run in a YAML file.
well, basically you'll have to store the user system's version in some config file or database and have a server where you keep the latest version of your scripts.
Then when the user request to check for updates (or each time that the software runs) your update script should hit the server and get the latest version number, compare it with the one your user has stored and if the user one is inferior the script should download the new scripts from the server (usually to a temp directory). Now all that the update script has to do is remove the old scripts and move the new ones to the directories where they belong. Finally the update script should update the version in the confi file/database.

Sugarcrm: remove file on uprades via manifest.php

How can I remove file on loading upgrade of some sugarcrm module?
I can write 'copy' in upgrade section of manifest.php to copy new file. But how can I remove old (useless) file upon install of a newer version of the same module?
You can use the scripts/post_install.php script and insert the logic there to remove the file.
Any file that is installed via a 'copy' command should be automatically removed/replaced upon uninstall. There are no further commands needed to make it work. Backups of any files/directories that are replaced (if there are any) are kept in the upload directory.

TYPO3 install from dummy and source

I want to install typo3 using dummy and source packages, how is it done ? i unpack both tar.gz into each own directory or mix them into one single directory ?
Even creating ENABLE_INSTALL_TOOL file and giving permissions, the instalation is is still locked.
Thank's in advance
There is also source+dummy package available, download it and unzip. Downloading separate dummy or source packs makes sense only when you want to add missing element or update the sources.
http://typo3.org/download/