Skip to content

Instantly share code, notes, and snippets.

View jalogut's full-sized avatar

Juan Alonso jalogut

View GitHub Profile
@jalogut
jalogut / or-example.php
Last active January 28, 2016 08:30
SearchCriteria OR Example for Magento 2
<?php
declare(strict_types = 1);
namespace Training5\VendorRepository\Controller\Test;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
#!/bin/bash
# Run this script whenever you need to update the logrotate configuration for your website.
# You can do that in 3 ways:
# a) Execute this script Manually
# b) Schedule it on a cronjob
# c) Execute it every time before the rotation takes place. Call this script on first line of your logrotate "/etc/cron.daily/logrotate"
# -e = stop if something fails
# -u = fail if you try to use an unset variable.
set -eu
@jalogut
jalogut / phpstorm-init-vcs-roots.php
Created July 13, 2017 12:48
Script to automatically init all vcs roots inside a project
#!/usr/bin/env php
<?php
class PhpStormVcsRoots
{
private $rootPath = ".";
private $maxDepth = "4";
private $configPath = ".idea/vcs.xml";
public function updateVcsRootsConfig()
@jalogut
jalogut / magento2-config-dump-only-specific.php
Last active March 1, 2020 21:41
Magento 2 code to dump only specific system settings when executing app:config:dump
// module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="VendorName_ModuleName" setup_version="0.0.1" >
<sequence>
<module name="Magento_Config"/>
</sequence>
</module>
</config>
// di.xml
@jalogut
jalogut / magento2-config-dump-skip-system.xml
Last active September 27, 2018 15:37
Magento 2 skip dumping the whole core_config_data when using app:config:dump
<!-- module.xml -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="VendorName_ModuleName" setup_version="0.0.1" >
<sequence>
<module name="Magento_Config"/>
</sequence>
</module>
</config>
<!-- di.xml -->
@jalogut
jalogut / External Tools.xml
Last active September 21, 2018 08:49
PHPStorm External Tools for Magento 2 (~/Library/Preferences/<product name><version number>/tools/External\ Tools.xml)
<!-- Local Setups -->
<toolSet name="External Tools">
<tool name="mg2 clear cache" showInMainMenu="true" showInEditor="false" showInProject="false" showInSearchPopup="false" disabled="false" useConsole="true" showConsoleOnStdOut="false" showConsoleOnStdErr="false" synchronizeAfterRun="false">
<exec>
<option name="COMMAND" value="bin/magento" />
<option name="PARAMETERS" value="cache:clean" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/magento" />
</exec>
</tool>
<tool name="mg2 generation flush" description="Flushs generated code like factories and proxies" showInMainMenu="true" showInEditor="false" showInProject="false" showInSearchPopup="false" disabled="false" useConsole="true" showConsoleOnStdOut="false" showConsoleOnStdErr="false" synchronizeAfterRun="true">
@jalogut
jalogut / .my.cnf
Last active March 15, 2018 12:16
Mysql ~/.my.cnf to fix MYSQL has gone away issue
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# https://expressionengine.com/blog/mysql-5.7-server-os-x-has-gone-away
interactive_timeout = 300
wait_timeout = 300
# https://github.com/Homebrew/legacy-homebrew/issues/47335
table_open_cache = 250
@jalogut
jalogut / di.xml
Created March 18, 2018 13:01
Fix eavSetup in Compiled mode
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- We create our own virtual class because original Magento\Setup\Module\DataSetup cannot be instantiated when compilation enabled. -->
<virtualType name="Vendor\Module\Setup\Module\DataSetup" type="Magento\Setup\Module\DataSetup">
<arguments>
<argument name="context" xsi:type="object">Magento\Framework\Module\Setup\Context</argument>
</arguments>
</virtualType>
<virtualType name="Vendor\Module\Eav\Setup\EavSetup" type="Magento\Eav\Setup\EavSetup">
<arguments>
<argument name="setup" xsi:type="object">Vendor\Module\Setup\Module\DataSetup</argument>
@jalogut
jalogut / nginx-magento2-multiwebsite.conf
Last active April 4, 2018 12:44
Set up multiple websites or stores with nginx
map $http_host $MAGE_RUN_CODE {
hostnames; # indicates that values can be hostnames with prefix or suffix mask.
default base;
*.ch ch;
*.de de;
*.at at;
}
server {
@jalogut
jalogut / magento2-deployer-plus-jenkinsfile.groovy
Last active June 8, 2018 14:12
magento2-deployer-plus Jenkinsfild pipeline
node {
// Clean workspace before doing anything
deleteDir()
def hostStage
def deployStatus
try {
stage ('Preparations') {
if (BRANCH_NAME == 'develop') {