-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcron_job.php
133 lines (95 loc) · 3.54 KB
/
cron_job.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
set_time_limit(0);
$start_time = time("now");
require_once('lib/config.php');
require_once('lib/ebay/selling.php');
require_once('lib/item.php');
if(isset($_GET['user_id']))
{
$users = array(DB::query_row("SELECT * from ebay_users where `user_id`='${_GET['user_id']}'"));
$lock_file = LOCK_FILE . '_' . $_GET['user_id'];
}
else
{
$users = DB::query_rows("SELECT * from ebay_users");
$lock_file = LOCK_FILE . '';
}
if(!Lock::lock($lock_file, "LOCK", 0*3600))
{
//die('Another instance is already running: ' . Lock::get_msg($lock_file));
}
Log::push('----- Cron job started -----');
foreach($users as $user_data)
{
$user_id = $user_data['user_id'];
$_user = new User($user_id);
$DEVNAME = trim($user_data['dev_name']);
$APPNAME = trim($user_data['app_name']);
$CERTNAME = trim($user_data['cert_name']);
$paypal_email = trim($user_data['paypal_address']);
$token = ($user_data['token']);
$service = new \DTS\eBaySDK\Trading\Services\TradingService(array(
'apiVersion' => $config['tradingApiVersion'],
'sandbox' => $user_data['sandbox'] == 1,
'siteId' => \DTS\eBaySDK\Constants\SiteIds::US,
'devId' => $user_data['dev_name'],
'appId' => $user_data['app_name'],
'certId' => $user_data['cert_name'],
'debug' => DEBUG,
));
/* Relisting inactive items */
// $items = EbaySelling::get_items('UnsoldList');
$items = array();
foreach ($items as $num =>$ebay_item)
{
if(!empty($_GET['num']) && $_GET['num'] != $num)
continue;
if(!empty($_GET['id']) && $_GET['id'] != $ebay_item->ItemID)
continue;
if(!empty($_GET['SKU']) && $_GET['SKU'] != $ebay_item->SKU)
continue;
$item = Item::from_ebay_data($ebay_item);
$item->scrape($ebay_item->SKU);
sleep(2);
if(!empty($item->vendor_data['scrapok']) && !empty($item->vendor_data['offerprice']) && $item->vendor_data['quantity'] && $item->vendor_data['prime'] == 'Yes')
{
$current = Ebay::get_item_by_sku($ebay_item->SKU);
if(@ $error = $current->Errors->offsetGet(0))
if($error->ErrorCode == '21916270') /* There is no active item matching the specified SKU */
{
$item->log('Should is back in stock.');
$_user->notify("Item is back in stock", $item->get_links() . ' can be relisted');
//$response = $item->relist();
}
}
if(file_exists('stop'))
xd('Interrupted');
gc_collect_cycles();
}
/* Updating active items */
$items = EbaySelling::get_items('ActiveList');
foreach ($items as $num =>$ebay_item)
{
if(!empty($_GET['num']) && $_GET['num'] != $num)
continue;
if(!empty($_GET['id']) && $_GET['id'] != $ebay_item->ItemID)
continue;
if(!empty($_GET['SKU']) && $_GET['SKU'] != $ebay_item->SKU)
continue;
$item = Item::from_ebay_data($ebay_item);
$item->scrape($ebay_item->SKU);
sleep(2);
if(! $item->vendor_data['scrapok'])
{
echo($ebay_item->ItemID . " => " . $ebay_item->SKU . " scrape FAIL<br>");
continue;
}
echo($ebay_item->ItemID . " => " . $ebay_item->SKU . " scrape OK<br>");
$item->update();
$item->setSort($num);
if(file_exists('stop'))
xd('Interrupted');
gc_collect_cycles();
}
}
Log::push('----- Cron job finished -----');