Programmatically delete a webform submission by sid without first loading it

Drupal 8 project has a 2 webforms:

  • Webform “ABC”
  • Webform “123”

Explanation of the process:

When Webform “ABC” is submitted, a new “node” is created and the “Sid” used to create this node is recorded inside a “text” field (field_submission_sid) on this created node.

Now, when Webform “123” is loaded, the value of (field_submission_sid) is populated inside a ‘text’ element (submission_to_delete)… and when the Webform “123” is submitted, a custom handler will delete the submission of sid value = (submission_to_delete)

The custom handler is working but I believe there is a better solution… so please I need your help ?

Custom handler:

<?php  namespace Drupal\custom_module\Plugin\WebformHandler;  use Drupal\Core\Session\AccountInterface; use Drupal\Core\Serialization\Yaml; use Drupal\Core\Form\FormStateInterface;  use Drupal\node\Entity\Node;  use Drupal\webform\WebformInterface; use Drupal\webform\Plugin\WebformHandlerBase; use Drupal\webform\webformSubmissionInterface; use Drupal\webform\Entity\WebformSubmission;   /**  * Delete a 'webform Submission' using its "SID" retrieved from a populated webform submission value.  *  * @WebformHandler(  *   id = "Delete a webform Submission using its sid",  *   label = @Translation("Delete a webform Submission using its sid"),  *   category = @Translation("Entity Delete"),  *   description = @Translation("Delete a webform Submission using its sid retrieved from a populated webform submission valu"),  *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,  *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,  *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED,  * )  */  class DeleteSidWebformHandler extends WebformHandlerBase {    /**    * {@inheritdoc}    */    // Function to be fired while submitting the Webform.   public function submitForm(array &$  form, FormStateInterface $  form_state, WebformSubmissionInterface $  webform_submission) {     // Get an array of the values from the submission.     $  values = $  webform_submission->getData();      // Load 'submission' object from webform-submission populated data.      //get (SID) from (submission_to_delete) text element available on the webform     $  sid = $  values["submission_to_delete"];     $  webform_submission = \Drupal\webform\Entity\WebformSubmission::load($  sid);      //Delete the Submission     $  webform_submission->delete();  } } 

If you notice, I am loading the submission first then i am deleting it…

is there a better solution where I can delete the submission directly without first have to load it ? maybe something like $ webform_submission = \Drupal\webform\Entity\WebformSubmission::delete(submission_to_delete);

Thank you,

Delete remote dir and transfer replacement dir from local

I have a remote VM (Ubuntu 18) that will be used in production.

ssh keys are discouraged, so I transfer files using scp.

I want a script that does two things.

  1. deletes a directory from the remote VM (For which I can use ssh)

  2. transfer a directory from local to remote, for which I can use scp.

However, I am not quite sure how to combine the two into one script. If I stay in ssh, then the scp command will be run from the remote box (right?). If I exit ssh, I exit the scrip altogether.

How to delete a date and time tab in setting to prevent user from changing it

Please understand me about my broken English

Hi i’m a student in South Korea. I’m making a Lenovo tablet a perfect education device that work quite restrictedly to study hard!!!!!

To do that, i have to prevent user from chaning system time in setting (Because changing system time is a easy way to pass my blocking application setting.)

So i’m trying to delete date and time menu in setting. (to keep Only auto time) enter image description here

By an experience of deleting a guest mode in system, I think i should use Buildprop app, but i don’t know what i should delete and change a system. Plz help me! Of course it’s okay not using Buildprop!

a rooted device and android versions is nougat, 7.1.1 I’m sorry for using broken English and thanks for reading this. Have a good day!

Delete database accidentally by a bash, rescue please

My developer committed a huge mistake and we cannot find our mongo database anyone in the server. Rescue please!!!

He logged into the server, and saved the following shell under ~/crontab/mongod_back.sh:

enter image description here

And then he run ./mongod_back.sh, then there were lots of permission denied, then he did Ctrl+C. Then the server shut down automatically.

He tried to restart the server, then he got an grub error:

enter image description here

He then contacted AliCloud, the engineer connected the disk to another working server, so that he could check the disk. Then, he realized that some folders have gone, including /data/ where the mongodb is!!!

1) We just don’t understand how the bash could destroy the disk including /data/;

2) And of cause, is it possible to get the /data/ back?

PS: he did not take snapshot of the disk before.

How to keep a substring and delete rest of string using Python

I am beginner in Python and I am web scraping a webpage and I get the following most of the time with the word “available” always there.

Your   product is    available   and costs 10.00€ 

I cannot count the empty spaces and remove word by word, so how can I keep only the word available and delete the rest of it?

And have something like

Available

thank you

Delete source files and copy randomly selected folder contents using batch


  • Delete all files of .ext in source folder
  • Randomly select folder either by naming pattern or any other means.
  • Then copy all *.ext files from randomly selected folder to source folder [if easier can just copy whole folder contents].
  • To be run as a batch file in a windows environment.

Example batch script (still have no idea how to code): delete-and-copy.cmd

call del C:\test\source\*.ext call Copy *.ext C:\test\library\group_%RANDOM% [COUNT=Folders %RANDOM%=Select1(%COUNT%)] "C:\test\source\" 

OR another not working suggestion:

call del C:\test\source\*.ext @echo off setlocal EnableDelayedExpansion cd C:\test\library\ set n=0 for %%f in (*.ext) do (    set /A n+=1    set "folder[!n!]=%%f" ) set /A "rand=(n*%random%)/Count_1_%_10" copy "!group_[%rand%]!/*.ext" C:\test\source\ 

Folder Layout

C:\test\source\delete-and-copy.cmd C:\test\source\  (150 *.ext files plus few others) C:\test\library\group_01\ (150 *.ext Files) C:\test\library\group_02\ (150 *.ext Files) C:\test\library\group_03\ (etc..) C:\test\library\group_04\ C:\test\library\group_05\ C:\test\library\group_06\ C:\test\library\group_07\ C:\test\library\group_08\ C:\test\library\group_09\ (...) C:\test\library\group_10\ (127 *.ext Files) 

Current Research:

  • SU – How do I select a random file in a folder? – with further reading

  • SU – Move folders using wildcard

  • SU – Can I copy multiple files from single folder to multiple folder in windows with batch file?

  • SU – Batch file to copy a file at random to another folder

  • SO – Need to create a batch file to select one random file from a folder and copy to another folder

  • SO – Delete all files of specific type (extension) recursively down a directory using a batch file

How can I delete an inaccessible folder on Windows 10?

I have a folder on one of my hard drives, P:\csharp\aperture\keystone\src\Keystone, which I want to delete but cannot. I have tried numerous different ways to change/reset permissions and I still cannot delete this folder.

PS P:\csharp\aperture> whoami azuread\mikelloyd  PS P:\csharp\aperture> rm -Recurse -Force .\keystone\ rm : Cannot remove item P:\csharp\aperture\keystone\src: The directory is not empty. At line:1 char:1 + rm -Recurse -Force .\keystone\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : WriteError: (src:DirectoryInfo) [Remove-Item], IOException     + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand rm : Cannot remove item P:\csharp\aperture\keystone\: The directory is not empty. At line:1 char:1 + rm -Recurse -Force .\keystone\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : WriteError: (P:\csharp\aperture\keystone\:DirectoryInfo) [Remove-Item], IOException     + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand  PS P:\csharp\aperture> rmdir .\keystone\  Confirm The item at P:\csharp\aperture\keystone\ has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue? [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A rmdir : Access to the path 'P:\csharp\aperture\keystone\src\Keystone' is denied. At line:1 char:1 + rmdir .\keystone\ + ~~~~~~~~~~~~~~~~~     + CategoryInfo          : PermissionDenied: (P:\csharp\aperture\keystone\:String) [Remove-Item], UnauthorizedAccessException     + FullyQualifiedErrorId : RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand  PS P:\csharp\aperture> icacls.exe .\keystone\ /reset /T processed file: .\keystone\ processed file: .\keystone\src .\keystone\src\Keystone: Access is denied. Successfully processed 2 files; Failed processing 1 files 

I don’t have read privileges.

no read privileges

It can’t show the owner:

no owner

If I try to change the owner, I don’t have permission to view or edit the object:

enter image description here

What is really strange is that I created the folder with my user, so I should be the effective owner. I have tried to delete the user as Administrator, but I can’t do that either. I can’t even delete the folder as NT\System:

P:\csharp\aperture\keystone\src>whoami /user  USER INFORMATION ----------------  User Name           SID =================== ======== nt authority\system S-1-5-18  P:\csharp\aperture\keystone\src>rmdir /S Keystone Keystone, Are you sure (Y/N)? Y Access is denied. 

nt system authority

How can I delete this folder that I created?

How to delete code-igniter (PHP) session files from cantos tmp folder

I am using code-igniter php framework and it created lot of ( 3.60 Lac ) session files at /tmp folder now my server is down due to no more space.

session file name is look like : ci_sessionfffb1692761c84c4e5506919c8a4d966 (ci_sessionXXXXXXXXXXXXXXXX)

enter image description here

How to delete only those ci_session files using command for centOS ?