/** * saves the category in a specific order and change the parent * @return void */ public function action_saveorder() { $this->auto_render = FALSE; $this->template = View::factory('js'); $cat = new Model_Category(core::get('id_category')); if ($cat->loaded()) { //saves the current category $cat->id_category_parent = core::get('id_category_parent'); $cat->parent_deep = core::get('deep'); //saves the categories in the same parent the new orders $order = 0; foreach (core::get('brothers') as $id_cat) { $id_cat = substr($id_cat, 3); //removing the li_ to get the integer //not the main category so loading and saving if ($id_cat != core::get('id_category')) { $c = new Model_Category($id_cat); $c->order = $order; $c->save(); } else { //saves the main category $cat->order = $order; $cat->save(); } $order++; } $this->template->content = __('Saved'); } else { $this->template->content = __('Error'); } }
public function action_icon() { //get icon if (isset($_FILES['category_icon'])) { $icon = $_FILES['category_icon']; } else { $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'index'))); } $category = new Model_Category($this->request->param('id')); if (core::config('image.aws_s3_active')) { require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php'); $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key')); } if (core::post('icon_delete') and $category->delete_icon() == TRUE) { Alert::set(Alert::SUCCESS, __('Icon deleted.')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $category->id_category))); } // end of icon delete if (!Upload::valid($icon) or !Upload::not_empty($icon) or !Upload::type($icon, explode(',', core::config('image.allowed_formats'))) or !Upload::size($icon, core::config('image.max_image_size') . 'M')) { if (Upload::not_empty($icon) && !Upload::type($icon, explode(',', core::config('image.allowed_formats')))) { Alert::set(Alert::ALERT, $icon['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $category->id_category))); } if (!Upload::size($icon, core::config('image.max_image_size') . 'M')) { Alert::set(Alert::ALERT, $icon['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $category->id_category))); } Alert::set(Alert::ALERT, $icon['name'] . ' ' . __('Image is not valid. Please try again.')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $category->id_category))); } else { if ($icon != NULL) { // saving/uploading img file to dir. $path = 'images/categories/'; $root = DOCROOT . $path; //root folder $icon_name = $category->seoname . '.png'; // if folder does not exist, try to make it if (!file_exists($root) and !@mkdir($root, 0775, true)) { // mkdir not successful ? Alert::set(Alert::ERROR, __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')); return; // exit function } // save file to root folder, file, name, dir if ($file = Upload::save($icon, $icon_name, $root)) { // put icon to Amazon S3 if (core::config('image.aws_s3_active')) { $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $icon_name, S3::ACL_PUBLIC_READ); } // update category info $category->has_image = 1; $category->last_modified = Date::unix2mysql(); $category->save(); Alert::set(Alert::SUCCESS, $icon['name'] . ' ' . __('Icon is uploaded.')); } else { Alert::set(Alert::ERROR, $icon['name'] . ' ' . __('Icon file could not been saved.')); } $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller(), 'action' => 'update', 'id' => $category->id_category))); } } }
/** * This function will upgrade DB that didn't existed in versions prior to 2.3.0 */ public function action_230() { //Cron update try { DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 3 * * *' WHERE callback='Sitemap::generate' LIMIT 1")->execute(); DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 5 * * *' WHERE callback='Core::delete_cache' LIMIT 1")->execute(); DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 4 1 * *' WHERE callback='Core::optimize_db' LIMIT 1")->execute(); DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 7 * * *' WHERE callback='Cron_Ad::unpaid' LIMIT 1")->execute(); DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 8 * * *' WHERE callback='Cron_Ad::expired_featured' LIMIT 1")->execute(); DB::query(Database::UPDATE, "UPDATE `" . self::$db_prefix . "crontab` SET period='00 9 * * *' WHERE callback='Cron_Ad::expired' LIMIT 1")->execute(); } catch (exception $e) { } //control login attempts try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute(); } catch (exception $e) { } //categories/locations/users/ads has_image/last_modified try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "locations` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "locations` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "ads` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } //new configs $configs = array(array('config_key' => 'aws_s3_active', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'aws_access_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_secret_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_bucket', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_domain', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'disallow_nudes', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'html_head', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'html_footer', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'login_to_contact', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'custom_css', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'custom_css_version', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'only_admin_post', 'group_name' => 'advertisement', 'config_value' => 0), array('config_key' => 'map_active', 'group_name' => 'appearance', 'config_value' => 1), array('config_key' => 'map_jscode', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'map_settings', 'group_name' => 'appearance', 'config_value' => ''), array('config_key' => 'recaptcha_active', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_secretkey', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_sitekey', 'group_name' => 'general', 'config_value' => '')); Model_Config::config_array($configs); //upgrade has_image field to use it as images count $ads = new Model_Ad(); $ads = $ads->where('has_images', '>', 0)->find_all(); if (count($ads)) { foreach ($ads as $ad) { $ad->has_images = 0; //begin with 0 images $route = $ad->image_path(); $folder = DOCROOT . $route; $image_keys = array(); if (is_dir($folder)) { //retrive ad pictures foreach (new DirectoryIterator($folder) as $file) { if (!$file->isDot()) { $key = explode('_', $file->getFilename()); $key = end($key); $key = explode('.', $key); $key = isset($key[0]) ? $key[0] : NULL; if (is_numeric($key)) { if (strpos($file->getFilename(), 'thumb_') === 0) { $image_keys[] = $key; } } } } //count images and reordering file names if (count($image_keys)) { asort($image_keys); foreach ($image_keys as $image_key) { $ad->has_images++; @rename($folder . $ad->seotitle . '_' . $image_key . '.jpg', $folder . $ad->seotitle . '_' . $ad->has_images . '.jpg'); @rename($folder . 'thumb_' . $ad->seotitle . '_' . $image_key . '.jpg', $folder . 'thumb_' . $ad->seotitle . '_' . $ad->has_images . '.jpg'); } } } //update has_images count try { $ad->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } //upgrade categories has_image $images_path = DOCROOT . 'images/categories'; if (is_dir($images_path)) { //retrive cat pictures foreach (new DirectoryIterator($images_path) as $file) { if ($file->isFile()) { $cat_name = str_replace('.png', '', $file->getFilename()); $cat = new Model_Category(); $cat->where('seoname', '=', $cat_name)->find(); if ($cat->loaded()) { $cat->has_image = 1; $cat->save(); } } } } //upgrade locations has_image $images_path = DOCROOT . 'images/locations'; if (is_dir($images_path)) { //retrive loc pictures foreach (new DirectoryIterator($images_path) as $file) { if ($file->isFile()) { $loc_name = str_replace('.png', '', $file->getFilename()); $loc = new Model_Location(); $loc->where('seoname', '=', $loc_name)->find(); if ($loc->loaded()) { $loc->has_image = 1; $loc->save(); } } } } //upgrade users has_image $images_path = DOCROOT . 'images/users'; if (is_dir($images_path)) { //retrive user pictures foreach (new DirectoryIterator($images_path) as $file) { if ($file->isFile() and is_numeric($id_user = str_replace('.png', '', $file->getFilename()))) { $user = new Model_User($id_user); if ($user->loaded()) { $user->has_image = 1; $user->save(); } } } } }
/** * does the DB migration * @param pointer $db * @param string $pf db_prefix */ private function migrate($db, $pf) { set_time_limit(0); $db_config = core::config('database.default'); $prefix = $db_config['table_prefix']; //connect DB original/to where we migrate $dbo = Database::instance('default'); //oc_accounts --> oc_users $users_map = array(); $accounts = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'accounts`'); foreach ($accounts as $account) { $user = new Model_User(); $user->where('email', '=', $account['email'])->limit(1)->find(); if (!$user->loaded()) { $user->name = $account['name']; $user->email = $account['email']; $user->password = $account['password']; $user->created = $account['createdDate']; $user->last_modified = $account['lastModifiedDate']; $user->last_login = $account['lastSigninDate']; $user->status = $account['active']; $user->id_role = 1; $user->seoname = $user->gen_seo_title($user->name); $user->save(); } $users_map[$account['email']] = $user->id_user; } //categories --> categories $categories_map = array(0 => 1); $categories = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'categories` ORDER BY `idCategoryParent` ASC'); foreach ($categories as $category) { $cat = new Model_Category(); $cat->name = $category['name']; $cat->order = $category['order']; $cat->created = $category['created']; $cat->seoname = $category['friendlyName']; $cat->price = $category['price']; $cat->description = substr($category['description'], 0, 250); $cat->parent_deep = $category['idCategoryParent'] > 0 ? 1 : 0; //there's only 1 deep $cat->id_category_parent = isset($categories_map[$category['idCategoryParent']]) ? $categories_map[$category['idCategoryParent']] : 1; $cat->save(); //we save old_id stores the new ID, so later we know the category parent, and to changes the ADS category id $categories_map[$category['idCategory']] = $cat->id_category; } //locations --> locations $locations_map = array(0 => 1); $locations = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'locations` ORDER BY `idLocationParent` ASC'); foreach ($locations as $location) { $loc = new Model_Location(); $loc->name = $location['name']; $loc->seoname = $location['friendlyName']; $loc->parent_deep = $location['idLocationParent'] > 0 ? 1 : 0; //there's only 1 deep $loc->id_location_parent = isset($locations_map[$location['idLocationParent']]) ? $locations_map[$location['idLocationParent']] : 1; $loc->save(); //we save old_id stores the new ID, so later we know the location parent, and to changes the ADS location id $locations_map[$location['idLocation']] = $loc->id_location; } //posts --> ads $ads_map = array(); $ads = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'posts`'); foreach ($ads as $a) { if (Valid::email($a['email'])) { //gettin the id_user if (isset($users_map[$a['email']])) { $id_user = $users_map[$a['email']]; } else { $user = Model_User::create_email($a['email'], $a['name']); $id_user = $user->id_user; } $ad = new Model_Ad(); $ad->id_ad = $a['idPost']; //so images still work $ad->id_user = $id_user; $ad->id_category = isset($categories_map[$a['idCategory']]) ? $categories_map[$a['idCategory']] : 1; $ad->id_location = isset($locations_map[$a['idLocation']]) ? $locations_map[$a['idLocation']] : 1; $ad->title = $a['title']; $ad->seotitle = $ad->gen_seo_title($a['title']); $ad->description = !empty($a['description']) ? Text::html2bb($a['description']) : $a['title']; $ad->address = $a['place']; $ad->price = $a['price']; $ad->phone = $a['phone']; $ad->has_images = $a['hasImages']; $ad->ip_address = ip2long($a['ip']); $ad->created = $a['insertDate']; $ad->published = $ad->created; //Status migration...big mess! if ($a['isAvailable'] == 0 and $a['isConfirmed'] == 0) { $ad->status = Model_Ad::STATUS_NOPUBLISHED; } elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 0) { $ad->status = Model_Ad::STATUS_NOPUBLISHED; } elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 1) { $ad->status = Model_Ad::STATUS_PUBLISHED; } elseif ($a['isAvailable'] == 0 and $a['isConfirmed'] == 1) { $ad->status = Model_Ad::STATUS_UNAVAILABLE; } elseif ($a['isAvailable'] == 2) { $ad->status = Model_Ad::STATUS_SPAM; } else { $ad->status = Model_Ad::STATUS_UNAVAILABLE; } try { $ad->save(); } catch (ORM_Validation_Exception $e) { // d($e->errors('')); } $ads_map[$a['idPost']] = $ad->id_ad; } } //posthits --> visits, mass migration $insert = 'INSERT INTO `' . $prefix . 'visits` ( `id_ad`, `created`, `ip_address`) VALUES'; $step = 5000; $total = $db->query(Database::SELECT, 'SELECT count(*) cont FROM `' . $pf . 'postshits`')->as_array(); $total = $total[0]['cont']; for ($i = 0; $i < $total; $i += $step) { $hits = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'postshits` LIMIT ' . $i . ', ' . $step); $values = ''; foreach ($hits as $hit) { //build insert query $values .= '(' . $hit['idPost'] . ', \'' . $hit['hitTime'] . '\', \'' . ip2long($hit['ip']) . '\'),'; } $dbo->query(Database::INSERT, $insert . substr($values, 0, -1)); } //old way of migrating // $hits = $db->query(Database::SELECT, 'SELECT * FROM `'.$pf.'postshits` '); // foreach ($hits as $hit) // { // //build insert query // $visit = new Model_Visit(); // $visit->id_ad = (isset($ads_map[$hit['idPost']]))?$ads_map[$hit['idPost']]:NULL; // $visit->created = $hit['hitTime']; // $visit->ip_address = ip2long($hit['ip']); // $visit->save(); // } }
/** * This function will upgrade configs */ public function action_170() { //deleted classes moved to common File::delete(DOCROOT . 'oc/classes/bitpay.php'); File::delete(DOCROOT . 'oc/classes/paymill.php'); File::delete(DOCROOT . 'oc/classes/stripeko.php'); File::delete(DOCROOT . 'themes/default/views/pages/authorize/button.php'); File::delete(DOCROOT . 'themes/default/views/pages/bitpay/button_loged.php'); File::delete(DOCROOT . 'themes/default/views/pages/paymill/button_loged.php'); //crontabs try { DB::query(Database::UPDATE, "INSERT INTO `" . self::$db_prefix . "crontab` (`name`, `period`, `callback`, `params`, `description`, `active`) VALUES\n ('Unpaid Orders', '0 7 * * *', 'Model_Order::cron_unpaid', NULL, 'Notify by email unpaid orders 2 days after was created', 1);")->execute(); } catch (exception $e) { } //url buy try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "products` ADD `url_buy` varchar(245) ;")->execute(); } catch (exception $e) { } //control login attempts try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `last_failed` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `failed_attempts` int(10) unsigned DEFAULT 0")->execute(); } catch (exception $e) { } //EU VAT try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `VAT_number` VARCHAR(65) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `country` VARCHAR(3) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `city` VARCHAR(65) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `postal_code` VARCHAR(20) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `address` VARCHAR(150) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } //eu vat orders try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `VAT` decimal(14,3) NOT NULL DEFAULT '0.000'")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `VAT_number` VARCHAR(65) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `country` VARCHAR(3) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `city` VARCHAR(65) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `postal_code` VARCHAR(20) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "orders` ADD `address` VARCHAR(150) NULL DEFAULT NULL")->execute(); } catch (exception $e) { } //categories/users has_image/last_modified try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "categories` ADD `last_modified` DATETIME NULL DEFAULT NULL ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "categories` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute(); } catch (exception $e) { } try { DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "users` ADD `has_image` TINYINT( 1 ) NOT NULL DEFAULT '0' ;")->execute(); } catch (exception $e) { } //configs $configs = array(array('config_key' => 'aws_s3_active', 'group_name' => 'image', 'config_value' => 0), array('config_key' => 'aws_access_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_secret_key', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_bucket', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'aws_s3_domain', 'group_name' => 'image', 'config_value' => ''), array('config_key' => 'html_head', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'html_footer', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'custom_css', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'custom_css_version', 'group_name' => 'appearance', 'config_value' => 0), array('config_key' => 'eu_vat', 'group_name' => 'general', 'config_value' => 0), array('config_key' => 'vat_number', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'company_name', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'vat_excluded_countries', 'group_name' => 'general', 'config_value' => '')); Model_Config::config_array($configs); //new mails $contents = array(array('order' => 0, 'title' => 'Receipt for [ORDER.DESC] #[ORDER.ID]', 'seotitle' => 'new-order', 'description' => "Hello [USER.NAME],Thanks for buying [ORDER.DESC].\n\nPlease complete the payment here [URL.CHECKOUT]", 'from_email' => core::config('email.notify_email'), 'type' => 'email', 'status' => '1')); Model_Content::content_array($contents); //upgrade has_image field to use it as images count $products = new Model_Product(); $products = $products->where('has_images', '=', 0)->find_all(); if (count($products)) { foreach ($products as $product) { $product->has_images = 0; //begin with 0 images $route = $product->image_path(); $folder = DOCROOT . $route; $image_keys = array(); if (is_dir($folder)) { //retrive ad pictures foreach (new DirectoryIterator($folder) as $file) { if (!$file->isDot()) { $key = explode('_', $file->getFilename()); $key = end($key); $key = explode('.', $key); $key = isset($key[0]) ? $key[0] : NULL; if (is_numeric($key)) { if (strpos($file->getFilename(), 'thumb_') === 0) { $image_keys[] = $key; } } } } //count images and reordering file names if (count($image_keys)) { asort($image_keys); foreach ($image_keys as $image_key) { $product->has_images++; @rename($folder . $product->seotitle . '_' . $image_key . '.jpg', $folder . $product->seotitle . '_' . $product->has_images . '.jpg'); @rename($folder . 'thumb_' . $product->seotitle . '_' . $image_key . '.jpg', $folder . 'thumb_' . $product->seotitle . '_' . $product->has_images . '.jpg'); } } } //update has_images count try { $product->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } //TODO //update has images //upgrade categories has_image $images_path = DOCROOT . 'images/categories'; if (is_dir($images_path)) { //retrive cat pictures foreach (new DirectoryIterator($images_path) as $file) { if ($file->isFile()) { $cat_name = str_replace('.png', '', $file->getFilename()); $cat = new Model_Category(); $cat->where('seoname', '=', $cat_name)->find(); if ($cat->loaded()) { $cat->has_image = 1; $cat->save(); } } } } //update crontabs }
public function addCategory($value) { $categery = new Model_Category(); $categery->name = $value; $categery->save(); }
public function action_index() { require $_SERVER['DOCUMENT_ROOT'] . "/application/vendor/vimeo/autoload.php"; $client_id = ''; $client_secret = ''; $token = ''; $token_secret = ''; $vimeo = new \Vimeo\Vimeo($client_id, $client_secret, $token); $categories = $vimeo->request("/categories"); foreach ($categories['body']['data'] as $category) { // $categoryArray = array('Animation', 'Arts & Design', 'Cameras & Techniques', 'Comedy', 'Documentary', 'Experimental', 'Fashion', 'Food', 'Instructionals', 'Music', 'Narrative', 'Personal', 'Reporting & Journalism', 'Sports', 'Talks')); // if (in_array($category['name'], $categoryArray)) { // continue; // } $categoryShortName = str_replace('/categories/', '', $category['uri']); for ($i = 1; $i <= 20; $i++) { sleep(1); echo 'page ' . $i . ' of ' . $category['uri']; $videos = $vimeo->request($category['uri'] . '/videos', array('sort' => 'plays', 'per_page' => 50, 'page' => $i)); // echo '<pre>'; print_r($videos); echo '</pre>'; exit; foreach ($videos['body']['data'] as $video) { // Prepares video data array $videoSpecs['uri'] = $video['uri']; $videoSpecs['name'] = $video['name']; $videoSpecs['description'] = $video['description']; $videoSpecs['link'] = $video['link']; $videoSpecs['duration'] = $video['duration']; $videoSpecs['width'] = $video['width']; $videoSpecs['height'] = $video['height']; $videoSpecs['create_time'] = $video['created_time']; $videoSpecs['plays'] = $video['stats']['plays']; $videoSpecs['likes'] = $video['metadata']['connections']['likes']['total']; $videoSpecs['comments'] = $video['metadata']['connections']['comments']['total']; if ($video['privacy']['embed'] === 'public') { $videoSpecs['embeddable'] = true; } else { $videoSpecs['embeddable'] = false; } // Look for existing record $videoOrm = ORM::factory('Video')->where('uri', '=', $video['uri'])->find_all()->as_array(); if (sizeOf($videoOrm) === 0) { // Add record to DB if it doesn't exist $videoRecord = new Model_Video(); $videoRecord->values($videoSpecs); $videoRecord->save(); $videoId = $videoRecord->id; $videoOrm = ORM::factory('Video')->where('uri', '=', $video['uri'])->find(); // Populate tags table with video data foreach ($video['tags'] as $tag) { $tagRecord = new Model_Tag(); $tagRecord->values(array('video_id' => $videoId, 'name' => $tag['name'])); $tagRecord->save(); } } else { // Update record if it exists $videoOrm[0]->values($videoSpecs); $videoOrm[0]->save(); $videoId = $videoOrm[0]->id; } // Populate categories table category data if that video and category association is not already stored $categoryOrm = ORM::factory('Category')->where('video_id', '=', $videoId)->and_where('short_name', '=', $categoryShortName)->find_all(); if ($categoryOrm->count() === 0) { $categoryRecord = new Model_Category(); $categoryRecord->values(array('video_id' => $videoId, 'name' => $category['name'], 'short_name' => $categoryShortName)); $categoryRecord->save(); } } } } }