Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/admin/abstract/class-rop-model-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function set( $key, $value = '', $refresh = false ) {

$this->data[ $key ] = apply_filters( 'rop_set_key_' . $key, $value );

return update_option( $this->namespace, $this->data );
return update_option( $this->namespace, $this->data, false );
}


Expand Down
14 changes: 14 additions & 0 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,20 @@ private function add_account_bluesky( $data ) {
return $this->response->to_array();
}

/**
* API method called to cleanup services.
*
* @access private
* @return array<string, mixed>
*/
public function cleanup_accounts() {
$model = new Rop_Services_Model();
$this->response->set_code( '200' )
->set_data( $model->cleanup_accounts() );

return $this->response->to_array();
}

/**
* Share API method.
*
Expand Down
23 changes: 23 additions & 0 deletions includes/admin/models/class-rop-services-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class Rop_Services_Model extends Rop_Model_Abstract {
*/
private $accounts_namespace = 'active_accounts';

/**
* Cleanup account count.
*
* @access private
* @var int $cleanup_account_count
*/
private $cleanup_account_count = 1000;

/**
* Utility method to clear authenticated services.
Expand Down Expand Up @@ -520,4 +527,20 @@ public function find_account( $account_id ) {
return false;
}

/**
* Utility method to cleanup authenticated services.
*
* @access public
* @return array<string, mixed>
*/
public function cleanup_accounts() {
$services = $this->get( $this->services_namespace );

if ( count( $services ) > $this->cleanup_account_count ) {
$services = array_slice( $services, -( $this->cleanup_account_count ), null, true );
$this->set( $this->services_namespace, $services );
}

return $services;
}
}
4 changes: 4 additions & 0 deletions includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public static function get_labels( $key = '' ) {
'upsell_bz_service_body' => __( 'We\'re sorry, %1$s is not available on your plan. Please upgrade to the business plan to unlock all these features and get more traffic.', 'tweet-old-post' ),
'search_account' => __( 'Search account', 'tweet-old-post' ),
'no_account_found' => __( 'No account found for search', 'tweet-old-post' ),
'cleanup_cta' => __( 'Cleanup accounts', 'tweet-old-post' ),
'cleanup_title' => __( 'Clean Up Accounts', 'tweet-old-post' ),
'cleanup_description' => __( 'This will remove older account records and keep only the most recent 1,000 accounts. This helps improve performance and reduce stored data.', 'tweet-old-post' ),
'cleanup_now' => __( 'Cleanup now', 'tweet-old-post' ),
),
'settings' => array(
'yes_text' => __( 'Yes', 'tweet-old-post' ),
Expand Down
3 changes: 3 additions & 0 deletions vue/src/models/rop_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ export default new Vuex.Store({
case 'toggle_tracking':

break
case 'cleanup_accounts':
state.authenticatedServices = stateData;
break;
default:
Vue.$log.error('No state request for ', requestName);
}
Expand Down
102 changes: 100 additions & 2 deletions vue/src/vue-elements/accounts-tab-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div
v-if="twitter_warning"
class="toast toast-warning"
v-html="labels.twitter_warning"

Check warning on line 7 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

'v-html' directive can lead to XSS attack
/>
<div class="container">
<div
Expand Down Expand Up @@ -84,11 +84,25 @@
>
<div class="column col-12">
<p class="upsell">
<i class="fa fa-info-circle " /> <span v-html="labels.upsell_accounts" />

Check warning on line 87 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

'v-html' directive can lead to XSS attack
</p>
</div>
</div>
<div class="column col-12 text-right">
<button
class="btn btn-secondary me-2"
@click="openCleanupModal()"
>
<i
v-if="!is_loading"
class="fa fa-trash"
/>
<i
v-else
class="fa fa-spinner fa-spin"
/>
{{ labels.cleanup_cta }}
</button>
<button
class="btn btn-secondary"
@click="resetAccountData()"
Expand All @@ -106,6 +120,32 @@
</div>
</div>
</div>
<div

Check warning on line 123 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

Expected indentation of 4 spaces but found 5 spaces
class="modal rop-cleanup-modal"
:class="cleanupModalClass"
>
<div class="modal-overlay" />
<div class="modal-container">
<div class="modal-header">
<button
class="btn btn-clear float-right"
@click="closeCleanupModal()"
/>
<div class="modal-title h5">
{{ labels.cleanup_title }}
</div>
</div>
<div class="modal-body">
{{ labels.cleanup_description }}
</div>
<div class="modal-footer">
<button
class="btn btn-success"
@click="cleanupAccount()"
>{{ labels.cleanup_now }}</button>

Check warning on line 145 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

Expected 1 line break before closing tag (`</button>`), but no line breaks found

Check warning on line 145 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

Expected 1 line break after opening tag (`<button>`), but no line breaks found
</div>
</div>
</div>
</div>
</template>

Expand All @@ -126,7 +166,7 @@
type: String
}
},
components: {

Check warning on line 169 in vue/src/vue-elements/accounts-tab-panel.vue

View workflow job for this annotation

GitHub Actions / JS Lint (18.x)

The "components" property should be above the "props" property on line 161
SignInBtn,
ServiceUserTile,
AddAccountTile,
Expand All @@ -142,7 +182,8 @@
labels: this.$store.state.labels.accounts,
upsell_link: ropApiSettings.upsell_link,
pro_installed: ropApiSettings.pro_installed,
postTimeout: ''
postTimeout: '',
cleanupModal: false,
}
},
computed: {
Expand Down Expand Up @@ -189,7 +230,12 @@
},
hasActiveAccountsLimitation: function () {
return !this.pro_installed && this.accountsCount >= 2 && this.checkLicense ;
}
},
cleanupModalClass: function () {
return {
'active': this.cleanupModal === true
}
},
},
mounted: function () {
if (0 === this.is_preloading) {
Expand Down Expand Up @@ -228,6 +274,33 @@
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
})
},
openCleanupModal: function() {
this.cleanupModal = true;
},
closeCleanupModal: function() {
this.cleanupModal = false;
},
cleanupAccount: function() {
if (this.is_loading) {
this.$log.warn('Request in progress...Bail');
return;
}
this.is_loading = true;
this.$store.dispatch('fetchAJAXPromise', {
req: 'cleanup_accounts',
data: {}
}).then(response => {
this.is_loading = false;
this.cleanupModal = false;
if (this.$parent.start_status === true) {
// Stop sharing process if enabled.
this.$parent.togglePosting();
}
}, error => {
this.is_loading = false;
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
})
},
filteredAccounts: function(accounts) {
const result = {};
const query = this.searchAccount?.toLowerCase() || '';
Expand Down Expand Up @@ -273,6 +346,31 @@
margin-bottom: 15px;
}

#rop_core .rop-cleanup-modal .modal-container{
max-width: 500px;
padding: 25px;

.modal-title, .modal-footer{
text-align: center;
}
.btn-success{
border:none;
background-color:#00a32a;
color: #fff;
padding: 0.5rem 1rem;
height: auto;
display: inline;
}
.btn-success:hover{
background-color:#009528;
}
.modal-body{
font-size: 0.7rem;
margin: 10px 30px;
padding: 0px;
}
}

@media ( max-width: 600px ) {
#rop_core .panel-body .text-gray {
margin-bottom: 10px;
Expand Down
Loading