How can I manually enable/disable a module? - drupal

I am trying to automate the process of enabling/disabling the module for my Drupal-8 website. As far I could understand from the docs, Drupal saves the info related to the modules in the table config inside its database (drupal/sites/default/files/.ht.sqlite).
Before enabling the module snowflake, I'm not unable to see any entry for it, but after manually enabling it through http://website/admin/modules, I can see this entry at the end of the table.
collection name data
---------- -------------- --------------------------------------------------------------------------------------------------------------------
snowflakes.set a:5:{s:8:"langcode";s:2:"en";s:7:"enabled";b:1;s:13:"exclude_admin";b:1;s:13:"toggle_button";b:0;s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"gWu2_RT_6nrFtvXiYNQFgZm17c3CEXCxrb-JnsCFKmM";}}
Is there any file/function that is generating entries like this for similar modules? Once I'm able to figure this out, it might help me automate the process of enabling a module without manually clicking the checkbox from http://website/admin/modules every time.

you can use drush to enable/disable modules.
See https://www.drush.org/latest/
Example (install):
drush pm:install "mymodule"
Unninstall
drush pm:uninstall "mymodule"
replace "mymodule" with the module machine name.

Related

Drupal 8 to publish files

I'm trying to create a simple CMS to ingest contents and publish files. I'm using Drupal 8 with Feeds module to read xml files from a directory and it works fine.
I can't figure it out how I can take the information saved in my custom content and publish them to a file in another directory.
Anyone can help?
Thx
Luca
Could you create a view to render the desired output for the content you're after and then use the Views data export module to export that view into a file?
I note the following:
This module also exposes a drush command that can execute the view and
save its results to a file.
drush views-data-export [view-name] [display-id] [output-file]
If you can do it with Drush you can do it with PHP.
So potentially you could write hooks to manage the export of files based on the activity of the feed. E.g. The hook_ENTITY_TYPE_insert would allow you to perform logic when a node of a particular content type is created.

Unable to delete uploaded XML file on Drupal 8.5

I have created a media type that accepts XML files and saves them to a custom publicly accessible location on the server.
Ideally I would like the file to be overwritten when the exact same file is uploaded. This does not happen, instead it creates a new file and adds a number on the end. I have "Create new Revision" turned off.
To get around this issue I thought I could just delete the file via the CMS. The uploaded file has status of "Permanent" and is used 0 places. I know the cron job cleans up files for you, but when I run the cron the file in question is still there. I figure it's because the file is set to permanent, but I don't see a way to flip this to temporary.
Any help is much appeciated.
There is a setting nested away in the file system settings, which lets you configure it to remove (or not removed) orphaned files. If drush isn't removing them despite having no usages recorded, I'd check this option isn't ticked.
The temporary and permanent status are used for storing temporary files during the upload/save process, so I wouldn't tinker with those too much.
If you fancy making the form yourself using the form API, then you can save the file programmatically using the FILE_EXISTS_REPLACE parameter.
https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_save_data/8.5.x

Rules requiring manual run in Alfresco

I have a rule on a folder which executes a JavaScript code whenever a new document enters the folder. The issue is the rule doesn't run automatically when a document enters the folder, but I have to run it manually.
I have tried running the script in background too. If I put a rule on update, that works automatically. The problem is with creation or entering of new documents in the folder. I am using Alfresco community 4.2.f share.
Please advise.
Thanks.
I cannot recreate this problem in Alfresco Community Edition 4.2.f. Make sure that:
All of the rules are enabled
The person putting the document in folder1 has permissions to create new documents in Folder 2.
The criteria for the rules are valid
The script in Folder 2 is not actually running. The best way to validate this is by turning on the server-side JavaScript debugger by editing $TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/log4j.properties and setting log4j.logger.org.alfresco.repo.web.scripts.AlfrescoRhinoScriptDebugger=on
Alternatively, for #4, you could change to an out-of-the-box action, like another Move that would move the document to Folder 3. That's what my test does. If that works for you like it does for me, you would be able to narrow down your troubleshooting to a problem with the custom script.
when running scripts fired by rules you can't rely on search for the new doc since indexing isn't finished when the script runs. If SOLR is configured as search engine, indexing is executed async from outside the repository every 15 secs. You already may know that you can get the name from the script node?

Remove rows from the node table

Some nodes are displayed in the content list even if they don't exist anymore.
When I click on them I get an empty page.
I was wondering if I can just delete the rows from the "Node" table or I should clean something else.
thanks
First: on the administer page, go to performance, and click on the clear all caches button. If it doesn't solve your problem, then try disabling every contrib, and see if the problem still exists. If not, try enabling them one-by-one, and you will know which contrib made the problem. Report it to the module's issue queue.
If disabling modules doesn't solve your problem, download drush. Try deleting the node directly with node_delete. Example (if the wrong node's nid is 3):
drush php-eval 'node_delete(3);'
If you are not familiar with the command line, you can do the same with this little PHP file (put it into the Drupal's root):
include './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
node_delete(3);
If it doesn't work then make a backup from your database, delete the node from the node table and go through every node-related table (which has a nid column), and delete the related entries.
This may not be your problem but:
You don't want to delete rows directly from the database. You'll end up with no way of knowing what shape your database is in afterwards. Node IDs exist in many tables and nodes are distributed through more than one table.
Go through the nodeapi and use the Drupal framework because that's what it's meant for! The node api will treat your database schema correctly.
See:
http://api.drupal.org/api/function/node_delete/6
So if you know the node ID, you can call node_delete.
Note that (depending on your Drupal permissions) you will likely need to be operating as a user with permissions to delete nodes -- such as user-1 rather than the default anonymous user. You can do this by pre-appending your node_delete() call with,
global $user;
$user = user_load(1);
You may also experience a timeout if deleting many nodes and invoking the PHP file via a browser. One fix for this is to invoke the PHP file via the command line (if you have shell access). For example,
php -f custom-script.php
Again, if you are deleting many nodes, you may also run out of memory. Increase the PHP memory limit for your script's invocation like this,
php -f custom-script.php -d memory_limit=512M
This works against my tests with Drupal 6. Note that you may also be able to fix the server timeout issue by setting an explicit timeout in the custom-script.php.

How to store Blobs in Drupal?

I want to store PDF and Image files in Drupal. By default Drupal seems to store binary/uploaded files into the filesystem. I want to to be able to store files so that - I can have workflows, metadata, IP information and URL aliases?
Update, am still stuck at how to create URL aliases for files on the file system. Drupal only seems to allow creating URL aliases to node content.
The simplest solution for Drupal is to use the Upload module, which is in core. The upload module allows you attach files to nodes. As you note, they are stored in the filesystem.
If you want to get more complex, you can build your own content types through the web interface by using the CCK family of modules (such as the filefield module or the imagefield module). Your files are still stored on the filesystem.
You could use CCK to create the metadata field you want.
You could use the workflow or rules modules to implement workflow.
IP information is recorded automatically by Drupal's logging module (either the database logging module, which logs to the database, or the syslog module, which logs to syslog).
URL aliases for nodes are available in core Drupal by enabling the path module (or download the pathauto module for automatic creation of aliases).
I tried Drupal's Upload module, FileField as well as uploading files using FCKEditor - I prefer the last one - it is closer to my specific scenario.
Creating an alias to the file will likely require some custom code.
It's not possible to simply create an alias using the Administer > Site building > URL aliases screen. I tried inserting a record with
insert into url_alias (src, dst) values ('sites/default/files/ChipotleArt.JPG', 'here-is-the-file.jpg');
That still didn't work. So, you will really likely need to write some custom code.

Resources