28. Apr 2022 |

SQL stuff

UPDATE `core_config_data` SET `value` = replace(value, 'oldtext.ee', 'newtext.ee');

1. Apr 2022 |

ps aux with grep

Very good ps aux overview can be found on Linode website.

grep stands for global regular expression print

grep by default is case sensitive. Add -i to make it case insensitive.

ps aux | grep -i "robert" | grep -i "vscode" – by such piping you can narrow down the search step by step.

If kill does not then add kill -9 <pid> (source).

history | grep “git commit” | grep “something”

Regular expressions in grep and on youtube basic Grep and Regex and the most useful DO guide

ps aux | grep -i "...be.t"  – simple pattern match.

ps aux | grep -P -i "^weekend"  – add -P to get perl compatible regular expressions to work

ps aux | grep -i '^weekend.*product' – lines that start with weekend and contains word product.

To see your proccesses then ps ux is enough.

22. Feb 2022 |

Magento REST API – Specified request cannot be processed and Class does not exist

Class \Vendor\ModuleName\Api\TestInterface does not exist

During development move things from local-src + symlink to app/code/{vendor}/{modulename} so that namespace and folder structure could match.

If you are using interfaces in your module then this is also true that you need to use full path reference in PHPdoc instead of use import and reference.

Both worked for me

Specified request cannot be processed

rest/V1/test/ – V in version needs to be capital letter (also in webapi.xml).

And just useful tip that you can extract interface out of existing class.

8. Feb 2022 |

How to install Magento on local nginx

Not a tutorial but notes for myself

Creating vitual host (tutorial), user rights in /var/www/ (rights to group, user to group) and here even better guidance.

Before Magento I usually set up default WordPress installation first to test if php works well, database is ok and nginx has started.

Useful command: sudo mv wordpress/* /var/www/html – how to move content of whole directory somewhere

Order of Magento installation

As it is in the documentation. But you can be sure something goes wrong.

  1. Composer create-project to get the metapackage: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento/
  2. Permissions, also sudo chown -R rbrt:www-data .  It is occasionally needed later too.
  3. php bin/magento install... (this is very long command you can find here)*
  4. If you need then you can also install sample data: php bin/magento sampledata:deploy (takes very long time) and you may also need to run php bin/magento catalog:images:resize to get the images shown in the store.

Clean Magento install with sample data is 1.4 GB, 109 thousand files (so creating and deleting may take long time), 410 database tables. For comparison, clean WordPress is just 12 tables.

*For this step you need ElasticSearch running. sudo systemctl start elasticsearchInstructions can be found here on Digital Ocean website.

Nginx conf

/etc/nginx/ -> nginx.conf

Restart: sudo systemctl reload nginx

Get ownership
sudo chown -R robert /var/www/html
Give ownership back to the webserver system user www-data.
sudo chown -R www-data:www-data /var/www/html

Conf

Create .conf to /etc/nginx/sites-available

Symlink conf to sites-enabled

sudo ln -s /etc/nginx/sites-available/abc.conf /etc/nginx/sites-enabled/

Symlinked conf updates itself automatically

Add custom domain to hosts file

sudo code /etc/hosts --user-data-dir

Rights

This did not work well…

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/www

Set file permissions before Magento installation

https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions – but I am not shure what the before means.

Disable 2FA

php bin/magento module:disable Magento_TwoFactorAuth

Because otherwise you can not log into admin (because mail server does not work)

Post installation commands

php bin/magento setup:di:compile
php bin/magento indexer:reindex or php bin/magento indexer:status
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento module:disable Magento_Csp
php bin/magento module:disable Magento_TwoFactorAuth

6. Feb 2022 |

Eestiblogid.eu – my hobby project

To improve my coding skills in a safe environment I should start working more on the hobby project eestiblogid.eu. I currently has ~150 weekly users so if I mess something up it should not be huge problem 🙂

Currently it is just 2 small services which I call Reader and Writer.

Reader is a small independent PHP application which basically reads the given list of XML files (RSS feeds) every hour and checks if there is anything new. If there is something new then entry is made to the database. Rules for detecting “new” are very primitive. Therefore, quite often you can see duplicate posts. Reader will probably stay as it is. I should just make the code cleaner from time to time, implement some logging etc.

Writer is also a small php application (using Twig for templating and Bootstrap for styling) to generate views for the front end and reading data from database.

There is no admin panel at the moment. I go straight to the database to edit things (remove, deactivate, delete etc).

Up next

What I would like to do now is to prepare REST endpoints for the front end. Probably it will be php backend built with Laravel or Lumen using their Eloquent ORM.

Front end should be built with React together with admin views for myself (using JWT for authentication).

I try to keep you informed of the progress under this eestiblogid.eu tag.

Update 09.03.22

It has been less than a month. I have not done anything (too busy with my internship). But, meanwhile, Lumen has become extinct (not being developed any further) and I am most probably considering GraphQL (with Lighthouse) insead of REST. So probably it is good that I have not done much.

14. Jan 2022 |

Solution: Composer dependencies require a PHP version…

Sorry. This is stupid advice here. Please don’t follow it 🙂 If your dependencies require different PHP version then change PHP version or change the dependency (to different version). Simple.

I tried to initiate new Laravel project and ran into an error. I have been using php 8.0.2 but Magento needed 7.4 so I switched to 7.4 and now I am having this issue with Composer 🙂

Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27.

PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version “>= 8.0.2”. You are running 7.4.27. in C:\Users\john\AppData\Roaming\Composer\vendor\composer\platform_check.php on line 24

How to get the value of PHP_VERSION_ID

In terminal run php -a and then var_dump(PHP_VERSION_ID);  You should see the id. To exit you can use ctrl+c.

How to solve it

Open the platform_check.php file and update the PHP_VERSION_ID to what you currently have.

Not sure if it is the best practice but it works.

14. Jan 2022 |

IADB IT-süsteemide arendus – 5. semestri lõpp

Lõputöö ja ettevõttepraktika on veel jäänud.

5. semester on nüüd lõppenud. Tundub uskumatu aga kooli lõpetamiseks on teha veel ainult Ettevõttepraktika (ICY0017, 24 EAP) ja lõputöö (6 EAP). Praktikakohta mul veel ei ole nagu siit võib näha aga otsin.

Sel semestril sai tehtud 7 ainet. 4 neist kohustuslikud, 3 valikained. Kokku 36 EAPd. Alljärgnevalt tehtud ained arvestuse saamise järjekorras.

Valikust võib aru saada, et valikuga on tegelikult üsna kitsas käes ja arvestades minu huvisid – teha valmis midagi tehnilist, praktilist ja töötavat – on vaba ja valikainete osas… no ei olegi ju midagi.

Alljärgnevalt kasutan aegajalt sõna “moodulisse”, mis tähendab, et õppekava on jaotatud mooduliteks. Kooli lõpetamiseks peab saama kõikides moodulites nõutud punktid täis ja siis validki lihtsalt midagi, mis seal moodulis on parajasti pakkumisel.

Füüsika mittefüüsikutele (NSO0160, 3 EAP, kohustuslik)

Õppejõud emeriitprofessor Sirje Keevallik. Arvestuse saamiseks on vaja teha kaks kontrolltööd, mille tulemuste summa annaks > 50%. Kontrolltööd sisaldavad (vähem) ülesannete lahendamist ja (rohkem) teooriat. Kuigi füüsika võib tunduda hirmutav, siis tegelikult ei ole seda ainet põhjust karta.

Kui kontrolltööd ebaõnnestuvad, siis oli lisaks veel eksami võimalus.

Veebihalduskeskkonnad (ICD0020, 6 EAP, valikaine)

Kuna mul oli vaja valikainete moodulisse millegi eest 6 EAP saada, siis sügissemestrit arvestades olin kahe vahel – inglise keel või see aine. Jäin selle juurde.

Õppejõud Meelis Antoi, kes ühtlasi on IADB õppekava programmijuht. Minu jaoks oli see ilmselt kõige lihtsam aine seni. Sisuks oli teha localhostis ühesuguse välimusega veebileht Drupalis, Joomlas ja WordPressis. Seejärel anti kooli poolt igale tudengile üks VPS, kuhu oli installitud Debian 9 ning omaltpoolt oli vaja installida php, mysql, apache ja enda localhostis valmistatud WordPressi leht sinna ümber tõsta. Pärast “läbijalutuse” formaadis tööde ettenäitamist  oligi arvestus käes.

VPSi andmine kooli poolt oli muidugi tore üllatus. Ma arvan, et mingi pisikese Ubuntuga purgi, mis oleks avalik, võiks kõik tudengid 1. semestri esimesel päeval saada endale haldamiseks 🙂

Automaattestimine (ICD0004, 3 EAP, programmerimise moodul)

Arvestatud sain 9. detsembril. Tegemis on valikainega programmeerimise moodulis. Õppejõud German Mumma. Väga kasulik aine ja hea õppejõud, nii et kindlasti soovitan. Töökeel on Java ning õppetöö väga praktiline – ehk korrektsel viisil testide kirjutamine + giti korrektne kasutamine. Teemadeks TDD, unit testing, integration testing, UI testing (Selenide). Testmise õppimiseks kasutasime Restful-booker API, OpenWeatherMap API, The Internet UI vaateid.

Koormustestimist ja performance testimist kahjuks ainesse ei mahtunud aga see huvitanuks mind ka.

Pisut raskemaks muutis aine asjaolu, et mul on Maveniga vähe kokkupuudet (nt konfi kirjutamine ja sõltuvuste valimine/haldamine) ja Javat seni üldse suhteliselt vähe kirjutanud aga sai hakkama ikka. Toetava ainena Märt Kalmo ainele oli sellest kindlasti palju abi.

Keskkonnakaitse ja säästev areng (YTG0060, 3 EAP, kohustuslik)

Õppejõud Üllar Rammul. See on õppekavas kohustuslik aine, mis on erialast tõesti täiesti eemal (ei ole kuidagi IT) aga sellegipoolest ma arvan, et see on täiesti õige aine täiesti õigel kohal. Lisaks suurepärane õppejõud ja väga hästi läbi viidud kursus.

Lai silmaring on hea ja see on puhtalt silmaringi aine.

Programmeerimine C# keeles (ICD0008, 6 EAP, kohustuslik)

Õppejõud Andres Käver. Arvestatud 22. detsembril. Millegipärast on see jätkuvalt väga krõbe aine, kuigi C# olen praeguseks juba päris palju kirjutanud. Ma ei ole lõpuni aru saanud, mis selle aine nii keeruliseks teeb, et nii vähe inimesi (41%) selle aine sooritatud saab.

Kõik, mida oli vaja teha aine läbimiseks, on siin lehel kirjas: 5 kodutööd ja eksam (1h teooriat, kuni 11h ülesande jaoks).

Veebirakendused Java baasil (ICD0011, 6 EAP, kohustuslik)

Õppejõud Märt Kalmo. Arvestatud 7. jaanuaril. Õppeaine sisuks on Java võimalusi ja tehnoloogiaid kasutades pisikeste back-end funktsionaalsuste teostamine. Rakenduseks oli pisike mõne tabeliga andmebaas, millega sai API endpointide kaudu suhelda. Front-endi ei teinud. Tehnoloogiad millega tutvuti: Servlet, Jdbc, PostgreSql, HsqlDb, Gradle, Spring Core,  Spring Mvc, JSR 303, JPA, Spring Security.

Mulle väga meeldib Märt Kalmo õpetamise stiil ja õppetöö korraldus: loeng → praktiline harjutus → iseseisev hindeline ülesanne (koos avatud testidega, mida saab lahendamise ajal kasutada) → vajadusel praktikum/konsultatsioon, kui iseseisva tööga kuskil tõrkeid tekib.

Samuti meeldib mulle väga tema lähenemine selles osas, et tähtis ei ole, et sa oskad mingit asja mingit moodi teha, vaid et sa saad aru (ja oskad selgitada), miks mingit asja üht või teist viisi tehakse (või ei ole hea mõte teha). Eesmärk on saada aru, mis on mingi asja mõte. Kui see lähenemine sobib, siis tema ained tõenäoliselt meeldivad.

Aga… edasises elus üldiselt on selle tulemusena raskem, kui saad aru, kui vähe inimesed üldiselt nii mõtlevad – et miks nad mingeid asju teevad või mis on nende asjade tegemise mõte 🙂

ICY0012 Infosüsteemide analüüs ja projekteerimine (6 EAP, toetav)

Kuna toetavate ainete moodulisse oli millegi eest 6 EAP vaja saada, siis jäin selle aine juurde. Marko soovitas ka seda ainet. Õppejõud on hinnatud õppejõud Nadežda “Nadya” Furs, keda väga palju kiidetakse. Semestri jooksul oli vaja esitleda kaks grupitööd – üks traditsioonilise ja teine agiilse osa kohta – ja see oligi kõik. Aine teemades oli päris suur ülekate Paul Leisi “Tarkvaratehnika” ainega, mida võtsin 4. semestril.

8. Jan 2022 |

How to prepare for the TestDome php assessment – my mistakes and tips

3rd year IT student in search of an internship

5th semester at school is pretty much over by now. Only one small assignment to do on upcoming Tuesday Thursday. Hopefully, I will write about the semester at some point.

On Monday I am going to do PHP tests for the internship that I applied for. I am preparing for it at the moment by solving Testdome PHP exercises and PHP interview questions. If I succeed it would be a huge step for me to become a sufficient Magento developer one day.

Continue reading “How to prepare for the TestDome php assessment – my mistakes and tips”

19. Nov 2021 |

Does PHP Loop Through the Whole Array to Find a Specific Element?

Same question here but I find its answer a bit misleading. My answer would be YES. You need to loop through the whole array to find a specific element and the worst case complexity is O(n). Unless:

  • you use associative array and ask the element by its key. Then the search takes constant time O(1).
  • you ask element by its index (you know where the element is and you go there directly). Then the search takes constant time O(1).
8. Oct 2021 |

PostgreSQL create db and user

I need it quite often during development (mainly school work) that I need to create new database together with new user that can only use this specific database. Here are three simple commands that do just that.

CREATE DATABASE robert_db;
CREATE USER robert WITH ENCRYPTED PASSWORD 'x1y2z3';
GRANT ALL PRIVILEGES ON DATABASE robert_db TO robert;

In development I usually keep db name and user name the same so that I have less variables to remember.