Yii2 dev digest #3 Dec'13

Official CHANGELOG appeared so my digests could be not so useful now
but in any case I will keep going :)

Discussions

that could be interesting to participate in

Take a look into and share your view on these questions Implement Transaction strategy for database cleanup (start transaction for connection and then rollback) Implement Reset strategy for database cleanup (tables truncate) Implement Drop/Create strategy for database cleanup (drop tables then create them <->)

What's new

Namespace and package names Extension MUST use the type yii2-extension in composer.json file. Extension MUST NOT use yii or yii2 in the composer package name or in the namespaces used in the package. Extension SHOULD use namespaces in this format vendor-name\package (all lowercase). Extension MAY use a yii2- prefix in the composer vendor name (URL). Extension MAY use a yii2- prefix in the repository name (URL). etc...

Acceptance tests integration and examples Functional tests integration and examples Unit tests integration and examples

@cebe : I think we can close this issue now. I am done with all the system I know and can support as I am going to work with them on a regular basis. Others should be provided as extensions or by other core developers. If someone wants to start working on an implementation of an AR feel free to contact me, I can help with that.


Read more ...

Easy-one-step install Redis 2.8 (latest) + PhpRedis in Ubuntu from source code

redis

Redis is a modern and very fast key-value storage. Someone calls it a "NoSQL" storage, someone - "just a memory cache". And all of them partly right - as Redis is a powerful tool, that could became very effective in different use cases.

Learn Redis

If you are not familiar with Redis at all. Start here - The Little Redis Book by Karl Seguin (Russian version)

Redis gets a lot of updates and new features, that's why in Linux repos you almost always see outdated versions. I recommend to install Redis and php_redis (PHP Redis driver extension) from source - it is very easy and fast.


Read more ...

Yii2 dev digest #2 Dec'13

It has gone some time after Yii2 Alpha announce, it increased activity in GitHub issues, a lot more people have tried to touch Yii2. And this is what I have noted.

$drivers = Driver::find()->with('cars')->asArray()->all();

will get populated nested arrays with releations

 $count = Yii::$app->db->createCommand('
      SELECT COUNT(*) FROM tbl_user WHERE status=:status
  ', [':status' => 1])->queryScalar();

  $dataProvider = new SqlDataProvider([
      'sql' => 'SELECT * FROM tbl_user WHERE status=:status',
      'params' => [':status' => 1],
      'totalCount' => $count,
      'sort' => [
          'attributes' => [
              'age',
              'name' => [
                  'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],
                  'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],
                  'default' => SORT_DESC,
                  'label' => 'Name',
              ],
          ],
      ],
      'pagination' => [
          'pageSize' => 20,
      ],
  ]);

Read more ...

Processing AppStore auto renewable subscriptions in PHP

in-app-purchases

First all be aware of Apple's policy as for auto renewable subscription and application types that could use it (your app could be rejected if reviewers will decide you that you are missusing subscriptions).

11.15 Apps may only use auto renewing subscriptions for periodicals (newspapers, magazines), business Apps (enterprise, productivity, professional creative, cloud storage) and media Apps (video, audio, voice), or the App will be rejected

Auto renewable subscriptions flow

Basically it works as all AppStore in-app purchases - iOS makes purchase on client side, receives Receipt and gives it server for validation. An issue appears when you need to renew subscription - unfortunately there is no something like IPN in PayPal and AppStore does not "push inform" us about prolongation or cancellation of subscription (as PayPal do). We need to do it ourselves.

As for auto-renew subscriptions we should make such steps:

  • Take initial receipt, validate it on server side (what should be validated except Apple response - is a topic for another big post)
  • Store initial receipt in DB (assign to user internally and save renew date)
  • CRON job should make periodic check of records by renew date (frequency depends on your logic, but once in 1-6 hours could be fine)
  • If it is time to check some subscription - take previously saved Receipt and make a validate request to Apple server as usually
  • If subscription was continued and money booked from user - you will receive response with new Receipt (and old one also), if not renewed - you will receive "Expired" response.
  • If subscription was continued and success response received - save it to DB, and use in next subscription validation round
  • If not - process your app logic on expired subscription (close some services for this user or something)

Read more ...

How to install Elance Tracker in latest Ubuntu 14.04 (Linux Mint 17)

Elance Tracker

Elance Tracker app uses Adobe Air and as Adobe has stopped Air support for Linux (the latest supported version is 2.6) - it became problematic to run Air apps on Linux.
You can find a lot of manual allover the Web how to solve different issues and install Air on Linux (like linking libgnome-keyring.so etc.), but with Ubuntu each new version brings less compatibility.
On Ubuntu 13.10 for a long time I was not able to install Adobe Air in any way. Only one manual from tkalin.com helped me to figure it out.

My previous manual using Wine was not correct. Sorry for that, with Wine you can install and run Tracker, but time and screenshots are not being tracked. So it is useless.

  • Here is one quick script. Save it as install_adobe_air.sh
#!/bin/bash
apt-get install libgtk2.0-0:i386 libstdc++6:i386 libnss3-1d:i386 lib32nss-mdns libxml2:i386 libxslt1.1:i386 libcanberra-gtk-module:i386 gtk2-engines-murrine:i386
cd /tmp
apt-get download libgnome-keyring0:i386
dpkg-deb -R libgnome-keyring0_3.8.0-2_i386.deb gnome-keyring
cp gnome-keyring/usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/i386-linux-gnu/
ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/i386-linux-gnu/libgnome-keyring.so.0
ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0
ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0.2.0 /usr/lib/libgnome-keyring.so.0.2.0
wget http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRInstaller.bin
chmod a+x AdobeAIRInstaller.bin
./AdobeAIRInstaller.bin
rm ./AdobeAIRInstaller.bin
rm /usr/lib/libgnome-keyring.so.0
rm /usr/lib/libgnome-keyring.so.0.2.0
  • Make it executable sudo chmod a+x install_adobe_air.sh
  • And run sudo ./install_adobe_air.sh (during running Abode Air wizard will appera, you should go through it)
  • Then download Elance Tracker for Linux as usual and install it in normal way

Read more ...
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes