<?php

$this->query("\n    CREATE TABLE `push_apns_devices` (\n        `device_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `app_version` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,\n        `device_uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL,\n        `last_known_latitude` decimal(11,8) DEFAULT NULL,\n        `last_known_longitude` decimal(11,8) DEFAULT NULL,\n        `device_token` char(64) COLLATE utf8_unicode_ci NOT NULL,\n        `device_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `device_model` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n        `device_version` varchar(25) COLLATE utf8_unicode_ci NOT NULL,\n        `push_badge` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `push_alert` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `push_sound` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n        `created_at` datetime NOT NULL,\n        `updated_at` timestamp NOT NULL,\n        PRIMARY KEY (`device_id`),\n        UNIQUE KEY `UNIQUE_KEY_APP_NAME_APP_VERSION_DEVICE_UID` (`app_name`,`app_version`,`device_uid`),\n        KEY `KEY_DEVICE_TOKEN` (`device_token`),\n        KEY `KEY_STATUS` (`status`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n    CREATE TABLE `push_delivered_message` (\n        `deliver_id` int(11) NOT NULL AUTO_INCREMENT,\n        `device_id` int(11) NOT NULL,\n        `device_uid` text COLLATE utf8_unicode_ci NOT NULL,\n        `device_type` tinyint(1) NOT NULL,\n        `message_id` int(11) NOT NULL,\n        `status` tinyint(1) NOT NULL DEFAULT '0',\n        `is_read` tinyint(1) NOT NULL DEFAULT '0',\n        `is_displayed` int(11) NOT NULL DEFAULT '0',\n        `delivered_at` datetime NOT NULL,\n        PRIMARY KEY (`deliver_id`),\n        KEY `KEY_DEVICE_ID` (`device_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$this->query("\n    CREATE TABLE `push_gcm_devices` (\n        `device_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `registration_id` text COLLATE utf8_unicode_ci,\n        `development` enum('production','sandbox') CHARACTER SET latin1 NOT NULL DEFAULT 'production',\n        `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n        `created_at` datetime NOT NULL,\n        `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n        PRIMARY KEY (`device_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n    CREATE TABLE `push_messages` (\n        `message_id` int(11) NOT NULL AUTO_INCREMENT,\n        `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL,\n        `text` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `latitude` decimal(11,8) DEFAULT NULL,\n        `longitude` decimal(11,8) DEFAULT NULL,\n        `radius` decimal(7,2) DEFAULT NULL,\n        `send_at` datetime DEFAULT NULL,\n        `send_until` datetime DEFAULT NULL,\n        `delivered_at` datetime DEFAULT NULL,\n        `status` enum('queued','delivered','sending','failed') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued',\n        `created_at` datetime NOT NULL,\n        `updated_at` datetime NOT NULL,\n        PRIMARY KEY (`message_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$this->query("\n    CREATE TABLE `push_certificate` (\n        `certificate_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_id` INT(11) NULL DEFAULT NULL,\n        `type` varchar(30) NOT NULL,\n        `path` varchar(255) NULL DEFAULT NULL,\n        `created_at` datetime NOT NULL,\n        `updated_at` datetime NOT NULL,\n        PRIMARY KEY (`certificate_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$library = new Media_Model_Library();
$library->setName('Push')->save();
$icon_paths = array('/push_notifications/push1.png', '/push_notifications/push2.png', '/push_notifications/push3.png', '/push_notifications/push4.png', '/push_notifications/push5.png', '/loyalty/loyalty6.png');
$icon_id = 0;
foreach ($icon_paths as $key => $icon_path) {
    $datas = array('library_id' => $library->getId(), 'link' => $icon_path, 'can_be_colorized' => 1);
    $image = new Media_Model_Library_Image();
    $image->setData($datas)->save();
    if ($key == 0) {
        $icon_id = $image->getId();
    }
}
$datas = array('library_id' => $library->getId(), 'icon_id' => $icon_id, 'code' => 'push_notification', 'name' => 'Push Notifications', 'model' => '', 'desktop_uri' => 'push/application/', 'mobile_uri' => 'push/mobile/', 'only_once' => 1, 'is_ajax' => 1, 'position' => 130);
$option = new Application_Model_Option();
$option->setData($datas)->save();
<?php

$media_library = new Media_Model_Library();
$media_library->setName("Code Scan")->save();
$icon_id = null;
$files_icon = new DirectoryIterator(Core_Model_Directory::getBasePathTo("images/library/code_scan"));
foreach ($files_icon as $file) {
    if ($file->isDot()) {
        continue;
    }
    $icon = new Media_Model_Library_Image();
    $icon_data = array("library_id" => $media_library->getId(), "link" => "/code_scan/" . $file->getFilename(), "can_be_colorized" => 1);
    $icon->setData($icon_data)->save();
    if ($icon_id == null) {
        $icon_id = $icon->getId();
    }
}
$option_data = array("code" => "code_scan", "name" => "Code Scan", "model" => "Codescan_Model_Codescan", "library_id" => $media_library->getId(), "icon_id" => $icon_id, "desktop_uri" => "codescan/application/", "mobile_uri" => "codescan/mobile_view/", "position" => 150);
$option = new Application_Model_Option();
$option->setData($option_data)->save();