<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class User_Model_DbTable_Verify extends Engine_Db_Table
{
  public function gc()
  {
    // Delete rows for users that are verified or the user does not exist
    $verifyTableName = $this->info('name');
    $userTable = Engine_Api::_()->getItemTable('user');
    $userTableName = $userTable->info('name');
    $select = new Zend_Db_Select($this->getAdapter());
    $select
      ->from($verifyTableName, null)
      ->joinLeft($userTableName, $userTableName . '.user_id=' . $verifyTableName . '.user_id', array('verified', 'user_id'))
      ->where($userTableName . '.verified = ?', 1);

    $gcIds = array();
    foreach( $select->query()->fetchAll() as $row ) {
      if( !empty($row['verified']) || empty($row['user_id']) ) {
        $gcIds[] = $row['user_id'];
      }
    }

    // Delete them
    if( !empty($gcIds) ) {
      $this->delete(array(
        'user_id IN(?)' => $gcIds,
      ));
    }

    return $this;
  }
}
