forked from GNUsocial/gnu-social
		
	Less pychotic debugging statements
This commit is contained in:
		
							
								
								
									
										132
									
								
								scripts/twitterstatusfetcher.php
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										132
									
								
								scripts/twitterstatusfetcher.php
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@@ -72,10 +72,8 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
                if ($pid) {
 | 
					                if ($pid) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // Parent
 | 
					                    // Parent
 | 
				
			||||||
                    common_debug("Parent: forked new status fetcher process " . $pid);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (defined('SCRIPT_DEBUG')) {
 | 
					                    if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                        print "Parent: forked fetcher process " . $pid . "\n";
 | 
					                        common_debug("Parent: forked new status fetcher process " . $pid);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $this->children[] = $pid;
 | 
					                    $this->children[] = $pid;
 | 
				
			||||||
@@ -90,10 +88,8 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
                // Remove child from ps list as it finishes
 | 
					                // Remove child from ps list as it finishes
 | 
				
			||||||
                while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) {
 | 
					                while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    common_debug("Child $c finished.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (defined('SCRIPT_DEBUG')) {
 | 
					                    if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                        print "Child $c finished.\n";
 | 
					                        common_debug("Child $c finished.");
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $this->remove_ps($this->children, $c);
 | 
					                    $this->remove_ps($this->children, $c);
 | 
				
			||||||
@@ -102,18 +98,14 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
                // Wait! We have too many damn kids.
 | 
					                // Wait! We have too many damn kids.
 | 
				
			||||||
                if (sizeof($this->children) > MAXCHILDREN) {
 | 
					                if (sizeof($this->children) > MAXCHILDREN) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    common_debug('Too many children. Waiting...');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if (defined('SCRIPT_DEBUG')) {
 | 
					                    if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                        print "Too many children. Waiting...\n";
 | 
					                        common_debug('Too many children. Waiting...');
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (($c = pcntl_wait($status, WUNTRACED)) > 0){
 | 
					                    if (($c = pcntl_wait($status, WUNTRACED)) > 0){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        common_debug("Finished waiting for $c");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        if (defined('SCRIPT_DEBUG')) {
 | 
					                        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                            print "Finished waiting for $c\n";
 | 
					                            common_debug("Finished waiting for $c");
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        $this->remove_ps($this->children, $c);
 | 
					                        $this->remove_ps($this->children, $c);
 | 
				
			||||||
@@ -124,21 +116,18 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
            // Remove all children from the process list before restarting
 | 
					            // Remove all children from the process list before restarting
 | 
				
			||||||
            while(($c = pcntl_wait($status, WUNTRACED)) > 0) {
 | 
					            while(($c = pcntl_wait($status, WUNTRACED)) > 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                common_debug("Child $c finished.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (defined('SCRIPT_DEBUG')) {
 | 
					                if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                    print "Child $c finished.\n";
 | 
					                    common_debug("Child $c finished.");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $this->remove_ps($this->children, $c);
 | 
					                $this->remove_ps($this->children, $c);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Rest for a bit before we fetch more statuses
 | 
					            // Rest for a bit before we fetch more statuses
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                common_debug('Waiting ' . POLL_INTERVAL .
 | 
					                common_debug('Waiting ' . POLL_INTERVAL .
 | 
				
			||||||
                    ' secs before hitting Twitter again.');
 | 
					                    ' secs before hitting Twitter again.');
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                print 'Waiting ' . POLL_INTERVAL .
 | 
					 | 
				
			||||||
                    " secs before hitting Twitter again.\n";
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sleep(POLL_INTERVAL);
 | 
					            sleep(POLL_INTERVAL);
 | 
				
			||||||
@@ -155,14 +144,16 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $cnt = $flink->find();
 | 
					        $cnt = $flink->find();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
            print "Updating Twitter friends subscriptions for $cnt users.\n";
 | 
					            common_debug('Updating Twitter friends subscriptions' .
 | 
				
			||||||
 | 
					                " for $cnt users.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $flinks = array();
 | 
					        $flinks = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while ($flink->fetch()) {
 | 
					        while ($flink->fetch()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (($flink->noticesync & FOREIGN_NOTICE_RECV) == FOREIGN_NOTICE_RECV) {
 | 
					            if (($flink->noticesync & FOREIGN_NOTICE_RECV) ==
 | 
				
			||||||
 | 
					                FOREIGN_NOTICE_RECV) {
 | 
				
			||||||
                $flinks[] = clone($flink);
 | 
					                $flinks[] = clone($flink);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -187,30 +178,28 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (empty($flink)) {
 | 
					        if (empty($flink)) {
 | 
				
			||||||
            common_log(LOG_WARNING, "Can't retrieve Foreign_link for foreign ID $fid");
 | 
					            common_log(LOG_WARNING,
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					                "Can't retrieve Foreign_link for foreign ID $fid");
 | 
				
			||||||
                print "Can't retrieve Foreign_link for foreign ID $fid\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $fuser = $flink->getForeignUser();
 | 
					        $fuser = $flink->getForeignUser();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (empty($fuser)) {
 | 
					        if (empty($fuser)) {
 | 
				
			||||||
            common_log(LOG_WARNING, "Unmatched user for ID " . $flink->user_id);
 | 
					            common_log(LOG_WARNING, "Unmatched user for ID " .
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					                $flink->user_id);
 | 
				
			||||||
                print "Unmatched user for ID $flink->user_id\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
            common_debug('Trying to get timeline for Twitter user ' .
 | 
					            common_debug('Trying to get timeline for Twitter user ' .
 | 
				
			||||||
                "$fuser->nickname ($flink->foreign_id).");
 | 
					                "$fuser->nickname ($flink->foreign_id).");
 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
            print 'Trying to get timeline for Twitter user ' .
 | 
					 | 
				
			||||||
                "$fuser->nickname ($flink->foreign_id).\n";
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // XXX: Biggest remaining issue - How do we know at which status
 | 
				
			||||||
 | 
					        // to start importing?  How many statuses?  Right now I'm going
 | 
				
			||||||
 | 
					        // with the default last 20.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $url = 'http://twitter.com/statuses/friends_timeline.json';
 | 
					        $url = 'http://twitter.com/statuses/friends_timeline.json';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $timeline_json = get_twitter_data($url, $fuser->nickname,
 | 
					        $timeline_json = get_twitter_data($url, $fuser->nickname,
 | 
				
			||||||
@@ -220,18 +209,19 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (empty($timeline)) {
 | 
					        if (empty($timeline)) {
 | 
				
			||||||
            common_log(LOG_WARNING, "Empty timeline.");
 | 
					            common_log(LOG_WARNING, "Empty timeline.");
 | 
				
			||||||
             if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                print "Empty timeline!\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($timeline as $status) {
 | 
					        foreach ($timeline as $status) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Hacktastic: filter out stuff coming from Laconica
 | 
					            // Hacktastic: filter out stuff coming from this Laconica
 | 
				
			||||||
            $source = mb_strtolower(common_config('integration', 'source'));
 | 
					            $source = mb_strtolower(common_config('integration', 'source'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (preg_match("/$source/", mb_strtolower($status->source))) {
 | 
					            if (preg_match("/$source/", mb_strtolower($status->source))) {
 | 
				
			||||||
 | 
					                if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
 | 
					                    common_debug('Skipping import of status ' . $status->id .
 | 
				
			||||||
 | 
					                        ' with source ' . $source);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -239,7 +229,6 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Okay, record the time we synced with Twitter for posterity
 | 
					        // Okay, record the time we synced with Twitter for posterity
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $flink->last_noticesync = common_sql_now();
 | 
					        $flink->last_noticesync = common_sql_now();
 | 
				
			||||||
        $flink->update();
 | 
					        $flink->update();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -250,18 +239,14 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $profile = Profile::staticGet($id);
 | 
					        $profile = Profile::staticGet($id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$profile) {
 | 
					        if (!$profile) {
 | 
				
			||||||
            common_log(LOG_ERR, 'Problem saving notice. No associated Profile.');
 | 
					            common_log(LOG_ERR,
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					                'Problem saving notice. No associated Profile.');
 | 
				
			||||||
                print "Problem saving notice. No associated Profile.\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $uri = 'http://twitter.com/' . $status->user->screen_name .
 | 
					        $uri = 'http://twitter.com/' . $status->user->screen_name .
 | 
				
			||||||
            '/status/' . $status->id;
 | 
					            '/status/' . $status->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Skip save if notice source is Laconica or Identi.ca?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $notice = Notice::staticGet('uri', $uri);
 | 
					        $notice = Notice::staticGet('uri', $uri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // check to see if we've already imported the status
 | 
					        // check to see if we've already imported the status
 | 
				
			||||||
@@ -290,21 +275,23 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
            if (!$notice_id) {
 | 
					            if (!$notice_id) {
 | 
				
			||||||
                common_log_db_error($notice, 'INSERT', __FILE__);
 | 
					                common_log_db_error($notice, 'INSERT', __FILE__);
 | 
				
			||||||
                if (defined('SCRIPT_DEBUG')) {
 | 
					                if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                    print "Could not save notice!\n";
 | 
					                    common_debug('Could not save notice!');
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // XXX: Figure out a better way to link replies?
 | 
					            // XXX: Figure out a better way to link Twitter replies?
 | 
				
			||||||
            $notice->saveReplies();
 | 
					            $notice->saveReplies();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // XXX: Do we want to polute our tag cloud with hashtags from Twitter?
 | 
					            // XXX: Do we want to polute our tag cloud with
 | 
				
			||||||
 | 
					            // hashtags from Twitter?
 | 
				
			||||||
            $notice->saveTags();
 | 
					            $notice->saveTags();
 | 
				
			||||||
            $notice->saveGroups();
 | 
					            $notice->saveGroups();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $notice->query('COMMIT');
 | 
					            $notice->query('COMMIT');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                print "Saved status $status->id as notice $notice->id.\n";
 | 
					                common_debug("Saved status $status->id" .
 | 
				
			||||||
 | 
					                    " as notice $notice->id.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -327,18 +314,19 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $profile = Profile::staticGet('profileurl', $profileurl);
 | 
					        $profile = Profile::staticGet('profileurl', $profileurl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($profile) {
 | 
					        if ($profile) {
 | 
				
			||||||
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                common_debug("Profile for $profile->nickname found.");
 | 
					                common_debug("Profile for $profile->nickname found.");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Check to see if the user's Avatar has changed
 | 
					            // Check to see if the user's Avatar has changed
 | 
				
			||||||
            $this->checkAvatar($user, $profile);
 | 
					            $this->checkAvatar($user, $profile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $profile->id;
 | 
					            return $profile->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            $debugmsg = 'Adding profile and remote profile ' .
 | 
					 | 
				
			||||||
                "for Twitter user: $profileurl\n";
 | 
					 | 
				
			||||||
            common_debug($debugmsg, __FILE__);
 | 
					 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                print $debugmsg;
 | 
					                common_debug('Adding profile and remote profile ' .
 | 
				
			||||||
 | 
					                    "for Twitter user: $profileurl");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $profile = new Profile();
 | 
					            $profile = new Profile();
 | 
				
			||||||
@@ -356,10 +344,6 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (empty($id)) {
 | 
					            if (empty($id)) {
 | 
				
			||||||
                common_log_db_error($profile, 'INSERT', __FILE__);
 | 
					                common_log_db_error($profile, 'INSERT', __FILE__);
 | 
				
			||||||
                if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                    print 'Could not insert Profile: ' .
 | 
					 | 
				
			||||||
                        common_log_objstring($profile) . "\n";
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                $profile->query("ROLLBACK");
 | 
					                $profile->query("ROLLBACK");
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -379,10 +363,6 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (empty($rid)) {
 | 
					                if (empty($rid)) {
 | 
				
			||||||
                    common_log_db_error($profile, 'INSERT', __FILE__);
 | 
					                    common_log_db_error($profile, 'INSERT', __FILE__);
 | 
				
			||||||
                    if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                        print 'Could not insert Remote_profile: ' .
 | 
					 | 
				
			||||||
                            common_log_objstring($remote_pro) . "\n";
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    $profile->query("ROLLBACK");
 | 
					                    $profile->query("ROLLBACK");
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -408,13 +388,10 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if ($newname != $oldname) {
 | 
					        if ($newname != $oldname) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            common_debug("Avatar for Twitter user $profile->nickname has changed.");
 | 
					 | 
				
			||||||
            common_debug("old: $oldname new: $newname");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                print "Avatar for Twitter user $user->id has changed.\n";
 | 
					                common_debug('Avatar for Twitter user ' .
 | 
				
			||||||
                print "old: $oldname\n";
 | 
					                    "$profile->nickname has changed.");
 | 
				
			||||||
                print "new: $newname\n";
 | 
					                common_debug("old: $oldname new: $newname");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $img_root = substr($path_parts['basename'], 0, -11);
 | 
					            $img_root = substr($path_parts['basename'], 0, -11);
 | 
				
			||||||
@@ -472,26 +449,21 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
                $this->newAvatar($id, $size, $mediatype, $filename);
 | 
					                $this->newAvatar($id, $size, $mediatype, $filename);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__);
 | 
					                common_log(LOG_WARNING, "Problem fetching Avatar: $url", __FILE__);
 | 
				
			||||||
                if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                    print "Problem fetching Avatar: $url\n";
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function updateAvatar($profile_id, $size, $mediatype, $filename) {
 | 
					    function updateAvatar($profile_id, $size, $mediatype, $filename) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        common_debug("Updating avatar: $size");
 | 
					 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
            print "Updating avatar: $size\n";
 | 
					            common_debug("Updating avatar: $size");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $profile = Profile::staticGet($profile_id);
 | 
					        $profile = Profile::staticGet($profile_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$profile) {
 | 
					        if (!$profile) {
 | 
				
			||||||
            common_debug("Couldn't get profile: $profile_id!");
 | 
					 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                print "Couldn't get profile: $profile_id!\n";
 | 
					                common_debug("Couldn't get profile: $profile_id!");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -500,7 +472,9 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $avatar = $profile->getAvatar($sizes[$size]);
 | 
					        $avatar = $profile->getAvatar($sizes[$size]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($avatar) {
 | 
					        if ($avatar) {
 | 
				
			||||||
 | 
					            if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
                common_debug("Deleting $size avatar for $profile->nickname.");
 | 
					                common_debug("Deleting $size avatar for $profile->nickname.");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            @unlink(INSTALLDIR . '/avatar/' . $avatar->filename);
 | 
					            @unlink(INSTALLDIR . '/avatar/' . $avatar->filename);
 | 
				
			||||||
            $avatar->delete();
 | 
					            $avatar->delete();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -538,9 +512,8 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $avatar->filename = $filename;
 | 
					        $avatar->filename = $filename;
 | 
				
			||||||
        $avatar->url = Avatar::url($filename);
 | 
					        $avatar->url = Avatar::url($filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        common_debug("new filename: $avatar->url");
 | 
					 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
            print "New filename: $avatar->url\n";
 | 
					            common_debug("new filename: $avatar->url");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $avatar->created = common_sql_now();
 | 
					        $avatar->created = common_sql_now();
 | 
				
			||||||
@@ -549,16 +522,11 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (!$id) {
 | 
					        if (!$id) {
 | 
				
			||||||
            common_log_db_error($avatar, 'INSERT', __FILE__);
 | 
					            common_log_db_error($avatar, 'INSERT', __FILE__);
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                print "Could not insert avatar!\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        common_debug("Saved new $size avatar for $profile_id.");
 | 
					 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
              print "Saved new $size avatar for $profile_id.\n";
 | 
					            common_debug("Saved new $size avatar for $profile_id.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $id;
 | 
					        return $id;
 | 
				
			||||||
@@ -573,15 +541,11 @@ class TwitterStatusFetcher extends Daemon
 | 
				
			|||||||
        $out = fopen($avatarfile, 'wb');
 | 
					        $out = fopen($avatarfile, 'wb');
 | 
				
			||||||
        if (!$out) {
 | 
					        if (!$out) {
 | 
				
			||||||
            common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__);
 | 
					            common_log(LOG_WARNING, "Couldn't open file $filename", __FILE__);
 | 
				
			||||||
            if (defined('SCRIPT_DEBUG')) {
 | 
					 | 
				
			||||||
                print "Couldn't open file! $filename\n";
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        common_debug("Fetching avatar: $url", __FILE__);
 | 
					 | 
				
			||||||
        if (defined('SCRIPT_DEBUG')) {
 | 
					        if (defined('SCRIPT_DEBUG')) {
 | 
				
			||||||
            print "Fetching avatar from Twitter: $url\n";
 | 
					            common_debug("Fetching avatar: $url");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $ch = curl_init();
 | 
					        $ch = curl_init();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user