How to create a Pi image programmatically [on hold]

I would like to create images for a raspberry pi which have my software preinstalled. In order to do so, it would be have image creation integrated in our continuous deployment process.

  • How can I create or customize a raspberry pi image from within a CI script?

I am not specific on what CD system it is, because I did not set up CD yet. If there is some CD tool which can do this, this may as well be the reason for me to choose it. Other than that, I believe that any CD system should be able to run a bash script, so tools which work in bash will solve my problem.

Programmatically removing photos from icloud

Recently I centralised all my photos from various sources to use iCloud so I can access them on my iPhone, mac and have them saved/full control. However in the process I inadvertently created a lot of duplicates. I made some python scripts to analyse and tag the duplicates, so that now I have a list of file paths to images on my mac. For example, one such file path looks like this:

Example 1 /Users/nicholasjenkins/Pictures/Photos Library.photoslibrary/Masters/2019/03/12/20190312-210251/11923478-a5bb-4727-a65e-079c1b774f82.jpg

Example 2 /Users/nicholasjenkins/Pictures/Photos Library.photoslibrary/Masters/2019/04/18/20190418-081743/IMG_4223.JPG

The problem now is if I try to delete these directly, icloud will eventually download them back.

Is there some way I can programmatically delete these images, or put them into an album (for easy deleting in the Photos app)?

Magento API to create and assign voucher codes programmatically

We have a situation where we need to create voucher codes dynamically and assign it to a set of rules. Since I’m new to magneto programming I’m not aware of using the REST API and all.

Could someone suggest how to do this, Is there an alternative way of accessing it via Python and PostgreSQL?

Also, we need this voucher codes to be sent to the customers on their first order, Do you know what all tables are involved in this?

Awaiting your suggestions. Thanks in advance.

Magento 2 : Add product to cart programmatically does not populate quote item id in validate method

How to add product to cart programmatically in Magento 2.2.0 ?

I have tried below code but when I do not get Quote item id in Validate method of below file.

\Magento\AdvancedSalesRule\Model\Rule\Condition\Product.php 

Code:

protected $  formKey;    protected $  cart; protected $  product;  public function __construct( \Magento\Framework\App\Action\Context $  context, \Magento\Framework\Data\Form\FormKey $  formKey, \Magento\Checkout\Model\Cart $  cart, \Magento\Catalog\Model\Product $  product, array $  data = []) {     $  this->formKey = $  formKey;     $  this->cart = $  cart;     $  this->product = $  product;           parent::__construct($  context); }  public function execute()  {    $  productId = 32;   $  params = array(                 'form_key' => $  this->formKey->getFormKey(),                 'product' => $  productId,                  'qty'   => 2                             );                    $  _product = $  this->product->load($  productId);        $  this->cart->addProduct($  _product, $  params);      $  this->cart->save();  } 

Sales Rule Validate Method Code:

File: \Magento\AdvancedSalesRule\Model\Rule\Condition\Product.php

Method:

public function validate(\Magento\Framework\Model\AbstractModel $  model)     {         //@todo reimplement this method when is fixed MAGETWO-5713         /** @var \Magento\Catalog\Model\Product $  product */         $  product = $  model->getProduct();         if (!$  product instanceof \Magento\Catalog\Model\Product) {             $  product = $  this->productRepository->getById($  model->getProductId());         }          if ($  model instanceof \Magento\Quote\Model\Quote\Item) {             die($  model->getItemId()); //NULL 

Thanks

Programmatically creating folders in lists results in invisible or incorrectly named folders

So far I’ve found two ways to create a folder via pnpjs-wrapped API calls. One, which is

SPList.rootFolder.folders.add("Name") 

works well for a document library, but, when used in a list, it results in having an invisible folder that you can access via URL, but can’t see in the list. Second way is

SPList.items.add({ Title: "Name", ContentTypeId: "0x0120" }) 

and it results in actually having two entities created in the list. One is a list item (in items collection) with the given name, which can be seen in the list and used to access the folder. Second is the actual folder (in folders collection), but its name is like #_.000 where # stands for the list item ID. And when I access the new folder I see the #_.000 name in breadcrumbs and in the URL, instead of given name.

In this case the item properties are like:

AssignedToId: null AssignedToStringId: null Attachments: false AuthorId: 10 Body: null Category: null Comment: null ComplianceAssetId: null ContentTypeId: "0x0120005B3A6725E6545840A09FDD3C367BC6FA" Created: "2019-06-21T04:54:58Z" EditorId: 10 FileSystemObjectType: 1 ForeignKeyId: null GUID: "b4ffd422-19e3-40ae-b58d-4c56280b159b" ID: 49 Id: 49 IssueStatus: null Line: null Modified: "2019-06-21T04:54:58Z" OData__UIVersionString: "1.0" Priority: null RelatedIssuesId: [] ServerRedirectedEmbedUri: null ServerRedirectedEmbedUrl: "" TaskDueDate: null Title: "MtFolder" V3Comments: null odata.editLink: "Web/Lists(guid'783d01c4-7dca-4ab2-aa7b-ca2e4c89283d')/Items(49)" odata.etag: ""1"" odata.id: "debe0338-9d3a-4770-94b0-aa54d92df311" odata.type: "SP.Data.LookupListListItem" 

The folder properties are like

Exists: true IsWOPIEnabled: false ItemCount: 0 Name: "49_.000" ProgID: null ServerRelativeUrl: "/Lists/LookupList/49_.000" TimeCreated: "2019-06-21T04:54:58Z" TimeLastModified: "2019-06-21T04:54:58Z" UniqueId: "a29e5616-a82d-475a-b649-94f926add5ab" WelcomePage: "" odata.editLink: "Web/GetFolderByServerRelativePath(decodedurl='/Lists/LookupList/49_.000')" odata.id: "https://contoso.sharepoint.com/_api/Web/GetFolderByServerRelativePath(decodedurl='/Lists/LookupList/49_.000')" odata.type: "SP.Folder" 

So I need that folder’s Name property to be the same as the item’s Title. This is not the case, obviously. But I can’t find any properties to link the folder with the item so that I could, for example, fetch the folder based on the item’s properties and update its name. There is something that looks like a link, however, in the item entity itself. For example, when handling the item.add() promise’s result, I can try:

.then(result => {     return result.item.folder.update({         Name: folderName     }); }) 

But this only returns 204 no content result, as if the folder wasn’t saved yet. Yet, it can be opened just a moment later with the same URL the folder.update() method tried to post the update info. I could probably wait and call the item.folder.update() a moment later, but what moment exactly? Don’t see a way to hook into the chain the moment the folder was saved.

So, this is my investigation so far.

Is there a way to hook into the result handling not for the new item, but for the attached folder? Or is there another method or a correct set of arguments for folders.add() or items.add() methods to create both the “folder-item” and the actual corresponding folder with correct name?

Programmatically create media file

I’m trying to programmatically create a media file. Here’s what I got so far:

$  file_data = file_get_contents('http://www.africau.edu/images/default/sample.pdf');  $  file = file_save_data($  file_data, 'public://3010.pdf', FILE_EXISTS_REPLACE);  $  media = Media::create([   'bundle' => 'file',   'uid' => '0',   'field_media_file' => [     'target_id' => $  file->id(),   ], ]);  $  media->setName('Hello')   ->setPublished(TRUE)   ->save(); 

Unfortunately this returns me the following error and the media file doesn’t get saved:

Error: Call to a member function getSource() on null in Drupal\media\Entity\Media->getSource() (line 138 of core/modules/media/src/Entity/Media.php).

What am I doing wrong? How can I fix this error?

Trying to programmatically redirect

I’m trying to redirect users in Drupal 8 as I was used to do in Drupal 7 with a simple drupal_goto().

This is my code.

$  response = new \Symfony\Component\HttpFoundation\RedirectResponse(\Drupal::url($  url_redirect)); $  response->send(); 

Executing it, I get the following error:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route http://mydomain.es/participar?utm_source=RTB&utm_campaign=&utm_medium=banner&utm_term=1 does not exist.

The alias /participar exists. What am I doing wrong?

How to programmatically create forums and containers (not forum topics)?

I need to create containers and forums using rules.

If I use the action “Create new entity” -> “Taxonomy term” I got that by default the new term created is treated as a forum, not a container. How can I either convert it to be a container or, using a custom PHP script, create directly a container ?

I tought it was some variable of the term to make the difference, but if I use Devel over both containers or forums they looks the same.

I found http://www.unibia.com/unibianet/drupal/how-create-drupal-forums-and-containers-programmatically but it refers to D6, and in D7 I don’t know what to pass as $ form and $ form_state to the forum_form_container() function.

How do I programmatically set contextual filters?

I need to set a contextual filter programmatically and almost every view I have will have this filter. However, some wont and will have other contextual filters instead.

I have tried following the examples in here but this will just set the first argument to be my filter value regardless of what field is it for.

In views_pre_build I get the keyed arguments list under $ view->argument and can do ->setArgument() but this doesn’t change the set of results.

Is there an easier way of setting a specific contextual filter?